q GUI 48 include windows h LRESULT CALLBACK
q 윈도우 GUI 애플리케이션 (4/8) • 예제 코드 #include <windows. h> // ① LRESULT CALLBACK Wnd. Proc(HWND, UINT, WPARAM, LPARAM); // ② int APIENTRY Win. Main(HINSTANCE h. Instance, HINSTANCE, LPSTR lp. Cmd. Line, int n. Cmd. Show) // ③ { // 윈도우 클래스 등록 ④ WNDCLASS wndclass; wndclass. cb. Cls. Extra = 0; wndclass. cb. Wnd. Extra = 0; wndclass. hbr. Background = (HBRUSH)Get. Stock. Object(WHITE_BRUSH); wndclass. h. Cursor = Load. Cursor(NULL, IDC_ARROW); wndclass. h. Icon = Load. Icon(NULL, IDI_APPLICATION); wndclass. h. Instance = h. Instance; wndclass. lpsz. Class. Name = "My. Window. Class"; wndclass. lpsz. Menu. Name = NULL; wndclass. style = CS_HREDRAW | CS_VREDRAW; wndclass. lpfn. Wnd. Proc = (WNDPROC)Wnd. Proc; if(!Register. Class(&wndclass)) return -1; -5 -
q 윈도우 GUI 애플리케이션 (5/8) • 예제 코드 (cont’d) // 윈도우 생성 ⑤ HWND h. Wnd = Create. Window("My. Window. Class", "Win. App", WS_OVERLAPPEDWINDOW, 0, 0, 600, 300, NULL, (HMENU)NULL, h. Instance, NULL); if(h. Wnd == NULL) return -1; Show. Window(h. Wnd, n. Cmd. Show); Update. Window(h. Wnd); // 메시지 루프 ⑥ MSG msg; while(Get. Message(&msg, 0, 0, 0) > 0){ Translate. Message(&msg); Dispatch. Message(&msg); } } return msg. w. Param; -6 -
q 윈도우 GUI 애플리케이션 (6/8) • 예제 코드 (cont’d) // 윈도우 프로시저 ⑦ LRESULT CALLBACK Wnd. Proc(HWND h. Wnd, UINT u. Msg, WPARAM w. Param, LPARAM l. Param) { switch(u. Msg){ case WM_CREATE: return 0; case WM_SIZE: return 0; case WM_DESTROY: Post. Quit. Message(0); return 0; } } return Def. Window. Proc(h. Wnd, u. Msg, w. Param, l. Param); -7 -
q 대화상자 기반 애플리케이션 (4/5) • 예제 코드 #include <windows. h> #include "resource. h" // ① BOOL CALLBACK Dlg. Proc(HWND, UINT, WPARAM, LPARAM); // ② int APIENTRY Win. Main(HINSTANCE h. Instance, HINSTANCE, LPSTR lp. Cmd. Line, int n. Cmd. Show) { Dialog. Box(h. Instance, MAKEINTRESOURCE(IDD_DIALOG 1), NULL, Dlg. Proc); // ③ return 0; } BOOL CALLBACK Dlg. Proc(HWND h. Dlg, UINT u. Msg, WPARAM w. Param, LPARAM l. Param) // ④ { - 15 -
q 대화상자 기반 애플리케이션 (5/5) • 예제 코드 (cont’d) switch(u. Msg){ case WM_INITDIALOG: // ⑤ return TRUE; case WM_COMMAND: // ⑥ switch(LOWORD(w. Param)){ case IDOK: End. Dialog(h. Dlg, 0); // ⑦ return TRUE; case IDCANCEL: End. Dialog(h. Dlg, 0); return TRUE; } return FALSE; } - 16 -
- Slides: 19