PBS_MARQUEE Progressbar WinApi

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

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

回答1:

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.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!