进度条WinApi [英] PBS_MARQUEE Progressbar WinApi
问题描述
我正在尝试获取类型PBS_MARQUEE工作的进度栏。
我可以创建进度条,但我只是不能管理它使它移动。
如果发现这个,但我不明白我需要做的:
因为我有进度条作为资源,而不是使用CreateWindowEx(..)我不得不使用SetWindowLongPtr(.. )为此控件设置PBS_MARQUEE风格...
我以这种方式创建进度条:
hwndPB = CreateWindowEx(0,PROGRESS_CLASS,
(LPSTR)NULL,WS_CHILD | WS_VISIBLE | PBS_MARQUEE,
rcClient.left,
rcClient.bottom -
rcClient.right,cyVScroll,
hwnd,(HMENU)0,NULL,NULL);
然后我尝试使它工作:
SetWindowLongPtr(hwndPB,GWL_STYLE,PBS_MARQUEE);
SendMessage(hwndPB,(UINT)PBM_SETMARQUEE,(WPARAM)1,(LPARAM)NULL);
Thx&
问题是,你要消除窗口风格。错误是行:
SetWindowLongPtr(hwndPB,GWL_STYLE,PBS_MARQUEE);
这会设置 PBS_MARQUEE
样式标志,
而是应该使用按位OR,如下所示:
LONG_PTR style = GetWindowLongPtr(wndPB,GWL_STYLE);
SetWindowLongPtr(hwndPB,GWL_STYLE,style | PBS_MARQUEE);
我不知道C ++类型规则,所以这里代码可能会有皱纹,但是我确定这是你的问题!
事实上,由于你在调用 CreateWindowEx() code>我不明白为什么你需要修改它。
你的选框进度条不工作。您是否包含常用控件v6的清单?
你可以通过在stdafx.h中加入以下内容来做到这一点:
#pragma comment(linker,/ manifestdependency:\type ='win32'name ='Microsoft.Windows.Common- version ='6.0.0.0'processorArchitecture ='*'publicKeyToken ='6595b64144ccf1df'language ='*'\)
b $ b
我在Visual Studio中将以下代码添加到空白的Win32项目中:
HWND hwndPB = CreateWindowEx(
0,PROGRESS_CLASS,(LPCWSTR)NULL,
WS_CHILD | WS_VISIBLE | PBS_MARQUEE,
0,0,400,100,
hWnd,(HMENU)0,hInst, NULL
);
SendMessage(hwndPB,(UINT)PBM_SETMARQUEE,(WPARAM)1,(LPARAM)NULL);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
我需要添加清单pragma来获取v6 comctl32,没有pragma没有字幕。 / p>
I'm trying to get a progress bar of the type PBS_MARQUEE working. I can create the progress bar, but i just can't manage it to make it moving.
If found this, but i don't understand clearly what i have to do:
"Turns out since i had the progress bar as a resource instead of using the CreateWindowEx(..) i had to use SetWindowLongPtr(..) to set the PBS_MARQUEE style for this control..."
I create the progressbar that way:
hwndPB = CreateWindowEx(0, PROGRESS_CLASS,
(LPSTR)NULL, WS_CHILD | WS_VISIBLE | PBS_MARQUEE ,
rcClient.left,
rcClient.bottom - cyVScroll,
rcClient.right, cyVScroll,
hwnd, (HMENU) 0, NULL, NULL);
Then i try to make it working:
SetWindowLongPtr(hwndPB,GWL_STYLE,PBS_MARQUEE);
SendMessage(hwndPB,(UINT) PBM_SETMARQUEE,(WPARAM) 1,(LPARAM)NULL );
Thx & regards
The problem is that you are obliterating the window style. The error is the line:
SetWindowLongPtr(hwndPB,GWL_STYLE,PBS_MARQUEE);
This sets the PBS_MARQUEE
style flag, but removes all other flags, most definitely not what you intend.
Instead you should use bitwise OR like so:
LONG_PTR style = GetWindowLongPtr(wndPB, GWL_STYLE);
SetWindowLongPtr(hwndPB, GWL_STYLE, style | PBS_MARQUEE);
I'm know next to nothing about C++ type rules so there will probably be wrinkles with this code, but I'm sure that this is your problem!
In fact, since you set the window style in the call to CreateWindowEx()
I don't see why you need to modify it at all.
One final hunch at why your marquee progress bar is not working. Did you include a manifest for common controls v6? The marquee style is only supported in common controls v6 and up.
You can do this most simply by including the following in, for example, stdafx.h:
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
I tested this with the following code added to the blank Win32 project in Visual Studio:
HWND hwndPB = CreateWindowEx(
0, PROGRESS_CLASS, (LPCWSTR)NULL,
WS_CHILD | WS_VISIBLE | PBS_MARQUEE,
0, 0, 400, 100,
hWnd, (HMENU) 0, hInst, NULL
);
SendMessage(hwndPB,(UINT) PBM_SETMARQUEE,(WPARAM) 1,(LPARAM)NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
I needed to add the manifest pragma to get v6 comctl32 and without the pragma there was no marquee.
这篇关于进度条WinApi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!