winproc.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:3k
- #include "global.h"
- #include "ddutil.h"
- extern CDisplay Display;
- extern HWND hMainWnd, hChildWnd;
- //-----------------------------------------------------------------------------
- // Global variables for command analyse
- //-----------------------------------------------------------------------------
- bool bKeyPressed[6] = { 0,0,0,0,0,0 };
- bool bFired = false;
- unsigned int uiRecentCmd = 0, uiCurrentCmd = 0;
- unsigned int KeyMap[6] = { 0, VK_RIGHT, VK_DOWN, VK_UP, VK_LEFT, VK_SPACE};
- //-----------------------------------------------------------------------------
- // Name: MainWndProc()
- // Desc: Callback message procedure of the main window
- //-----------------------------------------------------------------------------
- LRESULT CALLBACK MainWndProc( HWND hwnd, UINT message,
- WPARAM wParam, LPARAM lParam)
- {
- switch ( message )
- {
- case WM_CREATE:
- break;
- case WM_ACTIVATE:
- if ( LOWORD(wParam) == WA_INACTIVE )
- g_bActive = false;
- else {
- g_bActive = true;
- SetFocus( hChildWnd );
- }
- break;
- case WM_COMMAND:
- break;
- case WM_MOVE:
- Display.UpdateBounds();
- break;
- case WM_SIZE:
- Display.UpdateBounds();
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- }
- return DefWindowProc( hwnd, message, wParam, lParam );
- }
- //-----------------------------------------------------------------------------
- // Name: GameWndProc()
- // Desc: Callback message procedure of the game window
- //-----------------------------------------------------------------------------
- LRESULT CALLBACK GameWndProc( HWND hwnd, UINT message,
- WPARAM wParam, LPARAM lParam )
- {
- int i;
- uiCurrentCmd = 0;
- bFired = false;
-
- switch (message)
- {
- case WM_CREATE:
- g_bActive = true;
- break;
- case WM_LBUTTONDOWN:
- SetFocus(hwnd);
- break;
- case WM_KEYDOWN:
- for(i=1;i<5;i++) { // Pressed any direction button?
- if( wParam == KeyMap[i] ) {
- bKeyPressed[i] = true;
- uiCurrentCmd = i;
- uiRecentCmd = i;
- goto end_gameproc;
- }
- }
- // Not a direction button
- if ( wParam == KeyMap[5] ) // the fire button ?
- bFired = true;
- break;
- case WM_KEYUP:
- for( i=1; i<5; i++)
- if( wParam == KeyMap[i] ) {
- bKeyPressed[i] = false;
- break;
- }
- break;
- case WM_CLOSE:
- g_bActive = false;
- break;
- }
- // No input msg received
- if ( bKeyPressed[uiRecentCmd] ) // if the recent cmd is valid
- uiCurrentCmd = uiRecentCmd;
- else { // test all keys to find a valid one
- for( i=4; i>0; i--)
- if( bKeyPressed[i] )
- break;
- uiRecentCmd = i; // 4 - 0
- uiCurrentCmd = i;
- }
- end_gameproc:
- return DefWindowProc ( hwnd, message, wParam, lParam );
- }