2D游戏编程4—Windows事件

windows消息传来的参数分解:

Message: WM_ACTIVATE

Parameterization:

fActive      = LOWORD(wParam);       // activation flag
fMinimized   = (BOOL)HIWORD(wParam); // minimized flag
hwndPrevious = (HWND)lParam;         // window handle

The Activation Flags for WM_ACTIVATE

Value
Description

WA_CLICKACTIVE
Activated by a mouse click.

WA_ACTIVE
The window has been activated by some means other than the mouse, such as the keyboard interface.

WA_INACTIVE
The window is being deactivated.

WinProc激活程序消息的处理:

case WM_ACTIVATE:
{
// test if window is being activated
if (LOWORD(wparam)!=WA_INACTIVE)
   {
   // application is being activated
   } // end if
else
   {
   // application is being deactivated
   } // end else

} break;


Message: WM_CLOSE

case WM_CLOSE:
{
// display message box
int result =  MessageBox(hwnd,
    "Are you sure you want to close this application?",
              "WM_CLOSE Message Processor",
               MB_YESNO | MB_ICONQUESTION);

// does the user want to close?
if (result == IDYES)
   {
   // call default handler
   return (DefWindowProc(hwnd, msg, wparam, lparam));
   } // end if
else // throw message away
   return(0);

} break;
image

Message: WM_SIZE

fwSizeType = wParam;         // resizing flag
nWidth     = LOWORD(lParam); // width of client area
nHeight    = HIWORD(lParam); // height of client area

The fwSizeType flag indicates what kind of resizing just occurred

Value
Description

SIZE_MAXHIDE
Message is sent to all pop-up windows when some other window is maximized.

SIZE_MAXIMIZED
Window has been maximized.

SIZE_MAXSHOW
Message is sent to all pop-up windows when some other window has been restored to its former size.

SIZE_MINIMIZED
Window has been minimized.

SIZE_RESTORED
Window has been resized, but neither the SIZE_MINIMIZED nor SIZE_MAXIMIZED value applies.

处理代码:

case WM_SIZE:
         {
         // extract size info
         int width  = LOWORD(lparam);
         int height = HIWORD(lparam);

         // get a graphics context
         hdc = GetDC(hwnd);

         // set the foreground color to green
         SetTextColor(hdc, RGB(0,255,0));

         // set the background color to black
         SetBkColor(hdc, RGB(0,0,0));

         // set the transparency mode to OPAQUE
         SetBkMode(hdc, OPAQUE);

         // draw the size of the window
         sprintf(buffer,
         "WM_SIZE Called -  New Size = (%d,%d)", width, height);
         TextOut(hdc, 0,0, buffer, strlen(buffer));

         // release the dc back
         ReleaseDC(hwnd, hdc);

         } break;

Message: WM_MOVE

case WM_MOVE:
         {
         // extract the position
         int xpos = LOWORD(lparam);
         int ypos = HIWORD(lparam);

         // get a graphics context
         hdc = GetDC(hwnd);

         // set the foreground color to green
         SetTextColor(hdc, RGB(0,255,0));

         // set the background color to black
         SetBkColor(hdc, RGB(0,0,0));

         // set the transparency mode to OPAQUE
         SetBkMode(hdc, OPAQUE);

         // draw the size of the window
         sprintf(buffer,
        "WM_MOVE Called -  New Position = (%d,%d)", xpos, ypos);
         TextOut(hdc, 0,0, buffer, strlen(buffer));
         // release the dc back
         ReleaseDC(hwnd, hdc);

         } break;

posted @ 2013-09-15 15:33  xxx1  阅读(305)  评论(0编辑  收藏  举报