Thread: Win32 API, Help

  1. #1
    Banned
    Join Date
    May 2004
    Posts
    55

    Win32 API, Help

    I just wrote this program, whats wrong? I get a lot of errors >.<

    Code:
    #include <windows.h>
    const char classnamn[] = "myWinClass";
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam,
                            LPARAM lParam);
    
    {
      switch(msg)
        {
            case WM_CLOSE:
            DestroyWindow(hwnd);
            break;
            case WM_DESTROY:
            PostQuitMessage(0);
            break;
            default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
        }
    return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE
                        hPrevInstance, LPSTR lpCmdLine,
                         int nCmdShow)
    {
        WNDCLASSEX b;
        HWND hwnd;
        MSG msg;
        
        b.cbSize = sizeof(WNDCLASSEX);
        b.style = 0;
        b.lpfnWndProc = WndProc;
        b.cbClsExtra = 0;
        b.cbWndExtra = 0;
        b.hInstance = hInstance;
        b.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        b.hCursor = LoadCursor(NULL, IDC_ARROW);
        b.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        b.lpszMenuName = NULL;
        b.lpszClassName = classnamn;
        b.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
        
        if(!RegisterClassEx(&b))
        {
            MessageBox(NULL, "Window Registration Failed!",
                            "Error!", MB_OK | MB_ICONERROR);
        return 0;
        }
        
        hwnd = CreateWindowEx(
                WS_EX_CLIENTEDGE,
                classnamn,
                "Title",
                WS_OVERLAPPEDWINDOW,
                CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,
                NULL, NULL, hInstance, NULL);
        
        if(hwnd == NULL)
        {
            MessageBox(NULL, "Window Creation Failed!",
                            "Error", MB_OK | MB_ICONERROR);
            return 0;
        }
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
        
        while(GetMessage(&Msg), NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Here ya go
    This:
    Code:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam,
                            LPARAM lParam);
    should not have the ; at the end
    This:
    Code:
    MSG msg;
    should be
    Code:
    MSG Msg
    Last but not least This:
    Code:
        while(GetMessage(&Msg), NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
    Should be
    Code:
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
    Woop?

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    should be
    Code:
    MSG Msg
    should be
    Code:
    MSG Msg;
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Thanks hunter you meany
    Woop?

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    or he could change the calls to Msg.(member) to msg.(member) :P

    Note: Although I like my food without msg... (I am so sorry for that, but if i didnt post it, I wouldnt have been able to sleep)

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    I figured that it would involve less typing for me if I told him to just do it that way
    Woop?

  7. #7
    Banned
    Join Date
    May 2004
    Posts
    55
    thnks xD

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  2. OpenSSL and Win32 SSL API :: SSL/TLS
    By kuphryn in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-10-2004, 07:46 PM
  3. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  4. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  5. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 09:09 AM