-
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
-
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.
-
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?
-
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
-
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
}
-
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?
-
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.
-
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
-
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.