16,472
社区成员
发帖
与我相关
我的任务
分享
PAINTSTRUCT ps;
CDC* pDC=BeginPaint(&ps);
int nPos=m_Pro.GetPos();
CString csPos;
csPos.Format("%d%%",nPos);
CRect clientRC;
GetClientRect(clientRC);
CSize sztext=pDC->GetTextExtent(csPos);
int nX=(clientRC.Width()-sztext.cx)/2;
int nY=(clientRC.Height()-sztext.cy)/2;
//pDC->SetBkMode(TRANSPARENT);
int nMin,nMax;
m_Pro.GetRange(nMin,nMax);
double dFraction=(double)clientRC.Width()/(nMax-nMin);
int nLeft=nPos * dFraction;
CRect leftRC=clientRC;
leftRC.left=nLeft;
CRect rightRC=clientRC;
rightRC.left=nLeft;
//pDC->FillRect(leftRC,&CBrush(m_Pro));
pDC->FillRect(leftRC,&CBrush(m_crBlank));
pDC->SetTextColor(m_crText);
pDC->TextOut(nX,nY,csPos);
ReleaseDC(pDC);
EndPaint(&ps);
// ProgressBar
LRESULT CALLBACK PBProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
int nPos;
RECT clientRC;
RECT leftRC;
double dFraction;
int nLeft;
HBRUSH br;
char prompt[40];
SIZE sz;
// get oldproc
WNDPROC OldPbProc=(WNDPROC)GetProp(hWnd,"PbOldProc");
sprintf(prompt,"PBProc:%d\n",Msg);// case WM_NOTIFY=4E
OutputDebugString(prompt);
//
switch(Msg)
{
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
nPos=SendMessage(hWnd,PBM_GETPOS,0,0);
GetClientRect(hWnd,&clientRC);
FillRect(hdc,&clientRC,(HBRUSH)GetStockObject(LTGRAY_BRUSH));
dFraction=(double)(clientRC.right)/(100);
nLeft=(int) (nPos * dFraction);
leftRC=clientRC;
leftRC.right=nLeft;
leftRC.top+=18;
br=CreateSolidBrush(RGB(255,0,0));
FillRect(hdc,&leftRC,br);
sprintf(prompt,"%d%%",nPos);
GetTextExtentPoint32(hdc,prompt,strlen(prompt),&sz);
SetTextColor(hdc,RGB(0,0,0));
SetBkMode(hdc,TRANSPARENT);
TextOut(hdc,(int)(nLeft*(clientRC.right-sz.cx)/(double)clientRC.right),0,prompt,strlen(prompt));
EndPaint(hWnd,&ps);
return 1;
case WM_TIMER:
SendMessage(hWnd,PBM_STEPIT,0,0);
return 1;
}
return CallWindowProc(OldPbProc, hWnd, Msg, wParam, lParam);
}