Results 1 to 24 of 24

Thread: CreateWindow Problem

  1. #1

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Unhappy CreateWindow Problem

    PHP Code:
        //create the window
        
    g_Hwnd = ::CreateWindow g_szClassName
            
    g_szCaption,
            
    WS_MINIMIZEBOX WS_SYSMENU,
            
    CW_USEDEFAULTCW_USEDEFAULT,
            
    300
            
    NULL,
            
    NULL,
            
    hInstance,
            
    NULL);

        if (
    g_Hwnd == NULL)
        {
            
    MessageBox (NULL"Window Creation failed""PAManipulator Error"MB_OK);
                return 
    0;
        } 
    when i do this, it gives me the following errors:

    Code:
    C:\My Documents\C++ Projects (Clean + Efficient)\Parrallel Port Assignment\Init.cpp(45) : warning C4003: not enough actual parameters for macro 'CreateWindowA'
    C:\My Documents\C++ Projects (Clean + Efficient)\Parrallel Port Assignment\Init.cpp(45) : error C2059: syntax error : ')'
    Error executing cl.exe.
    Amon Ra
    The Power of Learning.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I think you forgot the height of the window (after 300)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    i thought about this too, but when i open the bracket in VC++ and it shows me the parameters, there is no nHeight parameter..
    i checked in the MSDN and it did show nHeight as being in the parameters..
    Amon Ra
    The Power of Learning.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    rightclick createwindow and press definition, then you should see something like this as you do the same with CreateWindowA:

    #define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y,\
    nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)\
    CreateWindowExA(0L, lpClassName, lpWindowName, dwStyle, x, y,\
    nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)

    Paste it here, if it doesn't have that nHeight parameter
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    huh?? i checked and it is there!

    that's exactly what i have

    PHP Code:
    #define CreateWindowA(lpClassName, lpWindowName, dwStyle, x, y,\
    nWidthnHeighthWndParenthMenuhInstancelpParam)\
    CreateWindowExA(0LlpClassNamelpWindowNamedwStylexy,\
    nWidthnHeighthWndParenthMenuhInstancelpParam
    ??
    Amon Ra
    The Power of Learning.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    well eh, maybe you have another function somewhere where you forgot to put in nHeight. Id doesn't matter what VC++ pop up in the tool tip (btw when theres several with the same name you can scroll them) just type in the height and it should choose the correct overloaded function.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    ok i did it and i got no errors
    but sorry to bother but in this

    PHP Code:
    BOOL InitInstance (void)
    {
            
    BOOL bRet FALSE;

            
    g_Hwnd CreateWindow (
                    
    g_szClassName,
                    
    g_szCaption,
                    
    WS_MINIMIZEBOX  WS_SYSMENU,
                    
    CW_USEDEFAULTCW_USEDEFAULT,
                    
    300200,
                    
    NULL,
                    
    NULL,
                    
    g_hInstance,
                    
    NULL
                    );

            
    ShowWindow (g_HwndSW_SHOW);
            
    UpdateWindow (g_Hwnd);

            if (
    g_Hwnd == 0)
            {
                    
    MessageBox (NULL"Window Creation Error""PAManipulator Error"MB_OK);
                    
    bRet FALSE;
            }
            else
                    
    bRet TRUE;

                 return 
    bRet;

    do you see any errors because when i run the program it does pop the "Window Creation Error".
    Amon Ra
    The Power of Learning.

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Nope, it's probably embeded in what you've got in those variables. Have you got the window class registered?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    yea with another one of my funcs

    PHP Code:
    BOOL InitApplication (void)
    {
            
    BOOL bRet FALSE;
            
    WNDCLASS wc;

            
    //set up info
            
    wc.style 0;
            
    wc.cbClsExtra 0;
            
    wc.cbWndExtra 0;
            
    wc.hbrBackground = (HBRUSH) (COLOR_WINDOW 1);
            
    wc.hCursor LoadCursor (g_hInstanceIDC_ARROW);
            
    wc.hIcon LoadCursor (g_hInstanceMAKEINTRESOURCE (IDI_ICON));
            
    wc.hInstance g_hInstance;
            
    wc.lpfnWndProc WndProc;
            
    wc.lpszClassName g_szClassName;
            
    wc.lpszMenuName NULL;
        
            
    bRet RegisterClass (&wc);
                return 
    bRet;

    these are teh variables i use

    PHP Code:
    charg_szClassName "Port Manipulator";
    HINSTANCE g_hInstance;
    HWND g_Hwnd;                        //storage for the handle of our window

    charg_szCaption "Port Manipulator";                //caption of window 
    Amon Ra
    The Power of Learning.

  10. #10
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    put this one in too:
    wc.cbSize = sizeof(WNDCLASSEX);
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  11. #11

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    so now i have

    PHP Code:
    BOOL InitApplication (void)
    {
            
    BOOL bRet FALSE;
            
    WNDCLASSEX wc;

            
    //set up info
            
    wc.style 0;
            
    wc.cbSize sizeof(WNDCLASSEX);
            
    wc.cbClsExtra 0;
            
    wc.cbWndExtra 0;
            
    wc.hbrBackground = (HBRUSH) (COLOR_WINDOW 1);
            
    wc.hCursor LoadCursor (g_hInstanceIDC_ARROW);
            
    wc.hIcon LoadCursor (g_hInstanceMAKEINTRESOURCE (IDI_ICON));
            
    wc.hInstance g_hInstance;
            
    wc.lpfnWndProc WndProc;
            
    wc.lpszClassName g_szClassName;
            
    wc.lpszMenuName NULL;
        
            
    bRet RegisterClassEx (&wc);
                return 
    bRet;

    no errors, but nothing shows..since i didn't add any error messages in that function, there is probably an error in the registration
    Amon Ra
    The Power of Learning.

  12. #12

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    yea, ijust checked and there is an error in the registration
    Amon Ra
    The Power of Learning.

  13. #13

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    i got rid of the registration erro by adding in

    wc.IconSm = ...

    but i still have a creation error..
    Amon Ra
    The Power of Learning.

  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    humm dunno :/
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  15. #15

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    well...i had this problem before and so i was using createwindowex with a non-ex style as the dwexstyle param.. but cornedbee pointed out to me that it was WRONG so if it doesn't work when i call CreateWindow, what should i do?
    Amon Ra
    The Power of Learning.

  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You have not enough normal window styles. e.g. you don't specify what border you want (WS_BORDER, WS_SIZEBOX, WS_THICKBORDER etc.)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  17. #17
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    WS_OVERLAPPEDWINDOW is a good start (just use that, it's a combination of other styles).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  18. #18

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    i still get that stupid message box with "Window Creation Failed"

    i changed the style to WS_OVERLAPPEDWINDOW

    PHP Code:
    BOOL InitInstance (void)
    {
            
    BOOL bRet FALSE;

            
    g_Hwnd CreateWindow (
                    
    g_szClassName,
                    
    g_szCaption,
                    
    WS_OVERLAPPEDWINDOW,
                    
    CW_USEDEFAULTCW_USEDEFAULT,
                    
    300200,
                    
    NULL,
                    
    NULL,
                    
    g_hInstance,
                    
    NULL
                    );

            if (
    g_Hwnd == 0)
            {
                    
    MessageBox (NULL"Window Creation Error""PAManipulator Error"MB_OK);
                    
    bRet FALSE;
            }
            else
            {
                    
    bRet TRUE;
            }

            
    ShowWindow (g_HwndSW_SHOW);
            
    UpdateWindow (g_Hwnd);

                 return 
    bRet;

    but no difference...
    Amon Ra
    The Power of Learning.

  19. #19

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    i looked everywhere, i dont get it.. i think that i shouldn't have tried to add the nHeight value when there is n't any parameter of that name when VC++ shows the tool tip..that's prob what makes the msgbox pop up..
    anyone have any ideas? thanks
    Amon Ra
    The Power of Learning.

  20. #20
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yeah. Upload the whole thing.

    The VC++ bug with CreateWindow lacking the height parameter in the tooltip is known (at least to me ). You'll have to remember it for this common-used function.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  21. #21

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    ok there..and like you also told me i had a bad coding style..i am trying to make it better...
    i just started this so it wont do anything..
    Amon Ra
    The Power of Learning.

  22. #22
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Your WndProc is malformed. Here is a corrected version:
    Code:
    LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch (msg)
    	{
    	case WM_CLOSE:
    			DestroyWindow (hwnd);
    			Clean ();
    			PostQuitMessage (0);
    		return 0;
    	}
    	return DefWindowProc (hwnd, msg, wParam, lParam);
    }
    I replaced APIENTRY with CALLBACK. While this is not necessary, it is good coding as it marks the function as a callback function.
    I also changed the switch statement to a more commonly used form. But the most important thing is that you need to use the hwnd that is passed to the function, as the WM_CREATE message is sent BEFORE CreateWindow returns, and therefore the g_Hwnd is not valid yet! (I found the error only because I thought it bad coding style not to use the hwnd passed to the WndProc, and only now I see the reason why it is so.)

    Your call to CreateWindow also has a syntax error: you have a comma after the last argument.

    And PLEASE, don't use goto in normal programming, especially not like you do in your WinMain. It is better to use multiple return instructions than doing such things. I would also forget the bRet variable in InitApplication and InitInstance, especially since it causes you to call ShowWindow and UpdateWindow even when g_Hwnd is NULL.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  23. #23

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    ok thanks..i am gonna try that...and i'll forget about about the goto which i saw on the msdn..thank you for pointing out bad things...
    thanks
    Amon Ra
    The Power of Learning.

  24. #24

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    thanks a lot ...it worked...
    i wouldn't mind if you could tell me whether there's is a thing i should change in my coding..
    thanks
    Amon Ra
    The Power of Learning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width