状态栏控件无法与XP Visual Styles清单一起正常使用 [英] Status bar control not working properly with XP Visual Styles manifest

查看:50
本文介绍了状态栏控件无法与XP Visual Styles清单一起正常使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,我创建了一个状态栏控件,然后为其设置了新字体.
我遇到的问题是当我包含XP Visual Styles时
清单(即通用控件6.0),则状态栏不会调整大小以匹配新的字体大小.

例如

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);



执行完最后一行之后,什么也没有发生!它不会调整大小.
请注意,如果我不包括清单样式,那么效果很好!
我尝试了带有ICC_BAR_CLASSES的InitCommonControls()和InitCommonControlsEX()都无济于事.

我还尝试使用MoveWindow和SetWindowPos更改大小或移动状态栏.包含视觉样式清单后,状态栏不会移动,似乎固定在该特定大小和位置上.

这是ComCtl32.dll 6.0中的错误吗?或非常烦人的预期功能.解决方法是什么?



好的,我决定将整个程序包括在下面,以便人们可以尝试一下并明白我的意思.它只是一个基本的Win32应用程序,添加了几行内容.如果在顶部注释掉#pragma清单行,您会注意到它按预期工作,并且清单行的状态栏不会调整大小.



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?



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;								// current instance
wchar_t *szTitle = L"Stupid Status Bar";			// The title bar text
wchar_t *szWindowClass = L"StupidClass";			// the main window class name

// 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; 

   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;
}

推荐答案

已解决.必须覆盖状态栏的默认proc,并使其WM_SIZE大小写返回0.然后从我的主窗口使用MoveWindow手动调整大小.
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.


这篇关于状态栏控件无法与XP Visual Styles清单一起正常使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆