Comment detail

ウィンドウの表示 (Nested Flatten)
VC++&MFCで。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <afxwin.h>

class CMainWindow : public CFrameWnd
{
public:
    CMainWindow()
    {
        CRect rect(0, 0, 400, 300);
        Create(NULL, _T("こんにちは、GUI!"), WS_OVERLAPPEDWINDOW, rect);
        CenterWindow();
    };
};

class CHelloGUIApp : public CWinApp
{
public:
    virtual BOOL InitInstance()
    {
        m_pMainWnd = new CMainWindow();
        m_pMainWnd->ShowWindow(m_nCmdShow);
        m_pMainWnd->UpdateWindow();
        return TRUE;
    }
};

CHelloGUIApp  helloGUIApp;

WindowsプログラムでPeekMessage()でループは厳禁です.これだとCPUリソースを食いつぶします.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
    case WM_CLOSE:
-        g_nExit = 1;
+        PostQuitMessage(0);

-    while(g_nExit==0){
-        if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ){
-            TranslateMessage( &msg );
-            DispatchMessage( &msg);
-        }
-    }
+   while (GetMessage(&msg, NULL, 0, 0) > 0) {
+       TranslateMessage(&msg);
+       DispatchMessage(&msg);
+   }

Index

Feed

Other

Link

Pathtraq

loading...