The main program loop itself needs to acknowledge Windows messages by allowing Windows the opportunity to run the static message proc. A full, production app needs to handle other windowing events too-for the complete list of windowing events, see Window Notifications. This simple example only checks for program exit conditions: WM_CLOSE, sent when the window is requested to be closed, and WM_DESTROY, which is sent after the window is actually removed from the screen. Return DefWindowProc(hWnd, uMsg, wParam, lParam) LRESULT CALLBACK MainClass::StaticWindowProc( Here's a very simple example of a static message processing function. This must be a static function because Windows will call it outside of the context of any class instance. You'll need to base your main program loop off of this hook by writing a "StaticWindowProc" function to process windowing events. The Windows desktop app model includes a hook into the Windows message loop. SetRect(&m_rc, 0, 0, nDefaultWidth, nDefaultHeight) This example uses a non-resizable 640 by 480 viewport for simplicity. When you call CreateWindow, you get back an opaque pointer to the window called an HWND you'll need to keep the HWND pointer and use it any time you need to reference the window, including destroying or recreating it, and (especially important) when creating the DXGI swap chain you use to draw in the window. We also need to provide size information for the window and the name of the window class we just created. If(dwError != ERROR_CLASS_ALREADY_EXISTS) ![]() WndClass.lpszClassName = m_windowClassName.c_str() WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH) WndClass.hCursor = LoadCursor(NULL, IDC_ARROW) ![]() WndClass.lpfnWndProc = MainClass::StaticWindowProc HIcon = ExtractIcon(m_hInstance, szExePath, 0) If the icon is NULL, then use the first one found in the exe GetModuleFileName(NULL, szExePath, MAX_PATH) M_hInstance = (HINSTANCE)GetModuleHandle(NULL) The window class contains essential properties of the window, including the icon it uses, the static message processing function (more on this later), and a unique name for the window class. First, create a window class by populating an instance of WNDCLASS, then register it using RegisterClass. The first thing we need to do is create a window.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |