Status Window

This is a discussion on Status Window within the Windows Programming forums, part of the Platform Specific Boards category; I have been trying to create a status bar on the bottom of my window. I can not make it ...

  1. #1
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69

    Status Window

    I have been trying to create a status bar on the bottom of my window. I can not make it work. I have tried CreateStatusWindow which does not work as well as being deprecated.
    Code:
    status = CreateWindowEx(
                         0,
                         STATUSCLASSNAME,
                         (LPCTSTR) "No user selected.",
                         SBARS_SIZEGRIP | WS_CHILD,
                         0, 0, 0, 0,
                         hwndDlg,
                         (HMENU) NULL,
                         hInst,
                         NULL);
            INT statsize=(-1);
           SendMessage((HWND)status, (UINT)SB_SETPARTS, (WPARAM)1, (LPARAM)(PINT)&statsize);
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Don't forget you also have to adjust your WM_SIZE handler so nothing is overlapping the status bar...

    Also check the returned handle... is it NULL? If it is your CreateWindowEx() call is failing.

  3. #3
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    What is argument 10 of CreateWindowEx for? What is the proper value?
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Benji Wiebe View Post
    What is argument 10 of CreateWindowEx for? What is the proper value?
    Well... here is one way to find out.

    It might also help if you used WS_VISIBLE in your styles.
    Last edited by CommonTater; 09-26-2011 at 07:05 PM.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    If you use the WS_CHILD then teh HMENU param is the ID number of the child (otehrwise it is the handle to the menu).

    So what number you put jhere is dependent on your ID numbers.

    This has to be unique on any given window/dialog.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by novacain View Post
    If you use the WS_CHILD then teh HMENU param is the ID number of the child (otehrwise it is the handle to the menu).

    So what number you put jhere is dependent on your ID numbers.

    This has to be unique on any given window/dialog.
    In a Status bar control you probably want that to be NULL ...

    Lets say you put in (HMENU) 1000 ... just as an example. When you click on the status bar a WM_COMMAND message is sent with 1000 in the low word of wParam ... Just like a button.. For a display only control, this is undesirable, hense, set it to NULL.

    The OP's problem is most likely that he did not include WS_VISIBLE in his Window Styles...

  7. #7
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    Quote Originally Posted by CommonTater View Post
    The OP's problem is most likely that he did not include WS_VISIBLE in his Window Styles...
    I added that and changed arg 10 of CreateWindowEx to NULL. It still does not work. The HWND returned by CreateWindowEx != NULL.
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  8. #8
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    Also you have to start the common controls to work with them; if you haven't done it yet see the reference for 'InitCommonControls()' and 'InitCommonControlsEx()' functions.

    Hope that helps

  9. #9
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    Quote Originally Posted by Niara View Post
    Also you have to start the common controls to work with them; if you haven't done it yet see the reference for 'InitCommonControls()' and 'InitCommonControlsEx()' functions.

    Hope that helps
    I do have the code
    Code:
    LPINITCOMMONCONTROLSEX cmmnctrls=malloc(sizeof(cmmnctrls));
        cmmnctrls->dwSize=sizeof(cmmnctrls);
        cmmnctrls->dwICC=ICC_STANDARD_CLASSES | ICC_BAR_CLASSES;
        InitCommonControlsEx(cmmnctrls);
    at the start of the WinMain function.
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  10. #10
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Quote Originally Posted by Benji Wiebe View Post
    I do have the code
    Code:
    LPINITCOMMONCONTROLSEX cmmnctrls=malloc(sizeof(cmmnctrls));
        cmmnctrls->dwSize=sizeof(cmmnctrls);
        cmmnctrls->dwICC=ICC_STANDARD_CLASSES | ICC_BAR_CLASSES;
        InitCommonControlsEx(cmmnctrls);
    at the start of the WinMain function.
    That doesn't work

  11. #11
    A source of questions... Benji Wiebe's Avatar
    Join Date
    Mar 2011
    Location
    Durham, Kansas
    Posts
    69
    Quote Originally Posted by adeyblue View Post
    That doesn't work
    Why not?!
    Ever notice how fast Windows runs?
    Neither did I.
    Which is why I switched to Linux.

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    What does GetLastError() return?


    Quote Originally Posted by CommonTater View Post
    In a Status bar control you probably want that to be NULL ...

    Lets say you put in (HMENU) 1000 ... just as an example. When you click on the status bar a WM_COMMAND message is sent with 1000 in the low word of wParam ... Just like a button.. For a display only control, this is undesirable, hense, set it to NULL.

    The OP's problem is most likely that he did not include WS_VISIBLE in his Window Styles...
    IMO this is bad advice. MSDN is clear that the ID of child controls should be unique on a window/dialog. This is because the child controls use this ID to communicate with the parent. I think you should not advise new coders to ignore MSDN instructions, especially without advising them EXACTLY when and why.

    Your advice makes it sound like setting the control's ID to NULL will stop all msgs being generated by the control, which IME is not true.
    The control will still generate msgs, but the parent will not be able to process them.
    If another control on the window also has NULL or zero as the ID it may stop the control from being created.

    Also a statusbar, especially with a size grip, is not just 'display only' control.
    The app will want to set text, change the part sizes in response to size changes etc.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by novacain View Post
    What does GetLastError() return?

    IMO this is bad advice. MSDN is clear that the ID of child controls should be unique on a window/dialog. This is because the child controls use this ID to communicate with the parent. I think you should not advise new coders to ignore MSDN instructions, especially without advising them EXACTLY when and why.

    Your advice makes it sound like setting the control's ID to NULL will stop all msgs being generated by the control, which IME is not true.
    The control will still generate msgs, but the parent will not be able to process them.
    If another control on the window also has NULL or zero as the ID it may stop the control from being created.

    Also a statusbar, especially with a size grip, is not just 'display only' control.
    The app will want to set text, change the part sizes in response to size changes etc.
    I did not tell anyone that that setting a null in the menuid would stop all messages... and, more importantly I can't for the life or me figure out where you got the idea I did...

    It stops ONE message... the WM_COMMAND message when you click on it... And for a display only control you don't really want it to be clickable, anyway.

    As a display control... you are going to be sending messages TO it, and will receive very few (if any) from it.

    You would do us both a favor if you would stop trying to manufacture controversy where there is none.

  14. #14
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Benji Wiebe View Post
    I do have the code
    Code:
    LPINITCOMMONCONTROLSEX cmmnctrls=malloc(sizeof(cmmnctrls));
        cmmnctrls->dwSize=sizeof(cmmnctrls);
        cmmnctrls->dwICC=ICC_STANDARD_CLASSES | ICC_BAR_CLASSES;
        InitCommonControlsEx(cmmnctrls);
    at the start of the WinMain function.
    Just use InitCommonControls(); and be done with it.

  15. #15
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    287
    I always use InitCommonControls(), but take a look at the msdn specification for that function:

    Code:
    Under Comctl32.dll version 5.x, only Windows 95 classes (ICC_WIN95_CLASSES) can be registered through InitCommonControls. Programs which 
    require additional common control classes must use the InitCommonControlsEx function.
    
    Under Comctl32.dll version 6.0 and later, InitCommonControls does nothing. Applications must explicitly register all common controls 
    through InitCommonControlsEx.
    Another thing, on the WM_SIZE handler: are you setting the size of the control correctly?

    That's what I think: combine all the advices here (WS_VISIBLE, WM_SIZE handling, InitCommonControls(), etc..) and if it doesn't work you should have something wrong in another part.

    Also wait a moment: what does it mean "I can not make it work."? The control doesn't appear on the hwndDlg window? The control appears but you can't show any text on it?
    Last edited by Niara; 09-28-2011 at 12:44 PM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Status bar
    By Nephiroth in forum Windows Programming
    Replies: 1
    Last Post: 01-29-2006, 07:20 AM
  2. Status bar
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-19-2005, 05:24 AM
  3. Window Status
    By Onkel BeBu in forum Windows Programming
    Replies: 3
    Last Post: 08-01-2003, 04:13 AM
  4. status bar
    By toby1909 in forum Windows Programming
    Replies: 3
    Last Post: 01-20-2002, 11:19 AM
  5. Status bar covering parent window....by the way, thanks Ward
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 10-02-2001, 08:16 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21