Is Zwar n Bissle Spät aber vieleicht hilft dir das funcs momentan Mitn Timer musts noch anpassen
[code]
#include <windows.h>
#include <StdIO.h>
#include <commctrl.h>
#include "resource.h"
#pragma comment(lib,"Comctl32.lib")
#define INCTIMERID1 1
static int PrevWndProcProzess;
int progress=0;
char status[10];
LRESULT CALLBACK ProgressWndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hwnd,
hText,
hwndProgress,
g_hText;
void Init (HWND hwnd)
{
SendMessage(hwndProgress, PBM_SETPOS,(WPARAM)progress,0);
}
void CALLBACK IncTimer1 (HWND hwnd, UINT iMsg, UINT iTimer, DWORD dwTime)
{
progress++;
if(progress < 100)
{
Init(hwnd);
}
if(progress >=100)
{
progress=0;
Init(hwnd);
//KillTimer(hwnd, INCTIMERID1);
//PostQuitMessage(0); //Programm nach ablauf beenden
}
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE prevInstance,
PSTR szCmdLine,
int iCmdShow)
{
InitCommonControls();
static TCHAR szAppName[] = TEXT("Progress Bar");
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = 0;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) CreateSolidBrush (RGB ( 0, 0, 0));
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
RegisterClass(&wndclass);
wndclass.lpfnWndProc = ProgressWndProc;
RegisterClass(&wndclass);
hwnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
szAppName,
TEXT("Progress Test"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
350, 100,
NULL,
NULL,
hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.lParam;
}
// Hauptnachrichtenschleife
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
// ProgressBar erzeugen
hwndProgress = CreateWindowEx(0, PROGRESS_CLASS, "",
WS_CHILD | PBS_SMOOTH | WS_VISIBLE,
10, 20, 310, 20, hwnd, NULL, ((LPCREATESTRUCT) lParam)->hInstance, NULL);
// Den ursprünglichen WND-PROC Pointer sichern und durch den eigenen ersetzen.
PrevWndProcProzess = SetWindowLong (hwndProgress, GWL_WNDPROC, (LONG)ProgressWndProc);
SendMessage(hwndProgress, PBM_SETRANGE, 0, MAKELPARAM(0, 1000));
SendMessage(hwndProgress, PBM_SETPOS, 500, 0);
SetTimer(hwnd, INCTIMERID1, 100, (TIMERPROC) IncTimer1);
return 0;
case WM_DESTROY:
// Den ursprünglichen Pointer wieder einsetzen
SetWindowLong (hwndProgress, GWL_WNDPROC, PrevWndProcProzess);
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
// Die neue WND-PROC für das ProgressBar
LRESULT CALLBACK ProgressWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static RECT Rect;
HDC hdc;
PAINTSTRUCT ps;
static TCHAR szStr[50];
HRGN hRgn;
COLORREF BarFore = RGB(0,128,0), // Farbe Fortschritts Anzeige
BarBk = RGB(255,0,0), // Hintergrund Farbe
TextFore = RGB(0,0,0), // Text Farbe Auf Hintergrund
TextBk = RGB(255,255,255); // Text Farbe Auf Fortschritts Anzeige
HBRUSH hBrush1,hBrush2;
switch (message)
{
case WM_LBUTTONDOWN:
case WM_PAINT:
{
wsprintf(szStr,"Test %d %%",progress);
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&Rect);
hBrush1=CreateSolidBrush(BarFore);
hBrush2=CreateSolidBrush(BarBk);
//drawing left part of bar
hRgn=CreateRectRgn(0,0,progress*Rect.right/100,Rect.bottom);
FillRgn(hdc,hRgn,(HBRUSH)hBrush1);
SetBkMode(hdc,TRANSPARENT);
SelectClipRgn(hdc,hRgn);
SetTextColor(hdc,TextBk);
DrawText (hdc, szStr, lstrlen(szStr), &Rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE) ;
SelectClipRgn(hdc,NULL);
DeleteObject(hRgn);
//drawing right part of bar
hRgn=CreateRectRgn((progress*Rect.right/100),0,Rect.right,Rect.bottom);
FillRgn(hdc,hRgn,(HBRUSH)hBrush2);
SelectClipRgn(hdc,hRgn);
SetTextColor(hdc,TextFore);
DrawText (hdc, szStr, lstrlen(szStr), &Rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE) ;
SelectClipRgn(hdc,NULL);
DeleteObject(hRgn);
DeleteObject(hBrush1);
DeleteObject(hBrush2);
EndPaint(hwnd,&ps);
}
return 0;
}
return CallWindowProc ((WNDPROC) PrevWndProcProzess, hwnd, message, wParam, lParam);
return DefWindowProc(hwnd, message, wParam, lParam);
}
[/code]