bool CreateMainWindow( const HINSTANCE i_thisInstanceOfTheProgram, const int i_initialWindowDisplayState ) { // Every window that Windows creates must belong to a "class". // Note that this is different than a C++ class (but similar in theory): // A windows class defines things that will be the same for every window // that belongs to the class. // (In other words, every window will have exactly one class, // but a windows class can have many windows.) // To create a new windows class it must be "registered" with Windows. ATOM mainWindowClass = RegisterMainWindowClass( i_thisInstanceOfTheProgram ); if ( mainWindowClass != NULL ) { s_mainWindow = CreateMainWindowHandle( i_thisInstanceOfTheProgram, i_initialWindowDisplayState ); if ( s_mainWindow == NULL ) { goto OnError; } return true; OnError: // Unregister the main window class { UnregisterMainWindowClass( i_thisInstanceOfTheProgram ); mainWindowClass = NULL; } return false; } else { return false; } }
/***************************************************************************** INT WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) hInst : (IN) Instance handle hPrevInstance : not used szCmdLine : not used iCmdShow : (IN) the state the user wants the window to be in Return Value: returns value of the main window *****************************************************************************/ INT WINAPI WinMain (HINSTANCE hInst, HINSTANCE /*hPrevInstance*/, LPSTR /*szCmdLine*/, int iCmdShow) { MSG msg; HWND mainHwnd; BOOL bPipeNecessary; lFILEINFO *fileList; HANDLE hMutex; g_hInstance = hInst; g_pstatus.bHaveComCtrlv6=CheckOsVersion(5,1); //are the common controls v6 available? (os>=winxp) g_pstatus.bIsVista=CheckOsVersion(6,0); g_pstatus.bHideVerified = false; InitializeCriticalSection(&thread_fileinfo_crit); hMutex = CreateMutex(NULL,FALSE,TEXT("Local\\RapidCRCUMutex")); if(!hMutex) { return 0; } WaitForSingleObject(hMutex,INFINITE); ReadOptions(); fileList = ParseCommandLine(&bPipeNecessary); if(fileList==NULL) { return 0; } RegisterMainWindowClass(); if (!(mainHwnd = InitInstance(iCmdShow))) { MessageBox(NULL, TEXT("Program uses Unicode and requires Windows NT or higher"), TEXT("Error"), MB_ICONERROR); return 0; } if(bPipeNecessary) { PostMessage(mainHwnd,WM_ACCEPT_PIPE,(WPARAM)fileList->uiCmdOpts,NULL); delete fileList; } else { PostMessage(mainHwnd,WM_THREAD_FILEINFO_START,(WPARAM)fileList,NULL); fileList=NULL; } ReleaseMutex(hMutex); while(GetMessage(&msg, NULL, 0, 0)) { if (!IsDialogMessage(mainHwnd, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } DeleteCriticalSection(&thread_fileinfo_crit); return (INT) msg.wParam; }
/* Our application entry point */ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpszCmdLine, int nCmdShow) { INITCOMMONCONTROLSEX icc; HWND hWnd; HACCEL hAccelerators; MSG msg; /* Assign global HINSTANCE */ g_hInstance = hInstance; /* Initialise common controls */ icc.dwSize = sizeof(icc); icc.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&icc); /* Register our main window class, or error */ if (!RegisterMainWindowClass()) { MessageBox(NULL, TEXT("Error registering main window class."), TEXT("Error"), MB_ICONERROR | MB_OK); return 0; } /* Create our main window, or error */ if (!(hWnd = CreateMainWindow())) { MessageBox(NULL, TEXT("Error creating main window."), TEXT("Error"), MB_ICONERROR | MB_OK); return 0; } /* Load accelerators */ hAccelerators = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR)); /* Show main window and force a paint */ ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); /* Main message loop */ while (GetMessage(&msg, NULL, 0, 0) > 0) { if (!TranslateAccelerator(hWnd, hAccelerators, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int)msg.wParam; }
/* Our application entry point */ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; HACCEL hAccelerators; MSG msg; /* Assign global HINSTANCE */ g_hInstance = hInstance; /* Register our main window class, or error */ if (!hPrevInstance && !RegisterMainWindowClass()) { MessageBox(NULL, "Error registering main window class.", "Error", MB_ICONHAND | MB_OK); return 0; } /* Create our main window, or error */ if (!(hWnd = CreateMainWindow())) { MessageBox(NULL, "Error creating main window.", "Error", MB_ICONHAND | MB_OK); return 0; } /* Load accelerators */ hAccelerators = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR)); /* Show main window and force a paint */ ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); /* Main message loop */ while (GetMessage(&msg, NULL, 0, 0) > 0) { if (!TranslateAccelerator(hWnd, hAccelerators, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return (int)msg.wParam; }
HWND CreateMainWindow() { RegisterMainWindowClass(); SIZE windowSize; DetermineWindowSize(&windowSize); HWND result = ::CreateWindow( WINDOW_CLASS, "Arkanoid", WINDOW_STYLE, CW_USEDEFAULT, CW_USEDEFAULT, windowSize.cx, windowSize.cy, NULL, // root window NULL, // no menu g_hInstance, NULL // no params ); if (result == NULL) throw WINException("Screen::Init(): CreateWindow(): "); return result; }