cant display status bar

This is a discussion on cant display status bar within the Windows Programming forums, part of the Platform Specific Boards category; hi im tryin to create a status bar for my main window , i place the CreateWindow() inside the WM_CREATE: ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    113

    cant display status bar

    hi im tryin to create a status bar for my main window , i place the CreateWindow() inside the WM_CREATE: in the window procedure
    what im doing wrong?

    Code:
    //window proc
    ...
    HWND hStatus;
        switch (message)                  /* handle the messages */
        {
            case WM_CREATE:
                hStatus=CreateWindow("msctls_statusbar32", "Ready",WS_CHILD|WS_VISIBLE,0,0,0,0,hwnd,(HMENU)NULL,GetModuleHandle(NULL), NULL);
    in cant see the staus bar in the main window
    and is the WM_CREATE: of winproc the best place to create the status bar?
    thanks for any help
    Last edited by terracota; 12-02-2004 at 12:20 PM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Have you properly linked the common controls library (comctl32.dll) with InitCommonControlsEx? Is the return value from CreateWindowEx non-NULL? If the return value from CreateWindowEx is NULL, what information does GetLastError give you? Given that the dimensions for the created statusbar are zero, are you resizing it in the parent's WM_SIZE handler or elsewhere?

    Although not responsible for your current problem, I'd suggest using STATUSCLASSNAME as the window class name instead of the explicit "msctls_statusbar32" you are currently using. See also description for status bars.
    Last edited by Ken Fitlike; 12-02-2004 at 12:39 PM. Reason: editing
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    ok i made some changes but still wont work im getting crazy with those darm status bars

    Code:
    #include <windows.h>
    #include <commctrl.h>
    
    #define ID_STATUS 100
    
    const char g_szClassName[] = "myWindowClass";
    
    HWND DoCreateStatusBar(HWND hwndParent, int nStatusID, HINSTANCE
                          hinst, int nParts)
    {
        HWND hwndStatus;
    
    	INITCOMMONCONTROLSEX InitC;
    	InitC.dwSize=sizeof(INITCOMMONCONTROLSEX);
    	InitC.dwICC = ICC_BAR_CLASSES;
    
            
    	InitCommonControlsEx(&InitC);
    		
        // Create the status bar.
        hwndStatus = CreateWindowEx(
            0,                       // no extended styles
            STATUSCLASSNAME,         // name of status bar class
            (LPCTSTR) NULL,          // no text when first created
            SBARS_SIZEGRIP |         // includes a sizing grip
            WS_CHILD,                // creates a child window
            0, 10, 0, 20,              // ignores size and position
            hwndParent,              // handle to parent window
            (HMENU) nStatusID,       // child window identifier
            hinst,                   // handle to application instance
            NULL);                   // no window creation data
    
        return hwndStatus;
    }  
    
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	HWND StatusM;
    	switch(msg)
    	{
    		case WM_CREATE:
    			StatusM = DoCreateStatusBar(hwnd, (int)ID_STATUS, GetModuleHandle(NULL), 2);
    			break;
    		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 wc;
    	HWND hwnd;
    	MSG Msg;
    	
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = 0;
    	wc.lpfnWndProc = WndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hInstance;
    	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = g_szClassName;
    	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    
    	if(!RegisterClassEx(&wc))
    	{
    		MessageBox(NULL,"Fallo al registrar ventana!","Error!",
    			      MB_ICONEXCLAMATION | MB_OK);
    	    return 0;
    	}
    	
    	hwnd = CreateWindowEx(
    		WS_EX_CLIENTEDGE,
    		g_szClassName,
    		"El titulo de mi ventana",
    		WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT, CW_USEDEFAULT, 340, 340,
    		NULL, NULL, hInstance, NULL);
    	
    	if(hwnd == NULL)
    	{
    		MessageBox(NULL, "Fallo al crear ventana!","Error!",
                       MB_ICONEXCLAMATION | MB_OK);
    		return 0;
    	}	
    	
    	ShowWindow(hwnd,nCmdShow);
    	UpdateWindow(hwnd);
    	
    	while(GetMessage(&Msg, NULL, 0,0)>0)
    	{
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);		   	
        }
    	   
        return 0;	 
    }
    heres the error message the compiler generates:
    Deleting intermediate files and output files for project 'prueba - Win32 Debug'.
    --------------------Configuration: prueba - Win32 Debug--------------------
    Compiling...
    winmain.cpp
    Linking...
    LINK : fatal error LNK1104: cannot open file "odbccp32.lib,"
    Error executing link.exe.

    prueba.exe - 1 error(s), 0 warning(s)

    and yes i checked that odbccp32.lib is linked with the project and im using vc++6.0

    any help please?

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    well i already fix it at least and i dont need to initializa that structure
    Code:
    HWND hStatus;
    	InitCommonControlsEx(NULL);
    	
    	switch(msg)
    	{
    		case WM_CREATE:
    			hStatus=CreateWindowEx(WS_EX_CLIENTEDGE,STATUSCLASSNAME,"StatusBar",
    					WS_CHILD | WS_VISIBLE ,0,0,0,0,
    					hwnd,(HMENU)ID_STATUS,GetModuleHandle(NULL),NULL);
    			break;
    i didnt linked the .lib well

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Out of curiosity....if you add this, do you get an error?

    Code:
    if( !InitCommonControlsEx(NULL) )// returns False on failure
    {
           iError = GetLastError();
           //TODO: add messagebox to display error number 
    }
    "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
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    yep
    the compiler generates that error:
    Code:
    Compiling...
    winmain.cpp
    Linking...
    Microsoft (R) Incremental Linker Version 6.00.8168
    Copyright (C) Microsoft Corp 1992-1998. All rights reserved.
    kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib comctl32.lib /subsystem:windows /incremental:yes "/pdb:Debug/control_status_bar.pdb" /debug /machine:I386 "/
    out:Debug/control_status_bar.exe" /pdbtype:sept 
    ".\Debug\winmain.obj" 
    LINK : fatal error LNK1168: cannot open Debug/control_status_bar.exe for writing
    Error executing link.exe.
    
    control_status_bar.exe - 1 error(s), 0 warning(s)
    what this means?

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    This means that the compiler can not open "control_status_bar.exe" to write the new program. Typically this is because the program is still running. Open up task manager and kill it.

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    113

    Unhappy

    thanks anonytmouse, i feel dumb :-)
    novacain

    im not sure if im retrieving the error:

    Code:
    DWORD dw = GetLastError();
    	switch(msg)
    	{
    		case WM_CREATE:
    			if(!InitCommonControlsEx(NULL)){
    				FormatMessage(
    					FORMAT_MESSAGE_ALLOCATE_BUFFER | 
    					FORMAT_MESSAGE_FROM_SYSTEM,
    					NULL,dw,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    					(LPTSTR) &cadena,
    					0, NULL );
    
    				wsprintf(temp,"%s",cadena);
    				MessageBox(hwnd,temp,"Error",MB_OK);
    
    			}
    			else{
    			hStatus=CreateWindowEx(WS_EX_CLIENTEDGE,STATUSCLASSNAME,"StatusBar",
    					WS_CHILD | WS_VISIBLE ,0,0,0,0,
    					hwnd,(HMENU)ID_STATUS,GetModuleHandle(NULL),NULL);
    			}
    			break;
    the error displayed is EHO, lol who knos whats that?
    and if i dont check the InitCommonControlsEx(NULL) return value the status bar is created with no problems, know im more lost
    Last edited by terracota; 12-03-2004 at 09:38 AM.

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Remove the else so the status bar is created even if the InitCommonControls() fails.

    You have the call to GetLastError() in the wrong place. Use GetLastError() in the FormatMessage() in place of your DWORD dw or call GetLastError() after InitCommonControls() and before FormatMessage()

    GetLastError() must be called directly after an error has occured. The system will post ERROR_SUCCESS and overwrite the error.
    "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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. status bar flickering
    By rakan in forum Windows Programming
    Replies: 5
    Last Post: 01-07-2008, 10:11 PM
  2. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 01:32 PM
  3. Status bar
    By maxorator in forum Windows Programming
    Replies: 3
    Last Post: 11-06-2005, 11:45 AM
  4. Troubles with Sockets
    By cornholio in forum Windows Programming
    Replies: 6
    Last Post: 10-26-2005, 06:31 AM
  5. Disabling "Ready" & Other Auto Status Bar Updates :: MFC
    By kuphryn in forum C++ Programming
    Replies: 1
    Last Post: 04-03-2002, 08:51 PM

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