quote: /* * HelloWorldW.CPP * * VERY simple windows application - opens a window with * "Hello World!" in it, waits for a keypress and then exits. * */ #define WIN32_LEAN_AND_MEAN #include /* forward declarations of some other functions that * we''ll code further down the file */ LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam); int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // pointer to command line int nCmdShow // show state of window ) { // Register our window class WNDCLASS wc; ATOM result; wc.style = 0; wc.lpfnWndProc = (WNDPROC)WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = gInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "HelloWorld"; result = RegisterClass(&wc); if (result) { // successfully registered our class // now we create a window HWND hWnd; hWnd = CreateWindow( "HelloWorld", // name of window class "HelloWorld #2", // caption on window (in titlebar) WS_OVERLAPPED/WS_MINIMIZEBOX/WS_BORDER/WS_SYSMENU/WS_CAPTION, // style 0,0, // x,y position 640,480, // width and height NULL, // NULL, // hInstance, // NULL // ); if (hWnd) { // successfully created a window. Yippee! ShowWindow(g_hWnd,SW_SHOWNORMAL); MSG msg; // Main message loop: while (GetMessage(&msg, hWnd, 0, 0)==TRUE) { TranslateMessage(&msg); // converts some keyboard messages into standard functions DispatchMessage(&msg); // this sends it off to the WndProc } } UnregisterClass("HelloWorld",hInstance); } return 0; } LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT ps; // used when repainting the window HDC hDC; // ditto - is a Device Context handle RECT r; // ditto - used to get the window rectangle char *message = "Hello World"; UINT cmd; // used when handling command messages switch( message ) { case WM_CREATE: // do anything you want here just before the window // is actually created. Not much (if anything) usually. break; case WM_COMMAND : cmd = HIWORD(wParam); // this is where you can process any command messages // usually with another switch statement on cmd break; case WM_PAINT : // we get this when windows wants us to redraw the // contents of the window (for whatever reason). hDC = BeginPaint (hWnd, &ps); GetClientRect(hWnd,&r); // just paint it black for now. FillRect(hDC,&r,(HBRUSH)GetStockObject(BLACK_BRUSH)); SetTextColor(hDC, RGB(255, 0, 0)); SetBkColor(hDC, RGB(0, 0, 0)); SetTextAlign(hDC, TA_CENTER); ExtTextOut(hDC, rect.right/2, rect.bottom/2, ETO_OPAQUE, NULL, message, strlen(message), NULL); EndPaint (hWnd, &ps); return 1; case WM_CLOSE : DestroyWindow(hWnd); break; case WM_DESTROY : PostQuitMessage(0); break; case WM_QUIT : done=TRUE; break; default : break; } // end switch (message) // If we haven''t handled the message then we are required // to pass it on to the default message handler that is // built in to windows. return DefWindowProc(hWnd, message, wParam, lParam); } // end Wndproc There is one Problem more. If I open the original *.cpp file with the C++Builder, it compiles ver well. But if I paste the code in a win32 Console Application, the compiler shows errors to me . Pls help me, I tried almost everything and it still doesn`t work. I hope, Microsoft will send me my orderd copy of Visual C++ soon, or I will go crazy. Help pls!!!
I have a damn Problem with the C++ Builder 3
If I create the basic skeleton of an window with that f***ing compiler, the code gets compiled well but if I want to start that application, it seems to run but the window does not appear. I give you an example of the code. I think it is from peamans homepage so it should be without any bugs.
Try adding "ws_visible" to the style line when you create the window. You will not need the ShowWindow command later. One less statement is one less line with a possible bug within it.
Also, when I make a window class I use the same hinstance as I used with the WinMain command. In your example you use gInstance while in WinMain you use hInstance.
It might not be the Builder compilier. I''ve had a similar problem when learning Win32 apps. I cann''t remember what the answer was but I had dropped a line somewhere.
Also, when I make a window class I use the same hinstance as I used with the WinMain command. In your example you use gInstance while in WinMain you use hInstance.
It might not be the Builder compilier. I''ve had a similar problem when learning Win32 apps. I cann''t remember what the answer was but I had dropped a line somewhere.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement