views:

82

answers:

2

Hello,

Does anyone know how I can add a progress bar to a listview cell using "pure" api. The only examples I've found are either in c# or outdated mfc

+1  A: 

You would need to overlay the progress bar onto the list view. You will need to handle column resize and scrolling messages to resize it properly.

Alternatively, you can use DrawThemeBackground() to draw a scroll bar onto the listview, without needing an actual control.

PAINTSTRUCT ps;
HDC hDC = BeginPaint(hwnd,&ps);
RECT r;
HTHEME theme = OpenThemeData(hwnd,L"PROGRESS");
SetRect(&r,10,10,100,25);
DrawThemeBackground(theme,hDC,11, 2 ,&r,NULL);
SetRect(&r,10,10,50,25);
DrawThemeBackground(theme,hDC,5, 4 ,&r,NULL);
CloseThemeData(theme);
EndPaint(hwnd,&ps);

This draws a meter. For a green progress bar, change the 2 and 4 to other numbers (1 and 1 I think).

Alexander Rafferty
DrawThemeBackground() sounds better. But I have no idea on how to use it. is there any sample code available that you know of?
bambam
That seems to work. There is just a "small" problem. The progress bar gets behind the listview.
bambam
Here is my WM_CREATE:hProgress = CreateWindowEx(0, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE, bitmapWidth-SpeakerWidth-100, 161, 100, 20, hwnd, NULL, cs->hInstance, NULL);On WM_PAINt i used your code but changed the hwnd to hProgress
bambam
Here is image of it. I am using it on a layered window, but I do not think it is the cause of the problemhttp://a.imagehost.org/0543/progress.jpg
bambam
You need to set the hProgress to an owner drawn one, by adding the owner drawn style (look up on msdn). You then need to handle the custom draw message sent to your app (not WM_PAINT), where you can draw on the progress bar (there is an example code snippet on the msdn about custom drawn controls). This is how I did it, and it worked great.
Alexander Rafferty
Works now. thank you.
bambam
A: 

You could take a look at WTL, there are some nice templates there that may give you some inspiration.

Anders K.
He specifically stated that he wanted a solution using the "pure" api. This would defeat the purpose.
Alexander Rafferty
@Alexander WTL is just a bunch of templates using the API, if he looks into the template sources he can see how it is done.
Anders K.