Pure WinApi(win32) een gekleurde progressbar maken.

Status
Niet open voor verdere reacties.

NLScotty

Gebruiker
Lid geworden
17 aug 2009
Berichten
200
Hallo,

Ik heb een probleem, ik heb een progressbar in mijn GUI zitten, maar als ik hem run en met SendMessage() vul, dan krijg ik de standaard XP progresbar ( groene balkjes), ik zou graag gewoon een rode/blauwe en gele kleur willen hebben + dat het een balk wordt, geen losse balkjes.

De code die ik nu gebruik voor de proressbar is:

Code:
hwndExp = CreateWindowEx(0, PROGRESS_CLASS,NULL, WS_CHILD | WS_VISIBLE,70, 56, 180, 17, hWnd, (HMENU) 0, hInstance, NULL);

Hopelijk weet iemand het, ik heb heel google afgezocht.

Grz NLScotty
 
Dit is alleen mogelijk als de gebruiker de Windows Classic theme gebruikt. In dit geval maak je gebruik van de PBS_SMOOTH style bij het creëren van je progressbar en gebruik je de PBM_SETBARCOLOR message om de indicator balk een kleur te geven.

PBS_SMOOTH
The progress bar displays progress status in a smooth scrolling bar instead of the default segmented bar. This style is supported only in the Windows Classic theme. All other themes override this style.

PBM_SETBARCOLOR
Sets the color of the progress indicator bar in the progress bar control. When visual styles are enabled, this message has no effect.

Edit: Volgens mij wordt er door Microsoft bedoelt dat je applicatie geen gebruik moet maken van de Windows XP themes. Dit weet ik echter niet zeker omdat ik dit niet getest heb.
 
Laatst bewerkt:
Bedankt, maar deze opties hebben niet gewerkt, waarschijnlijk gaat er iets fout met themes etc.

Er moet toch een andere manier zijn om dit voor elkaar te krijgen?
 
Zal je me even op weg willen helpen met een progressbar, ik volg het niet helemaal.
 
Hoe wil je dat ik je precies help? Het intikken van de benodigde zoekopdrachten op MSDN is tot nu toe aardig gelukt.
 
Zover heb ik dit, het geeft een grijze box, maar hoe kan ik er een progressbar met kleuren/ text van maken?

Code:
TCHAR custom[] = _T("CustCtrl345");

LRESULT CALLBACK CustWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)

{

    switch(msg)

    {

    default:

        break;

    }


return DefWindowProc(hwnd, msg, wParam, lParam);
}

void InitCustomControl()
{
WNDCLASSEX wc;

wc.cbSize = sizeof(wc);
wc.lpszClassName = custom;
wc.hInstance = hInstance;
wc.lpfnWndProc = CustWndProc;
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hIcon = 0;
wc.lpszMenuName = 0;
wc.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_BTNFACE);
wc.style = 0;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIconSm = 0;


RegisterClassEx(&wc);
}
HWND hwndCtrl;


LRESULT CALLBACK WndProc1(HWND hWnd, UINT  msg, WPARAM wParam, LPARAM lParam)
{
	switch ( msg)
	{
	case WM_CREATE:
		InitCustomControl();
		hwndCtrl = CreateWindowEx(

                 WS_EX_CLIENTEDGE, // give it a standard border

                 custom,

                _T("hehe"),

                 WS_VISIBLE | WS_CHILD,

                 70, 10, 180, 17,

                 hWnd,

                 NULL, hInstance, NULL

               );
 
Misschien heb je wat aan onderstaande code.
Code:
struct ProgressieBalk
{
 int pos;
 COLORREF kleur;
};

LRESULT CALLBACK CustWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 LRESULT lres = 0;
 struct ProgressieBalk *pb;

 switch(msg)
 {
    case WM_NCCREATE:
    pb = (struct ProgressieBalk*) GlobalAlloc( GPTR, sizeof *pb);
    if( pb )
    {
        pb->kleur = CLR_DEFAULT;
        SetWindowLong(hwnd, 0, (LONG)pb);
        lres = 1;
    }
    break;

    case WM_NCDESTROY:
    GlobalFree(  (HGLOBAL)GetWindowLong(hwnd,0) );
    break;

    case WM_PAINT:
    {
       HDC         hdc;
       PAINTSTRUCT ps;
       RECT        rc;
       HBRUSH      brush;

       pb = (struct ProgressieBalk*) GetWindowLong(hwnd,0);
       GetClientRect(hwnd,&rc);
       rc.right = rc.right * pb->pos /100;

       if( pb->kleur == CLR_DEFAULT )
            brush = CreateSolidBrush(   GetSysColor( COLOR_HIGHLIGHT )   );
       else brush = CreateSolidBrush( pb->kleur );

       hdc = BeginPaint(hwnd, &ps);
       FillRect(hdc, &rc, brush);
       EndPaint(hwnd, &ps);

       DeleteObject(brush);
    }
    break;

    case PBM_SETPOS:
    pb      = (struct ProgressieBalk *) GetWindowLong(hwnd,0);
    lres    = pb->pos;
    pb->pos = wParam;
    InvalidateRect(hwnd, NULL, TRUE);
    UpdateWindow(hwnd);
    break;

    case PBM_SETBARCOLOR:
    pb        = (struct ProgressieBalk *) GetWindowLong(hwnd,0);
    lres      = pb->kleur;
    pb->kleur = lParam;
    InvalidateRect(hwnd, NULL, FALSE);
    UpdateWindow(hwnd);
    break;

    default:
    lres = DefWindowProc(hwnd, msg, wParam, lParam);
    break;
 }
 return lres;
}
En in void InitCustomControl()
wc.cbWndExtra = 0;
vervangen door
wc.cbWndExtra = sizeof(void*);

Zoals te zien is zijn niet alle progressbar messages en styles geimplementeerd.
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan