by voided » Dec 22, 2001 @ 9:53pm
Well I used peekmessage(). I'm currently using a Debug build but I have also tried the Release Build. The following is the code of my main file.<br><br>#include "stdafx.h"<br>#include <commctrl.h><br>#include <aygshell.h><br>#include "XSprite.h"<br>#include "XConsole.h"<br><br>//Menu Bar Height<br>#define MENU_HEIGHT 26<br>#define MAX_LOADSTRING 100<br>#define APP_TITLE TEXT("XConsole")<br>#define WINDOW_CLASS TEXT("MainWindow")<br><br>// Global Variables:<br>HINSTANCE hInst; // The current instance<br>HWND hwndCB; // The command bar handle<br><br>// Foward declarations of functions included in this code module:<br>ATOM MyRegisterClass (HINSTANCE hInstance, LPTSTR szWindowClass);<br>BOOL InitInstance (HINSTANCE, int);<br>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);<br><br><br> //Global variables for XConsoles <br>DWORD presentTickValue, startTickValue, nextSecondTickValue;<br>int fps = 0, frameCounter = 0;<br>HWND XConsolehWnd;<br><br>HDC XConsoleBackBufferHDC;<br>HBITMAP XConsoleBackBufferHANDLER;<br>BITMAP XConsoleBackBufferBITMAP;<br>void* pXConsoleOffScreen;<br>int sizeofBackBuffer;<br><br>GXDisplayProperties g_gxdp;<br>void* pFrameBuffer;<br><br><br>XSprite *testSprite = new XSprite(TEXT("..\\Test.bmp"));<br><br><br><br>int WINAPI WinMain( HINSTANCE hInstance,<br> HINSTANCE hPrevInstance,<br> LPTSTR lpCmdLine,<br> int nCmdShow)<br>{<br> MSG msg;<br> <br> // Look for running instance of application<br> if (FindWindow(WINDOW_CLASS, APP_TITLE)){<br> SetForegroundWindow(FindWindow(WINDOW_CLASS, APP_TITLE));<br> return FALSE;<br> }<br> // Perform application initialization:<br> if (!InitInstance (hInstance, nCmdShow)) <br> {<br> return FALSE;<br> }<br> <br> // Main message loop:<br> BOOL endLoop = FALSE;<br> while (!endLoop) <br> {<br> if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))<br> {<br> if(msg.message == WM_QUIT)<br> endLoop = TRUE;<br> // Dispatch the message<br> TranslateMessage(&msg);<br> DispatchMessage(&msg);<br> }<br> else<br> {<br> presentTickValue = GetTickCount();<br> if(nextSecondTickValue < presentTickValue)<br> {<br> fps = frameCounter;<br> frameCounter = 0;<br> nextSecondTickValue = presentTickValue + 1000;<br> }<br> else<br> frameCounter++;<br> <br> testSprite->draw(0, 0);<br> updateConsole();<br> }<br> }<br><br> return msg.wParam;<br>}<br><br>//<br>// FUNCTION: MyRegisterClass()<br>//<br>// PURPOSE: Registers the window class.<br>//<br>// COMMENTS:<br>//<br>// This function and its usage is only necessary if you want this code<br>// to be compatible with Win32 systems prior to the 'RegisterClassEx'<br>// function that was added to Windows 95. It is important to call this function<br>// so that the application will get 'well formed' small icons associated<br>// with it.<br>//<br>ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)<br>{<br> WNDCLASS wc;<br> <br> wc.style = CS_HREDRAW | CS_VREDRAW;<br> wc.lpfnWndProc = (WNDPROC) WndProc;<br> wc.cbClsExtra = 0;<br> wc.cbWndExtra = 0;<br> wc.hInstance = hInstance;<br> wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(WINDOW_CLASS));<br> wc.hCursor = 0;<br> wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);<br> wc.lpszMenuName = 0;<br> wc.lpszClassName = szWindowClass;<br> <br> return RegisterClass(&wc);<br>}<br><br>//<br>// FUNCTION: InitInstance(HANDLE, int)<br>//<br>// PURPOSE: Saves instance handle and creates main window<br>//<br>// COMMENTS:<br>//<br>// In this function, we save the instance handle in a global variable and<br>// create and display the main program window.<br>//<br>BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)<br>{<br> HWND hWnd;<br> <br> hInst = hInstance; // Store instance handle in our global variable<br> // Initialize global strings<br> MyRegisterClass(hInstance, WINDOW_CLASS);<br> <br> XConsolehWnd = hWnd = CreateWindow(WINDOW_CLASS, APP_TITLE, WS_VISIBLE,<br> CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);<br> <br> if (!hWnd)<br> { <br> SetForegroundWindow ((HWND)(((DWORD)hWnd) | 0x01)); <br> return FALSE;<br> }<br> //When the main window is created using CW_USEDEFAULT the height of the menubar (if one<br> // is created is not taken into account). So we resize the window after creating it<br> // if a menubar is present<br> {<br> <br> RECT rect;<br> GetClientRect(hWnd, &rect); <br> <br> RECT rc;<br> GetWindowRect(hWnd, &rc);<br> rc.bottom -= MENU_HEIGHT;<br> if (hwndCB)<br> MoveWindow(hWnd, rc.left, rc.top, rc.right, rc.bottom, FALSE);<br> }<br> <br> <br> ShowWindow(hWnd, nCmdShow);<br> UpdateWindow(hWnd);<br><br> return TRUE;<br>}<br><br>//<br>// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)<br>//<br>// PURPOSE: Processes messages for the main window.<br>//<br>// WM_COMMAND - process the application menu<br>// WM_PAINT - Paint the main window<br>// WM_DESTROY - post a quit message and return<br>//<br>//<br>LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)<br>{<br><br> PAINTSTRUCT ps;<br><br> switch (message) <br> {<br> case WM_COMMAND:<br> break;<br><br> case WM_CREATE:<br> SHFullScreen(hWnd, SHFS_HIDETASKBAR);<br> HDC winDC;<br> winDC = GetDC(hWnd);<br> RECT rcMain;<br> rcMain.left = 0; <br> rcMain.top = 0;<br> rcMain.right = GetDeviceCaps(winDC, HORZRES);<br> rcMain.bottom = GetDeviceCaps(winDC, VERTRES);<br> MoveWindow(hWnd, rcMain.left, rcMain.top, rcMain.right, rcMain.bottom, TRUE); <br> ShowWindow(hWnd, SW_SHOW);<br> ReleaseDC(hWnd, winDC); <br> // Setting up the XConsole<br> intializeXConsole();<br> break;<br> <br> case WM_LBUTTONDOWN:<br> SendMessage(hWnd,WM_CLOSE,0,0);<br> break;<br><br> case WM_PAINT:<br> BeginPaint(hWnd, &ps);<br> EndPaint(hWnd, &ps);<br> <br> break; <br> case WM_HIBERNATE:<br> //Release any large memory resources here<br> break;<br><br> case WM_ACTIVATE:<br> break;<br><br> case WM_DESTROY:<br> // Freeing up all the resources used by XConsole<br> destroyXConsole();<br> DestroyWindow(hwndCB);<br> PostQuitMessage(0);<br><br> break;<br><br> default:<br> return DefWindowProc(hWnd, message, wParam, lParam);<br><br> }<br> return 0;<br>}<br><br>void intializeXConsole(void)<br>{<br><br> // Initial the GAPI and get the framebuffer<br> GXOpenDisplay(XConsolehWnd, GX_FULLSCREEN);<br> g_gxdp = GXGetDisplayProperties();<br><br> // Creates the off screen buffer<br> HDC hScreenDC;<br> hScreenDC = GetDC(0);<br> XConsoleBackBufferHDC = CreateCompatibleDC(hScreenDC);<br><br> //Initialize the DIB header for the backbuffer<br> BYTE buffer[sizeof(BITMAPINFOHEADER) + 3 * sizeof(RGBQUAD)];<br><br> // Handy pointers<br> BITMAPINFO* pBMI = (BITMAPINFO*) buffer;<br> BITMAPINFOHEADER* pHeader = &pBMI->bmiHeader;<br> DWORD* pColors = (DWORD*)&pBMI->bmiColors; <br><br> // DIB Header<br> pHeader->biSize = sizeof(BITMAPINFOHEADER);<br> pHeader->biWidth = g_gxdp.cxWidth;<br> pHeader->biHeight = -(long)g_gxdp.cyHeight;<br> pHeader->biPlanes = 1;<br> pHeader->biBitCount = (WORD)g_gxdp.cBPP;<br> pHeader->biCompression = BI_BITFIELDS;<br> pHeader->biSizeImage = sizeofBackBuffer <br> = (g_gxdp.cxWidth * g_gxdp.cyHeight * g_gxdp.cBPP) / 8;<br> pHeader->biXPelsPerMeter = 0;<br> pHeader->biYPelsPerMeter = 0;<br> pHeader->biClrUsed = 0;<br> pHeader->biClrImportant = 0;<br><br> // Color masks<br> if (g_gxdp.ffFormat & kfDirect555)<br> {<br> pColors[0] = 0x1F << 10;<br> pColors[1] = 0x1F << 5;<br> pColors[2] = 0x1F;<br> }<br> else if (g_gxdp.ffFormat & kfDirect565)<br> {<br> pColors[0] = 0x1F << 11;<br> pColors[1] = 0x3F << 5;<br> pColors[2] = 0x1F;<br> }<br> else if (g_gxdp.ffFormat & kfDirect888)<br> {<br> pColors[0] = 0x00FF0000;<br> pColors[1] = 0x0000FF00;<br> pColors[2] = 0x000000FF;<br> }<br> else if (g_gxdp.ffFormat & kfDirect444)<br> {<br> pColors[0] = 0x0F00;<br> pColors[1] = 0x00F0;<br> pColors[2] = 0x000F;<br> }<br> <br> XConsoleBackBufferHANDLER = CreateDIBSection( hScreenDC, pBMI, DIB_RGB_COLORS, &pXConsoleOffScreen,<br> 0, 0 );<br> GetObject(XConsoleBackBufferHANDLER, sizeof(BITMAP), &XConsoleBackBufferBITMAP);<br><br> SelectObject(XConsoleBackBufferHDC, XConsoleBackBufferHANDLER);<br> // Initialize the ticker<br> nextSecondTickValue = GetTickCount() + 1000;<br><br> ReleaseDC(0,hScreenDC);<br> pFrameBuffer = GXBeginDraw();<br>}<br><br><br><br>void destroyXConsole(void)<br>{<br> DeleteDC(XConsoleBackBufferHDC);<br> DeleteObject(XConsoleBackBufferHDC);<br> GXEndDraw();<br> GXCloseDisplay();<br>}<br><br><br><br>void updateConsole(void)<br>{<br> RECT rt;<br> GetClientRect(XConsolehWnd, &rt);<br> unsigned short strBuffer[10];<br><br> swprintf(strBuffer,L"FPS: %ld", fps);<br> // Draws to the back buffer<br> DrawText(XConsoleBackBufferHDC, strBuffer, _tcslen(strBuffer), &rt,<br> DT_SINGLELINE);<br><br> <br><br> memcpy(pFrameBuffer, pXConsoleOffScreen, sizeofBackBuffer);<br><br>}