본문 바로가기
프로그래밍/기법

[윈도] 윈도우 프로시져의 멤버 함수화

by 써드아이 2014. 4. 18.

많이들 쓰는 듯...




class MyClass;



LRESULT CALLBACK WndProc( HWND hHwnd, UINT msg, WPARAM wParam, LPARAM lParam )

{

LRESULT result;

static MyClass *pthis = (MyClass*) GetWindowLong( hWnd, GWL_USERDATA );


if ( pthis == NULL && msg == WM_NCCREATE )

{

void *userdata = (void*)( ((CREATESTRUCT*) lParam)->lpCreateParam );

SetWindowLong( hWnd, GWL_USERDATA, userdata );

result = DefWindowProc( hWnd, msg, wParam, lParam );

}

else

{

if ( this )

result = pthis->MyWndProc( hWnd, msg, wParam, lParam );

else

result = DefWindowProc( hWnd, msg, wParam, lParam );

}


return result;

}


class MyClass

{

public:

CreateWindow( ... )

{

wc.lpfnWndProc = WndProc;

RegiserWindow( &wc );

m_hWnd = CreateWindowEx( /* */, this );

}


LRESULT MyWndProc( hWnd, msg, wParam, lParam );


protected:

m_hWnd;

}