Thread: Damn Simple Window Program

  1. #1
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178

    Damn Simple Window Program

    this has a malfuntion in it ONE ERROR!

    40 C:\Documents and Settings\Richard\Desktop\Win API.cpp expected primary-expression before ')' token

    ill comment it in the code

    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    
    char szClassName[ ] = "App";
    char WinName[ ] = "Windows API Test....";
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        MSG Msg;
        HWND hWnd;
        WNDCLASSEX cls;
        
        cls.cbSize = sizeof(WNDCLASSEX);
        cls.style = CS_HREDRAW | CS_VREDRAW;
        cls.lpfnWndProc = WindowProcedure;
        cls.cbClsExtra = 0;
        cls.cbWndExtra = 0;
        cls.hIcon = LoadIcon(NULL, IDI_ERROR);
        cls.hCursor = LoadCursor(NULL, IDC_NO);
        cls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        cls.lpszMenuName = NULL;
        cls.lpszClassName = szClassName;
        cls.hInstance = hInstance;
        cls.hIconSm = LoadIcon(NULL, IDI_ERROR);
        
        RegisterClassEx(&cls);
        
        hWnd = CreateWindow (szClassName, WinName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
        CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); 
        
        if( !hWnd )
        {
            return 0;
        }
        
        ShowWindow(hWnd, SW_SHOWNORMAL);
        UpdateWindow(hWnd);
        
        while( GetMessage(&Msg, NULL, 0, 0,) ) /* line 40 (error) */
        {
               TranslateMessage(&Msg);
               DispatchMessage(&Msg);
        }
        
        return Msg.wParam;
    }
        
    LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
            switch(Msg)
                {
                       case WM_DESTROY:
                                PostQuitMessage(WM_QUIT);
                                break;
                           default:
                                return DefWindowProc(hWnd, Msg, wParam, lParam);
                }
            return 0;
    }
    help please
    Last edited by C+noob; 07-11-2005 at 04:00 AM. Reason: Adding Sig
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

  2. #2
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    and for:
    Code:
    cls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    i want to get the background red i tried RED_BRUSH but it didnt work any ideas??

  3. #3
    Registered User r1ck0r's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    30
    For the first question, try this:
    Code:
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    -
    For the second question, you will have to create a red brush,
    Code:
    HBRUSH BackgroundBrush = CreateSolidBrush(RGB(255,0,0));
    Then,
    Code:
    cls.hbrBackground = BackgroundBrush;
    Don't forget to
    Code:
    DeleteObject(BackgroundBrush);
    When you're finished with it.
    Last edited by r1ck0r; 07-11-2005 at 04:48 AM.

  4. #4
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    wow thanks! but know i have double thee errors and createsold obj. thingy dontwork says undeclared (HBRUSH IS UNDECLARED)
    so i kept it white


    [Linker error] undefined reference to `GetStockObject@4'

    ld returned 1 exit status
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

  5. #5
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    i just deleted the hbrbackground attribute so it now compiles then exits quick
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

  6. #6
    Registered User r1ck0r's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    30
    Here's your code, works fine for me.

    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    
    char szClassName[ ] = "App";
    char WinName[ ] = "Windows API Test....";
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        MSG Msg;
        HWND hWnd;
        WNDCLASSEX cls;
        HBRUSH BackgroundBrush = CreateSolidBrush(RGB(255,0,0));
        
        cls.cbSize = sizeof(WNDCLASSEX);
        cls.style = CS_HREDRAW | CS_VREDRAW;
        cls.lpfnWndProc = WindowProcedure;
        cls.cbClsExtra = 0;
        cls.cbWndExtra = 0;
        cls.hIcon = LoadIcon(NULL, IDI_ERROR);
        cls.hCursor = LoadCursor(NULL, IDC_NO);
        cls.hbrBackground = BackgroundBrush;
        cls.lpszMenuName = NULL;
        cls.lpszClassName = szClassName;
        cls.hInstance = hInstance;
        cls.hIconSm = LoadIcon(NULL, IDI_ERROR);
        
        RegisterClassEx(&cls);
        
        hWnd = CreateWindow (szClassName, WinName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
        CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); 
        
        if( !hWnd )
        {
            return 0;
        }
        
        ShowWindow(hWnd, SW_SHOW);
        UpdateWindow(hWnd);
        
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
               TranslateMessage(&Msg);
               DispatchMessage(&Msg);
        }
    
        DeleteObject(BackgroundBrush);
    
        return Msg.wParam;
    }
        
    LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
            switch(Msg)
                {
                       case WM_DESTROY:
                                PostQuitMessage(WM_QUIT);
                                break;
                           default:
                                return DefWindowProc(hWnd, Msg, wParam, lParam);
                }
            return 0;
    }

  7. #7
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    [Linker error] undefined reference to `CreateSolidBrush@4'

    [Linker error] undefined reference to `DeleteObject@4'

    i think its my compiler what IDE do you use?
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

  8. #8
    Registered User r1ck0r's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    30
    I use Microsoft Visual C++ Pro 6.0, if you would listen to me in the other thread and create a windows project, I'm sure it will work, because you're using a blank project needed libraries are not getting included, gdi32.lib for example.

  9. #9
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    ok i did but still same ........


    Code:
    cls.hbrbackground = (HBRUSH)COLOR_BACKGROUND;
    if i cange it its ........s up
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

  10. #10
    Registered User r1ck0r's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    30
    You're still getting those linker errors?
    Are you definitely linking to gdi32.lib?

  11. #11
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    how do i know should i #include it
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

  12. #12
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Quote Originally Posted by C+noob
    how do i know should i #include it
    No. Don't #include anything other than header files. Check in the linker options ... it'll be buried in a menu somewhere.
    Away.

  13. #13
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    no no settingsa in the linker options reflectuing libraries but in another secxtion your able to include libraries buit i dont know were you would find the pone im lookin for
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

  14. #14
    Registered User joed's Avatar
    Join Date
    Mar 2004
    Posts
    59
    Code:
    while( GetMessage(&Msg, NULL, 0, 0,) ) /* line 40 (error) */
    extra comma after 0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  3. Making dialog box the only window
    By PJYelton in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2005, 12:02 PM
  4. Help with small simple program
    By Sonor in forum C Programming
    Replies: 5
    Last Post: 04-02-2005, 07:40 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM