DaAvange
August 15th, 2007, 10:44 AM
Hello,
I don't know if the title is right, be here is what I did so far and what I'm tring to do.
I subclassing the common control progress bar class so I can change its appearance and it worked really well,
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT lpPaintStruct;
switch(uMsg) {
case WM_PAINT: {
BeginPaint(hwnd, &lpPaintStruct);
DrawProgressBar(hwnd);
EndPaint(hwnd, &lpPaintStruct);
return TRUE;
}
default:
return CallWindowProc(OldWndProc, hwnd, uMsg, wParam, lParam);
}
return 0;
}
void DrawProgressBar(HWND hWnd) {
RECT WndRect;
GetWindowRect(hWnd, &WndRect);
int PhysWidth = WndRect.right - WndRect.left;
int PhysHeight = WndRect.bottom - WndRect.top;
UINT NewPerc = SendMessage(hWnd, PBM_GETPOS, 0, 0);
UINT MaxPerc = SendMessage(hWnd, PBM_GETRANGE, FALSE, NULL);
register UINT c;
HBITMAP hBackBmp;
HDC frontHDC;
HDC backHDC;
HDC TargetHDC;
DWORD dwLimit;
if (NewPerc > MaxPerc) NewPerc = MaxPerc;
if (MaxPerc != 100) {
if (NewPerc > 0) NewPerc = (int)(((float) NewPerc / (float) MaxPerc) * 100);
else NewPerc = 0;
}
TargetHDC = GetDC(hWnd);
hBackBmp = CreateCompatibleBitmap(TargetHDC, SliceWidth * 101, SliceHeight);
backHDC = CreateCompatibleDC(TargetHDC);
SelectObject(backHDC, hBackBmp);
frontHDC = CreateCompatibleDC(TargetHDC);
dwLimit = GdiSetBatchLimit((DWORD) 100);
for (c = 0; c <= 100; c++) {
if (c == 0) SelectObject(frontHDC, ((NewPerc > 0) ? hTubeColorLeft : hTubeEmptyLeft));
else if (c == 100) {
SelectObject(frontHDC, ((NewPerc == 100) ? hTubeColorRight : hTubeEmptyRight));
}
else {
if (c < NewPerc) SelectObject(frontHDC, hTubeColorFilled);
else if (c == NewPerc) SelectObject(frontHDC, hTubeColorFiller);
else SelectObject(frontHDC, hTubeEmptyMiddle);
}
BitBlt(backHDC, c *SliceWidth , 0, SliceWidth, SliceHeight, frontHDC, 0, 0, SRCCOPY);
}
StretchBlt(TargetHDC, 1, 1, PhysWidth, PhysHeight, backHDC, 0, 0, SliceWidth * 101, SliceHeight, SRCCOPY);
GdiFlush();
GdiSetBatchLimit(dwLimit);
ReleaseDC(hWnd, TargetHDC);
DeleteDC(frontHDC);
DeleteDC(backHDC);
}
It draws it, but there is a annoying rectangle frame of that control that allways stays there (and its not WS_BORDER) , here is the picture:
http://img186.imageshack.us/img186/9819/untitledrz8.jpg
I don't know if the title is right, be here is what I did so far and what I'm tring to do.
I subclassing the common control progress bar class so I can change its appearance and it worked really well,
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT lpPaintStruct;
switch(uMsg) {
case WM_PAINT: {
BeginPaint(hwnd, &lpPaintStruct);
DrawProgressBar(hwnd);
EndPaint(hwnd, &lpPaintStruct);
return TRUE;
}
default:
return CallWindowProc(OldWndProc, hwnd, uMsg, wParam, lParam);
}
return 0;
}
void DrawProgressBar(HWND hWnd) {
RECT WndRect;
GetWindowRect(hWnd, &WndRect);
int PhysWidth = WndRect.right - WndRect.left;
int PhysHeight = WndRect.bottom - WndRect.top;
UINT NewPerc = SendMessage(hWnd, PBM_GETPOS, 0, 0);
UINT MaxPerc = SendMessage(hWnd, PBM_GETRANGE, FALSE, NULL);
register UINT c;
HBITMAP hBackBmp;
HDC frontHDC;
HDC backHDC;
HDC TargetHDC;
DWORD dwLimit;
if (NewPerc > MaxPerc) NewPerc = MaxPerc;
if (MaxPerc != 100) {
if (NewPerc > 0) NewPerc = (int)(((float) NewPerc / (float) MaxPerc) * 100);
else NewPerc = 0;
}
TargetHDC = GetDC(hWnd);
hBackBmp = CreateCompatibleBitmap(TargetHDC, SliceWidth * 101, SliceHeight);
backHDC = CreateCompatibleDC(TargetHDC);
SelectObject(backHDC, hBackBmp);
frontHDC = CreateCompatibleDC(TargetHDC);
dwLimit = GdiSetBatchLimit((DWORD) 100);
for (c = 0; c <= 100; c++) {
if (c == 0) SelectObject(frontHDC, ((NewPerc > 0) ? hTubeColorLeft : hTubeEmptyLeft));
else if (c == 100) {
SelectObject(frontHDC, ((NewPerc == 100) ? hTubeColorRight : hTubeEmptyRight));
}
else {
if (c < NewPerc) SelectObject(frontHDC, hTubeColorFilled);
else if (c == NewPerc) SelectObject(frontHDC, hTubeColorFiller);
else SelectObject(frontHDC, hTubeEmptyMiddle);
}
BitBlt(backHDC, c *SliceWidth , 0, SliceWidth, SliceHeight, frontHDC, 0, 0, SRCCOPY);
}
StretchBlt(TargetHDC, 1, 1, PhysWidth, PhysHeight, backHDC, 0, 0, SliceWidth * 101, SliceHeight, SRCCOPY);
GdiFlush();
GdiSetBatchLimit(dwLimit);
ReleaseDC(hWnd, TargetHDC);
DeleteDC(frontHDC);
DeleteDC(backHDC);
}
It draws it, but there is a annoying rectangle frame of that control that allways stays there (and its not WS_BORDER) , here is the picture:
http://img186.imageshack.us/img186/9819/untitledrz8.jpg