Advertisement

PeekMessage and GetMessage

Started by January 11, 2000 05:28 PM
0 comments, last by acw83 24 years, 11 months ago
Take a look at my code. All is well with GetMessage, but GetMessage sucks for games. When I try PeekMessage it exits the app or gives me an hourglass.... I hope HTML doesn''t screw this up... ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// // // // NAME: Triangle.cpp // // // // DESC: Draws a single triangle to a fullscreen // // surface. // // // // AUTH: Andrew C. White // // // // DATE: January 9, 2000 // // // ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// //============================================================ // Includes //============================================================ #include "stdafx.h" //============================================================ // Defines //============================================================ #define NAME "Triangle" #define WIDTH 800 #define HEIGHT 600 #define BPP 24 //============================================================ // Globals //============================================================ LPDIRECTDRAW7 lpDD =NULL; LPDIRECTDRAWSURFACE7 lpDDSFront =NULL; LPDIRECTDRAWSURFACE7 lpDDSBack =NULL; //============================================================ // Functions //============================================================ //============================= // ExitOnError //============================= void ExitOnError(HWND hWnd, LPSTR szError) { ShowCursor(TRUE); MessageBox(hWnd, szError, "Error", MB_OK); PostQuitMessage(0); return; } //============================= // WndProc //============================= LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_CREATE: // Initialize the app. { if( FAILED (DirectDrawCreateEx(NULL, (VOID**)&lpDD, IID_IDirectDraw7, NULL)) ) ExitOnError(hWnd, "ERROR: DirectDrawCreateEx failed!"); if( FAILED (lpDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE / DDSCL_FULLSCREEN)) ) ExitOnError(hWnd, "ERROR: SetCooperationLevel failed!"); if( FAILED (lpDD->SetDisplayMode(WIDTH, HEIGHT, BPP, NULL, NULL)) ) ExitOnError(hWnd, "ERROR: SetDisplayMode failed!"); DDSURFACEDESC2 ddsd; DDSCAPS2 ddscaps; ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS / DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE / DDSCAPS_FLIP / DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; if( FAILED (lpDD->CreateSurface(&ddsd, &lpDDSFront, NULL)) ) ExitOnError(hWnd, "ERROR: CreateSurface failed!"); ZeroMemory(&ddscaps, sizeof(ddscaps)); ddscaps.dwCaps = DDSCAPS_BACKBUFFER; if( FAILED (lpDDSFront->GetAttachedSurface(&ddscaps, &lpDDSBack)) ) ExitOnError(hWnd, "ERROR: GetAttachedSurface failed!"); return(0); } break; case WM_DESTROY: // Shut down the app. { if( lpDDSFront ) lpDDSFront->Release(); if( lpDD ) lpDD->Release(); lpDDSFront =NULL; lpDD =NULL; return(0); } break; case WM_KEYDOWN: // Process keyboard input. { switch((int) wParam) { case VK_ESCAPE: { PostQuitMessage(0); } break; default: break; } return(0); } break; } return (DefWindowProc(hWnd, message, wParam, lParam)); } //============================= // WinMain //============================= int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX winclass = { sizeof(winclass), CS_OWNDC / CS_HREDRAW / CS_VREDRAW, WndProc, NULL, NULL, hInstance, LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), (HBRUSH) GetStockObject(BLACK_BRUSH), NULL, "winclass", LoadIcon(NULL, IDI_APPLICATION) }; RegisterClassEx(&winclass); HWND hWnd = CreateWindowEx(WS_EX_TOPMOST, "winclass", NAME, WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); MSG message; while(1) { if( !GetMessage(&message, NULL, NULL, NULL) ) break; TranslateMessage(&message); DispatchMessage(&message); } return (0); }
I am an idiot, I solved my own problem 3 minuets after post...

This topic is closed to new replies.

Advertisement