Comment detail

ウィンドウの表示 (Nested Flatten)

This comment is reply for 354 kawauchik: VC++&MFCで。(ウィンドウの表示). Go to thread root.

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...