Menu

WinMain Function

starcreek
2008-01-05
2012-09-26
  • starcreek

    starcreek - 2008-01-05

    Ok theres my basic 3:

    1. Dev Version 4.9.9.2 with windows 2002

    2. I'm trying to create a window using the WinMain() function.

    LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wPARAM,
    LPARAM 1Param)
    {
    switch(msg)
    {
    case WM_DESTROY:
    PostQuitMessage(0);
    return 0;
    break;
    }

             return DefWindowProc(hWnd, msg, wParam, 1Param);
             }
    
             int WINAPI WinMain(HINSTANCE hInst, HINSTANCE prevhInst,
                                LPSTR cmd, int show)
             {
                WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 
                                  0, 0, hInst, NULL,
                                  NULL, NULL, NULL, "AppClass", NULL };
    
                RegisterCLassEx(&wc);
    
                HWND hWnd = CreateWIndow("AppClass", "Window Title",
                               WS_OVERLAPPEDWINDOW, 100, 100, 640, 480,
                               NULL, NULL, hInst, NULL);
    
                ShowWindow(hWnd, SW_SHOWDEAFUALT);
                UpdateWIndow(hWnd);
    
                // entejr sloop
                Msg msg;
    
                Zero Memory(&msg, sizeof(msg));
    
                while(msg.message != VM_QUIT)
                   {
                  if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
                         {
                            TranslateMessage(&msg);
                            DispatchMessage(&msg);
                            }
                         else
                            {
                               // dosmething to thes cren
                               }
                               }
    
                               UnregisterdClass("AppClass", wc. hInstance);
                               }
    

    3

    1. My compile Log:
      Compiler: Default compiler
      Executing g++.exe...
      g++.exe "C:\Dev-Cpp\1.2.cpp" -o "C:\Dev-Cpp\1.2.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
      C:\Dev-Cpp\1.2.cpp:1: error: LRESULT' does not name a type C:\Dev-Cpp\1.2.cpp:2:31: invalid suffix "Param" on integer constant C:\Dev-Cpp\1.2.cpp:12:54: invalid suffix "Param" on integer constant C:\Dev-Cpp\1.2.cpp:15: error:WINAPI' does not name a type

    Execution terminated

     
    • cpns

      cpns - 2008-01-05

      You have not included <windows.h> where such things as LRESULT and WINAPI are defined.

      Do not put your projects or source in c:\dev-cpp. Apart from being a fundamentally bad idea to 'pollute' an application installation, it sometimes causes problems that prevent Dev-C++ from building the code.

      The easiest way to get started with a Win32 GUI app is to start wit the provided Win32 GUI template project. It will ensure that all the correct compiler and linker settings are applied as well as providing a minimal Win32 framework to get you started. File->New->Project

      Symbols in C/C++ may not start with a number (only alphabetic or underscore). On lines 2 and 12 you have 1Param where you meant lParam (lowercase-L and the number 1 are almost indistinguishable in Courier font, but context is usually sufficient to distinguish them. Unfortunately many programming books use Courier). Try using a programming font where such characters are more clearly distinguishable. I recommend Consolas ( http://www.microsoft.com/downloads/details.aspx?familyid=22e69ae4-7e40-4807-8a86-b3d36fab68d3&displaylang=en )

      Symbols in C/C++ (or any other programming language I am aware of) cannot contain spaces. So you may want to reconsider this line:

      Zero Memory(&msg, sizeof(msg));

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.