교재 소개

다음과 같은 자료들이 있다. 무료 교재 소개 https://open.umn.edu/opentextbooks/ http://bigbook.or.kr/ Green Tea Press – Free books by Allen B. Downey Gilbert Strang, Calculus  https://ocw.mit.edu/courses/res-18-001-calculus-fall-2023/pages/textbook/ Open Logic Project https://builds.openlogicproject.org/ Open Logic Text Complete Version (2024-12-01) 이상구, 선형대수 https://ibook.skku.edu/Viewer/LA-Texbook http://matrix.skku.ac.kr/LA/ David Cherney, Tom Denton, Rohit Thomas and Andrew Waldron, Linear Algebra https://www.math.ucdavis.edu/~linear/

WinAPI 0002 - 윈도우 클래스의 등록

지난번에 이어 wWinMain 함수를 좀 더 다듬어 보자.

우선, RegisterClass 함수를 통해 윈도우 클래스를 등록해 보자. WinAPI에서는 틀에 해당하는 윈도우 클래스를 먼저 등록하고, 이걸 통해 윈도우를 생성하는 방식을 사용한다. 


#ifndef UNICODE

#define UNICODE

#endif


#include <windows.h>


BOOL InitApplication(HINSTANCE hinstance)

{

WNDCLASSEXW wcx = { }; 

 

wcx.cbSize = sizeof(wcx);    // size of structure 

wcx.style = CS_HREDRAW | CS_VREDRAW;    // the class styles

// https://learn.microsoft.com/en-us/windows/win32/winmsg/window-class-styles

wcx.lpfnWndProc = DefWindowProcW;    // points to window procedure 

wcx.cbClsExtra = 0;    // no extra class memory 

// The number of extra bytes

// to allocate following the window-class structure.

// The system initializes the bytes to zero.

wcx.cbWndExtra = 0;                // no extra window memory 

//  The number of extra bytes to allocate following the window instance.

//  The system initializes the bytes to zero.

//  If an application uses WNDCLASSEX

//  to register a dialog box

//  created by using the CLASS directive in the resource file,

//  it must set this member to DLGWINDOWEXTRA.

wcx.hInstance = hinstance;         // handle to instance 

wcx.hIcon = LoadIcon(NULL, 

IDI_APPLICATION);              // predefined app. icon 

wcx.hCursor = LoadCursor(NULL, 

IDC_ARROW);                    // predefined arrow 

wcx.hbrBackground = GetStockObject( 

WHITE_BRUSH);                  // white background brush 

wcx.lpszMenuName =  L"MainMenu";    // name of menu resource 

wcx.lpszClassName = L"MainWClass";  // name of window class 

wcx.hIconSm = LoadImage(hinstance, // small class icon 

MAKEINTRESOURCE(5),

IMAGE_ICON, 

GetSystemMetrics(SM_CXSMICON), 

GetSystemMetrics(SM_CYSMICON), 

LR_DEFAULTCOLOR); 

 

// Register the window class. 

return RegisterClassEx(&wcx); 

}


int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)

{

if ( !InitApplication(hInstance) ) 

return FALSE; 


return 0;

}

주석을 제거한 소스코드는 다음과 같다.

#ifndef UNICODE

#define UNICODE

#endif


#include <windows.h>


BOOL InitApplication(HINSTANCE hinstance)

{

WNDCLASSEXW wcxw = { };


wcxw.cbSize = sizeof(wcxw);

wcxw.style = CS_HREDRAW | CS_VREDRAW;

wcxw.lpfnWndProc = DefWindowProcW;

wcxw.cbClsExtra = 0;

wcxw.cbWndExtra = 0;

wcxw.hInstance = hinstance;

wcxw.hIcon = LoadIcon(NULL, IDI_APPLICATION);

wcxw.hCursor = LoadCursor(NULL, IDC_ARROW);

wcxw.hbrBackground = GetStockObject(WHITE_BRUSH);

wcxw.lpszMenuName = L"MainMenu";

wcxw.lpszClassName = L"MainWClass";

wcxw.hIconSm = LoadImage(hinstance, MAKEINTRESOURCE(5), IMAGE_ICON,

GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),

LR_DEFAULTCOLOR);

return RegisterClassExW(&wcxw);

}


int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)

{

if ( !InitApplication(hInstance) )

{

return FALSE;

}

return 0;

}


컴파일 시에는 gdi32 라이브러리를 링크해 줘야 한다. 소스 코드 파일이름이 ex2.c 일 경우에 다음과 같이 입력한다.

gcc ex2.c -o ex2 -municode -lgdi32

실행시켜도 아직은 아무것도 뜨지 않는다. 다음에는 윈도우를 하나 띄우도록 해 볼 것이다.


관련 문서는 다음과 같다.

DefWIndowProcW 함수(winuser.h)

RegisterClassExW 함수(winuser.h)

WNDCLASSEXW 구조체(winuser.h)

Using Window Classes

Window Class Style

GetStockObject function (wingdi.h)

LoadImageW function (winuser.h)

MAKEINTRESOURCEW macro (winuser.h)

GetSystemMetrics function (winuser.h)

About Icons

Conventions for Function Prototypes



댓글

이 블로그의 인기 게시물

목차 (글 목록)

LaTeX - 시작하기