Windows API... Status Bar problems.

This is a discussion on Windows API... Status Bar problems. within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I'm trying to put a status bar in my win32 app, using the following code: (in case of WM_CREATE ...

  1. #1
    Registered User
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    18

    Windows API... Status Bar problems.

    Hi. I'm trying to put a status bar in my win32 app, using the following code:
    (in case of WM_CREATE Message)

    Code:
    HWND hStatus;
    int statwidths[] = {100, -1};
    
    hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
    	WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,
    	hwnd, (HMENU)ID_STATUS, GetModuleHandle(NULL), NULL);
    
    SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
    SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Test");
    
    if(hStatus == NULL)
        MessageBox(hwnd, "Could not create StatusBar.", "Error", MB_OK | MB_ICONERROR);
    I added the MessageBox bit in after I compiled and ran the app and saw no StatusBar. It seems hStatus is null and that no Status Bar has been created. Could somebody please advice me as to why this is? Thankyou for any replies.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Assuming that hStatus is a local variable, I would make it a static local variable.

    Code:
    static HWND hStatus;

  3. #3
    Registered User
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    18
    Quote Originally Posted by BobS0327 View Post
    Assuming that hStatus is a local variable, I would make it a static local variable.

    Code:
    static HWND hStatus;
    How would this help at all?

    Thanks for the reply.
    SwitchCase

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    The code you posted is correct except I would have checked hStatus right after I created the window. I incorrectly made the assumption that hStatus was somehow losing it's value, which is not the case after rereading your code. Since the code is correct, the only other issue that comes to mind is that you're possibly not calling InitCommonControls.

    I apologize for the initial misinformation.

  5. #5
    Registered User
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    18
    Quote Originally Posted by BobS0327 View Post
    The code you posted is correct except I would have checked hStatus right after I created the window. I incorrectly made the assumption that hStatus was somehow losing it's value, which is not the case after rereading your code. Since the code is correct, the only other issue that comes to mind is that you're possibly not calling InitCommonControls.

    I apologize for the initial misinformation.
    No need to apologise.

    I've tryed using InitCommonControls() just before reading your recent reply, after reading through MSDN. Unfortunatly Im have problems getting this to work, as whenever I call InitCommonControls() I get a linking error. The error given by the compliler is:
    Linking executable: F:\Dev\New\Win32GUI.exe
    .objs\main.o:main.cpp.text+0x600): undefined reference to `InitCommonControls@0'
    collect2: ld returned 1 exit status
    Process terminated with status 1 (0 minutes, 4 seconds)
    Does this indicate any other errors i have made?

    I have included commctrl.h, I really don't know what the problem is. Sorry if its obvious.

    Thankyou.
    SwitchCase

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Are you linking with comctl32.lib?

  7. #7
    Registered User
    Join Date
    May 2007
    Location
    Manchester, UK
    Posts
    18
    Quote Originally Posted by BobS0327 View Post
    Are you linking with comctl32.lib?
    ...Ooops.... no.

    Sorry for wasting your time. I'm an idiot.
    The help is much appreciated despite, thankyou.
    SwitchCase

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What does this do (Windows API)?
    By EVOEx in forum Windows Programming
    Replies: 4
    Last Post: 12-19-2008, 10:48 AM
  2. Want to learn Windows API for Game Programming
    By George M. in forum Windows Programming
    Replies: 15
    Last Post: 09-28-2008, 11:26 AM
  3. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  4. MFC or Windows API
    By aresashura in forum Windows Programming
    Replies: 7
    Last Post: 12-01-2001, 10:21 PM
  5. Status bar covering parent window....by the way, thanks Ward
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 10-02-2001, 09:16 PM

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