교재 소개

다음과 같은 자료들이 있다. 무료 교재 소개 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 0003 - CreateWindowExW 함수

CreateWindow 함수는 CreateWindowEx 함수의 매크로로 구성되며, 이때 dwExStyle 의 값은 0L이 된다. 따라서 CreateWindowEx 함수만을 알고 있으면 된다.

HWND CreateWindowExW(
    [in] DWORD dwExStyle,
    [in, optional] LPCWSTR lpClassName,
    [in, optional] LPCWSTR lpWindowName,
    [in] DWORD dwStyle,
    [in] int X,
    [in] int Y,
    [in] int nWidth,
    [in] int nHeight,
    [in, optional] HWND hWndParent,
    [in, optional] HMENU hMenu,
    [in, optional] HINSTANCE hInstance,
    [in, optional] LPVOID lpParam
);

소스 코드는 다음과 같다.

#ifndef UNICODE

#define UNICODE

#endif


#include <windows.h>


LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

{

switch (uMsg)

{

case WM_DESTROY:

PostQuitMessage(0);

return 0;


case WM_PAINT:

{

PAINTSTRUCT ps;

HDC hdc = BeginPaint(hwnd, &ps);


// All painting occurs here, between BeginPaint and EndPaint.

FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));


EndPaint(hwnd, &ps);

}

return 0;

}

return DefWindowProc(hwnd, uMsg, wParam, lParam);

}


BOOL InitApplication(HINSTANCE hinstance)

{

WNDCLASSEXW wcxw = { };


wcxw.cbSize = sizeof(wcxw);

wcxw.style = CS_HREDRAW | CS_VREDRAW;

wcxw.lpfnWndProc = WindowProc;

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);

}


HWND InitInstance(HINSTANCE hinstance, int nCmdShow)

{

HWND hwnd;


hwnd = CreateWindowExW( 

0,

L"MainWClass",        // name of window class 

L"Sample",            // title-bar string 

WS_OVERLAPPEDWINDOW, // top-level window 

CW_USEDEFAULT,       // default horizontal position 

CW_USEDEFAULT,       // default vertical position 

CW_USEDEFAULT,       // default width 

CW_USEDEFAULT,       // default height 

(HWND) NULL,         // Parent window. no owner window 

(HMENU) NULL,        // Menu. use class menu 

hinstance,           // handle to application instance 

(LPVOID) NULL);      // no window-creation data 

 

if (!hwnd) { return hwnd; }

 

// Show the window and send a WM_PAINT message to the window 

// procedure. 

 

ShowWindow(hwnd, nCmdShow); 

UpdateWindow(hwnd); 

return hwnd; 

}


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

{

MSG msg;

HWND hwnd;


if ( !InitApplication(hInstance) )

{

return FALSE;

}


if ( !(hwnd = InitInstance(hInstance, nCmdShow)) )

{

return FALSE;

}


BOOL fGotMessage;

while ((fGotMessage = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0 &&

fGotMessage != -1) 

TranslateMessage(&msg); 

DispatchMessage(&msg); 


return msg.wParam; 

UNREFERENCED_PARAMETER(pCmdLine); 

주석을 없앤 코드는 다음과 같다.

 #ifndef UNICODE

#define UNICODE

#endif


#include <windows.h>


LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

{

switch (uMsg)

{

case WM_DESTROY:

PostQuitMessage(0);

return 0;


case WM_PAINT:

{

PAINTSTRUCT ps;

HDC hdc = BeginPaint(hwnd, &ps);


FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));


EndPaint(hwnd, &ps);

}

return 0;

}

return DefWindowProc(hwnd, uMsg, wParam, lParam);

}


BOOL InitApplication(HINSTANCE hinstance)

{

WNDCLASSEXW wcxw = { };


wcxw.cbSize = sizeof(wcxw);

wcxw.style = CS_HREDRAW | CS_VREDRAW;

wcxw.lpfnWndProc = WindowProc;

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);

}


HWND InitInstance(HINSTANCE hinstance, int nCmdShow)

{

HWND hwnd;


hwnd = CreateWindowExW( 

0,

L"MainWClass",        // name of window class 

L"Sample",            // title-bar string 

WS_OVERLAPPEDWINDOW, // top-level window 

CW_USEDEFAULT,       // default horizontal position 

CW_USEDEFAULT,       // default vertical position 

CW_USEDEFAULT,       // default width 

CW_USEDEFAULT,       // default height 

(HWND) NULL,         // Parent window. no owner window 

(HMENU) NULL,        // Menu. use class menu 

hinstance,           // handle to application instance 

(LPVOID) NULL);      // no window-creation data 

 

if (!hwnd) { return hwnd; }

 

ShowWindow(hwnd, nCmdShow); 

UpdateWindow(hwnd); 

return hwnd; 

}


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

{

MSG msg = { };

HWND hwnd;


if ( !InitApplication(hInstance) ) { return FALSE; }


if ( !(hwnd = InitInstance(hInstance, nCmdShow)) ) { return FALSE; }


BOOL fGotMessage;

while ((fGotMessage = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0 &&

fGotMessage != -1) 

TranslateMessage(&msg); 

DispatchMessage(&msg); 


return msg.wParam; 

UNREFERENCED_PARAMETER(pCmdLine); 

관련 문서는 다음과 같다.

댓글

이 블로그의 인기 게시물

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

목차 (글 목록)

LaTeX - 시작하기