bool CKeyModule::onPrimaryMessage (MSG *pmsg) { INSTANCE_DATA *pdata = pInstanceData;//(INSTANCE_DATA*) GetObjFromID (ncurrid); if (!pdata) { return FALSE; } // ignore primary messages while we're in the background if (!pdata->bAppHasFocus) return FALSE; switch (pmsg->message) { case WM_KEYDOWN: return ProcessKeyDown (pmsg->wParam, pmsg->lParam, pdata); case WM_CHAR: return ProcessChar (pmsg->wParam, pmsg->lParam, pdata); case WM_KEYUP: return ProcessKeyUp (pmsg->wParam, pmsg->lParam, pdata); } return FALSE; }
// // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_TESTFOCUS: break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_CHAR: ProcessKeyDown(hWnd,wParam & 0xff); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
//----------------------------------------------------------------------------- // Entry point into the program. //----------------------------------------------------------------------------- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) { Instance = hInstance; InitCommonControls(); // A monospaced font FixedFont = CreateFont(SS.TW.CHAR_HEIGHT, SS.TW.CHAR_WIDTH, 0, 0, FW_REGULAR, false, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Lucida Console"); if(!FixedFont) FixedFont = (HFONT)GetStockObject(SYSTEM_FONT); // Create the root windows: one for control, with text, and one for // the graphics CreateMainWindows(); ThawWindowPos(TextWnd); ThawWindowPos(GraphicsWnd); ShowWindow(TextWnd, SW_SHOWNOACTIVATE); ShowWindow(GraphicsWnd, SW_SHOW); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(GetDC(GraphicsWnd)); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(GetDC(GraphicsWnd)); // Create the heaps for all dynamic memory (AllocTemporary, MemAlloc) InitHeaps(); // A filename may have been specified on the command line; if so, then // strip any quotation marks, and make it absolute. char file[MAX_PATH] = ""; if(strlen(lpCmdLine)+1 < MAX_PATH) { char *s = lpCmdLine; while(*s == ' ' || *s == '"') s++; strcpy(file, s); s = strrchr(file, '"'); if(s) *s = '\0'; } if(*file != '\0') { GetAbsoluteFilename(file); } #ifdef HAVE_SPACEWARE // Initialize the SpaceBall, if present. Test if the driver is running // first, to avoid a long timeout if it's not. HWND swdc = FindWindow("SpaceWare Driver Class", NULL); if(swdc != NULL) { SiOpenData sod; SiInitialize(); SiOpenWinInit(&sod, GraphicsWnd); SpaceNavigator = SiOpen("GraphicsWnd", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &sod); SiSetUiMode(SpaceNavigator, SI_UI_NO_CONTROLS); } #endif // Call in to the platform-independent code, and let them do their init SS.Init(); if(strcmp(file, "")) SS.OpenFile(file); // And now it's the message loop. All calls in to the rest of the code // will be from the wndprocs. MSG msg; DWORD ret; while((ret = GetMessage(&msg, NULL, 0, 0)) != 0) { #ifdef HAVE_SPACEWARE // Is it a message from the six degree of freedom input device? if(ProcessSpaceNavigatorMsg(&msg)) goto done; #endif // A message from the keyboard, which should be processed as a keyboard // accelerator? if(msg.message == WM_KEYDOWN) { if(ProcessKeyDown(msg.wParam)) goto done; } if(msg.message == WM_SYSKEYDOWN && msg.hwnd == TextWnd) { // If the user presses the Alt key when the text window has focus, // then that should probably go to the graphics window instead. SetForegroundWindow(GraphicsWnd); } // None of the above; so just a normal message to process. TranslateMessage(&msg); DispatchMessage(&msg); done: SS.DoLater(); } #ifdef HAVE_SPACEWARE if(swdc != NULL) { if(SpaceNavigator != SI_NO_HANDLE) SiClose(SpaceNavigator); SiTerminate(); } #endif // Write everything back to the registry FreezeWindowPos(TextWnd); FreezeWindowPos(GraphicsWnd); // Free the memory we've used; anything that remains is a leak. SK.Clear(); SS.Clear(); return 0; }