Reputation: 55
In my program I created a status bar control and then set a new font for it. The problem I'm having is that when I include the XP Visual Styles manifest (i.e. Common controls 6.0), then the status bar is not resizing to match the new font size.
e.g.
hGiantFont = CreateFont(-48, 0, 0, 0, FW_NORMAL, FALSE, FALSE,
FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH |
FF_DONTCARE, L"MS Shell Dlg 2");
hStatusBar = CreateWindowEx (
0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hWnd, (HMENU)666, hInst, NULL
);
SendMessage(hStatusBar, WM_SETFONT, (WPARAM)hGiantFont,
(LPARAM)MAKELONG(TRUE, 0));
SendMessage(hStatusBar, WM_SIZE, 0, 0);
After executing the last line, nothing happens! It doesn't resize. Note that if I don't include the visual styles Manifest, it works fine! I've tried both InitCommonControls() and InitCommonControlsEX() with ICC_BAR_CLASSES to no avail.
I've also tried using MoveWindow and SetWindowPos to change the size or move the status bar. With the visual styles manifest included, the status bar does not move, it seems glued to that specific size and location.
Is this a bug in ComCtl32.dll 6.0? Or an extremely annoying intended feature. What is the work around?
Also has anoyone else tried doing the same thing with successful results?
Edit:
Ok I've decided to include the whole program below, so people can try it out and see what I mean. It's just a bare basics Win32 app with a few lines added. If you comment out the #pragma manifest line at the top you'll notice it works as expected, and with the manifest line, the status bar doesn't resize.
// StupidStatusBar.cpp : Defines the entry point for the application.
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h>
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")
// Global Variables:
HINSTANCE hInst;
wchar_t *szTitle = L"Stupid Status Bar";
wchar_t *szWindowClass = L"StupidClass";
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_WIN95_CLASSES;
if(!InitCommonControlsEx(&icex))
{
MessageBox(NULL, L"Error initializing common controls", L"Error", MB_OK);
return 1;
}
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
return FALSE;
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hStatusBar;
HFONT hGiantFont;
switch (message)
{
case WM_CREATE:
hGiantFont = CreateFont(-48, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"MS Shell Dlg 2");
hStatusBar = CreateWindowEx (
0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hWnd, (HMENU)666, hInst, NULL
);
SendMessage(hStatusBar, WM_SETFONT, (WPARAM)hGiantFont, (LPARAM)MAKELONG(TRUE, 0));
SendMessage(hStatusBar, WM_SIZE, 0, 0);
SetWindowText(hStatusBar, L"Testing Testing");
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Upvotes: 3
Views: 1754
Reputation: 1
I had a similar problem, and I think there is no crap in the Win32 API library, it Works but a certain procedure has to be followed that is not shown so clearly in the Win32 API documentation (as of now, it is sketched at https://code.msdn.microsoft.com/CppWindowsCommonControls-9ea0de64, section L); it is as follows:
1) globally, define the variable hWndStatusbar:
HWND hWndStatusbar;
2) in the WM_CREATE of the main window procedure add the following code at the end (if "case WM_CREATE" is not already treated in the WndProc window procedure, just add it):
RECT rcStatusRect;
int iStatusBarWidths[1];
GetClientRect(hWnd, &rcStatusRect);
iStatusBarWidths[0] = rcStatusRect.right;
hWndStatusbar = CreateWindowEx(0, STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0, hWnd, NULL, hInst, NULL);
SendMessage(hWndStatusbar, SB_SETPARTS, (WPARAM)1, (LPARAM)iStatusBarWidths);
SendMessage((HWND)hWndStatusbar, (UINT)SB_SETTEXT, (WPARAM)(INT)0 | 0, (LPARAM)(LPSTR)TEXT("Hello"));
3) if "case WM_SIZE" is not already treated in your WndProc window procedure, just add it, and add the following code at the end:
int iStatusBarWidths[1];
iStatusBarWidths[0] = -1;
SendMessage(hWndStatusbar, SB_SETPARTS, (WPARAM)1, (LPARAM)iStatusBarWidths);
SendMessage(hWndStatusbar, WM_SIZE, 0, 0);
That is like everything, for me it Works like this, under Visual Studio Community 2015..
Upvotes: 0
Reputation: 55
Solved it. Had to override the default proc for the status bar and make its WM_SIZE case return 0. Then manually resize using MoveWindow from my main window.
Upvotes: 2