{"id":212,"date":"2014-06-10T14:33:24","date_gmt":"2014-06-10T05:33:24","guid":{"rendered":"http:\/\/csharp.ihavenomoney.co.kr\/?p=212"},"modified":"2019-06-27T10:55:44","modified_gmt":"2019-06-27T01:55:44","slug":"%eb%a7%a4%ed%81%ac%eb%a1%9c-%ec%82%ac%ec%9a%a9-window","status":"publish","type":"post","link":"https:\/\/csharp.ihavenomoney.co.kr\/?p=212","title":{"rendered":"\ub9e4\ud06c\ub85c \uc0ac\uc6a9 Window"},"content":{"rendered":"<p><a href=\"http:\/\/csharp.ihavenomoney.co.kr\/wp-content\/uploads\/2014\/06\/classwindow.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/csharp.ihavenomoney.co.kr\/wp-content\/uploads\/2014\/06\/classwindow-300x236.png\" alt=\"classwindow\" width=\"300\" height=\"236\" class=\"alignnone size-medium wp-image-197\" srcset=\"https:\/\/csharp.ihavenomoney.co.kr\/wp-content\/uploads\/2014\/06\/classwindow-300x236.png 300w, https:\/\/csharp.ihavenomoney.co.kr\/wp-content\/uploads\/2014\/06\/classwindow.png 319w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre class=\"lang:c++ decode:true \" >#include &lt;Windows.h&gt;\r\n\r\n#define DECLARE_MESSAGE_MAP()    static MessageMap messageMap[];\r\n#define BEGIN_MESSAGE_MAP(class_name)\tMessageMap class_name::messageMap[]={\r\n#define END_MESSAGE_MAP()\t{0,NULL}};\r\n\r\nLRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam);\r\n\r\n\/\/Class CObject\r\nclass CObject{\r\nprotected:\r\n\tstatic char szAppName[];\r\n\tHWND hwnd;\r\n\tMSG msg;\r\n\tWNDCLASSEX wndclass;\r\npublic:\r\n\tvoid InitInstance(HINSTANCE hInstance, PSTR szCmdLine, int iCmdShow);\r\n\tvoid Run();\/\/Message\r\n    WPARAM ExitInstance(); \/\/exit\r\n\t\/\/message handler\r\n\tvirtual void OnCreate() = 0;\r\n\tvirtual void OnDraw() = 0;\r\n\tvirtual void OnDestroy() = 0;\r\n};\r\n\r\nvoid CObject::InitInstance(HINSTANCE hInstance, PSTR szCmdLine, int iCmdShow)\r\n{\r\n\twndclass.cbSize = sizeof(wndclass);\r\n\twndclass.style  = CS_HREDRAW|CS_VREDRAW;\r\n\twndclass.lpfnWndProc = WndProc;\r\n\twndclass.cbClsExtra =0;\r\n\twndclass.cbWndExtra= 0;\r\n\twndclass.hInstance = hInstance;\r\n\twndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);\r\n\twndclass.hCursor = LoadCursor(NULL,IDC_ARROW);\r\n\twndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);\r\n\twndclass.lpszMenuName = NULL;\r\n\twndclass.lpszClassName = szAppName;\r\n\twndclass.hIconSm = LoadIcon(NULL,IDI_APPLICATION);\r\n\r\n\tRegisterClassEx(&amp;wndclass);\r\n\r\n\thwnd = CreateWindow(szAppName,\r\n\t\t\t\t\t\t\"Hello Program\",\r\n\t\t\t\t\t\tWS_OVERLAPPEDWINDOW,\r\n\t\t\t\t\t\tCW_USEDEFAULT,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\tCW_USEDEFAULT,\r\n\t\t\t\t\t\t0,\r\n\t\t\t\t\t\tNULL,\r\n\t\t\t\t\t\tNULL,\r\n\t\t\t\t\t\thInstance,\r\n\t\t\t\t\t\tNULL);\r\n\tShowWindow(hwnd,iCmdShow);\r\n\tUpdateWindow(hwnd);\r\n}\r\n\r\nvoid CObject::Run(){\r\n\twhile(GetMessage(&amp;msg,NULL,0,0)){\r\n\t\tTranslateMessage(&amp;msg);\r\n\t\tDispatchMessage(&amp;msg);\r\n\t}\r\n}\r\n\r\nWPARAM CObject::ExitInstance(){\r\n\treturn msg.wParam;\r\n}\r\n\r\nchar CObject::szAppName[]=\"HelloWin\";\r\n\/\/CObject* pCObject;\r\n\r\n\/\/class CView\r\nclass CView;\r\ntypedef void (CView::*CViewFunPointer)();\/\/\ud568\uc218\ud3ec\uc778\ud130\r\ntypedef struct tagMessgeMap{ \/\/\uad6c\uc870\uccb4\r\n\tUINT iMsg;\r\n\tCViewFunPointer fp;  \/\/\ud568\uc218\ud3ec\uc778\ud130 \uc8fc\uc18c\r\n}MessageMap;\r\nstatic CViewFunPointer fpCViewGlobal; \/\/\uc815\uc801 \uc8fc\uc18c\r\n\r\nclass CView:public CObject{\r\npublic:\r\n\t\/\/static MessageMap messageMap[];\r\n\tDECLARE_MESSAGE_MAP()\r\n\t\/\/override all message handler\r\n\tvoid OnCreate();\r\n\tvoid OnDraw();\r\n\tvoid OnDestroy();\r\n};\r\n\r\nBEGIN_MESSAGE_MAP(CView)\r\n\/\/MessageMap CView::messageMap[]={\r\n\t{WM_CREATE,&amp;CView::OnCreate},\r\n\t{WM_PAINT,&amp;CView::OnDraw},\r\n\t{WM_DESTROY,&amp;CView::OnDestroy},\r\n\t\/\/{0,NULL}\r\n\/\/};\r\nEND_MESSAGE_MAP()\r\n\r\nvoid CView::OnCreate(){\r\n}\r\n\r\nvoid CView::OnDraw()\r\n{\r\n\tHDC hdc;\r\n\tPAINTSTRUCT ps;\r\n\tRECT rect;\r\n\r\n\thdc=BeginPaint(hwnd,&amp;ps);\r\n\tGetClientRect(hwnd,&amp;rect);\r\n\tDrawText(hdc,\"Hello Window\",-1,&amp;rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);\r\n\tEndPaint(hwnd,&amp;ps);\r\n}\r\n\r\nvoid CView::OnDestroy() {\r\n\tPostQuitMessage(0);\r\n}\r\n\r\nCView app;\r\n\r\nLRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam)\r\n{\r\n\tint i=0;\r\n\r\n\twhile(CView::messageMap[i].iMsg!=0){\r\n\t\tif(iMsg==CView::messageMap[i].iMsg){\r\n\t\t\tfpCViewGlobal=CView::messageMap[i].fp;\r\n\t\t\t(app.*fpCViewGlobal)();\r\n\t\t\treturn 0;\r\n\t\t}\r\n\t\t++i;\r\n\t}\r\n\treturn DefWindowProc(hwnd,iMsg,wParam,lParam);\r\n}\r\nint WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)\r\n{\r\n\t\/\/pCObject = &amp;app; \/\/ CView app;\r\n\tapp.InitInstance(hInstance,szCmdLine,iCmdShow);\r\n\tapp.Run();\r\n\treturn app.ExitInstance();\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;Windows.h&gt; #define DECLARE_MESSAGE_MAP() static MessageMap messageMap[]; #define BEGIN_MESSAGE_MAP(class_name) MessageMap class_name::messageMap[]={ #define END_MESSAGE_MAP() {0,NULL}}; LRESULT CALLBACK WndProc(HWND hwnd,UINT iMsg,WPARAM wParam,LPARAM lParam); \/\/Class CObject class CObject{ protected: static char szAppName[]; HWND hwnd; MSG msg; WNDCLASSEX wndclass; public: void InitInstance(HINSTANCE hInstance, PSTR szCmdLine, int iCmdShow); void Run();\/\/Message WPARAM ExitInstance(); \/\/exit \/\/message handler virtual void OnCreate() = 0;\u2026 <span class=\"read-more\"><a href=\"https:\/\/csharp.ihavenomoney.co.kr\/?p=212\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-212","post","type-post","status-publish","format-standard","hentry","category-c"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=212"}],"version-history":[{"count":3,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/212\/revisions"}],"predecessor-version":[{"id":544,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/212\/revisions\/544"}],"wp:attachment":[{"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csharp.ihavenomoney.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}