| CODE |
bool InitWindowApp(HINSTANCE instanceHandle, int Show); int Run(); LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nShowCmd) { if(!InitWindowApp(hInstance, nShowCmd)) { ::MessageBox(0, "Failed to create Window!", "Fail", MB_OK); return 0; } } bool InitWindowApp(HINSTANCE instanceHandle, int Show) { WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = instanceHandle; wc.hIcon = ::LoadIcon(0, IDI_APPLICATION); wc.hCursor = ::LoadCursor(0, IDC_ARROW); wc.hbrBackground = (HBRUSH) ::GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = "MyWindow"; if(!::RegisterClass(&wc)) { ::MessageBox(0, "Failed to register Window!", "Fail", MB_OK); return false; } MainWindowHandle = ::CreateWindow("MyWindow", "MyWindow", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, instanceHandle, 0); if(MainWindowHandle == 0) { ::MessageBox(0, "Failed to create Window!", "Fail", MB_OK); return false; } ::ShowWindow(MainWindowHandle, Show); ::UpdateWindow(MainWindowHandle); return true; } int Run() { MSG msg; while(true) { if(::PeekMessage(&msg,0,0,0,PM_REMOVE)) { if(msg.message == WM_QUIT) { break; } ::TranslateMessage(&msg); ::DispatchMessage(&msg); } } return msg.wParam; } LRESULT CALLBACK WndProc(HWND windowHandle, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_KEYDOWN: if(wParam == VK_ESCAPE) { ::DestroyWindow(MainWindowHandle); } return 0; case WM_DESTROY: ::PostQuitMessage(0); return 0; } return ::DefWindowProc(windowHandle, msg, wParam, lParam); } |
Hi
I`m new to c++ .. i do most of windows programing in C#.. but i also want to learn C++.. not C++ .NET .. i understand that the code above creates a window.. i dont understnad..
i cand see void main() how ill this start f void main isnt there

simle form in c++
Tamer Shaaban
Zappo
Stephan Ruhland
kawano1h
Instead of main, it has WinMain which is the entry point for applications targetting the GUI subsystem (as opposed to the console).
See http://msdn.microsoft.com/library/default.asp url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/winmain.asp