Home > Software engineering >  The progress bar shows percentage, why don't the progress bar move?
The progress bar shows percentage, why don't the progress bar move?

Time:09-26

 PAINTSTRUCT ps; 
The CDC * pDC=BeginPaint (& amp; Ps);
Int nPos=m_Pro. GetPos ();
Cstrings csPos;
CsPos. The Format (" % d % % ", nPos);
CRect clientRC;
GetClientRect (clientRC);
CSize sztext=pDC - & gt; GetTextExtent (csPos);
Int nX=(clientRC Width () - sztext. Cx)/2;
Int nY=(clientRC Height () - sztext. Cy)/2;
//pDC - & gt; 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 - & gt; FillRect (leftRC, & amp; CBrush (m_Pro));
PDC - & gt; FillRect (leftRC, & amp; CBrush (m_crBlank));
PDC - & gt; SetTextColor (m_crText);
PDC - & gt; TextOut (nX, nY, csPos);
The ReleaseDC (pDC);
EndPaint (& amp; Ps);

CodePudding user response:

//pDC - & gt; FillRect (leftRC, & amp; CBrush (m_Pro));
Cancel this sentence annotations to try again

CodePudding user response:

The progress bar is m_Pro? PDC progress bar?

CodePudding user response:

That is to say you the paint of paint is a progress bar

CodePudding user response:

M_Pro variables is a progress bar

CodePudding user response:

PDC - & gt; FillRect (leftRC, & amp; CBrush (m_Pro)); The m_Pro in this sentence should be m_crProgreess current progress of color

CodePudding user response:

PDC - & gt; FillRect (leftRC, & amp; CBrush (m_Pro));
1 if pDC m_Pro. GetDC (); ?
2 leftRC is a progress bar on the left?
3, & amp; CBrush (m_Pro)???????
CBrush: : CBrush
CBrush ();

The CBrush (a COLORREF crColor);
Throw (CResourceException);

The CBrush (int nIndex, a COLORREF crColor);
Throw (CResourceException);

CBrush (CBitmap * pBitmap);
Throw (CResourceException);

No CBrush (m_Pro)!

CodePudding user response:

PDC - & gt; FillRect (leftRC, & amp; CBrush (m_Pro));
1 if pDC m_Pro. GetDC (); ? Not
2 leftRC is a progress bar on the left? Should be the client area
3, & amp; CBrush (m_Pro)???????
CBrush: : CBrush
CBrush ();

The CBrush (a COLORREF crColor);
Throw (CResourceException);

The CBrush (int nIndex, a COLORREF crColor);
Throw (CResourceException);

CBrush (CBitmap * pBitmap);
Throw (CResourceException);

No CBrush (m_Pro)! Should be a CBrush (m_crProgress); COLORREF m_crProgress;//color

CodePudding user response:

In the progress bar OnPaint, custom painting!

CodePudding user response:

Is in the OnPaint

CodePudding user response:

1 suggestion from CProgressCtrl derived a new class, handle the WM_PAINT message
2 can't block message ring, long operation process in the background

CodePudding user response:

The practice of the win32
1 create
The HWND CreateProgress (HINSTANCE HINSTANCE, HWND hwndParent)
{//progressbar
HWND hProgress=0;
HProgress=CreateWindow (PROGRESS_CLASS/* */"msctls_progress32",
NULL,
WS_VISIBLE | WS_CHILD | WS_TABSTOP | PBS_SMOOTH,
10 and 40, 160, 30,
HwndParent, HMENU IDC_PROGRESS,
HInstance,
NULL);
//
SendMessage (hProgress PBM_SETRANGE, 0, MAKELPARAM (0100));
SendMessage (hProgress PBM_SETSTEP, 1, 0);
The SetTimer (hProgress, 1200, NULL);
//
Return hProgress;

}
2. WndProc subclass (derived)
Case WM_CREATE message handler:
{
M_hProgress=CreateProgress ((HINSTANCE) GetWindowLong (HWND, GWL_HINSTANCE), HWND);
WNDPROC PbOldProc=(WNDPROC) SetWindowLong (m_hProgress GWL_WNDPROC, (LONG) PBProc);
SetProp (m_hProgress,//handle of window
"PbOldProc",//the atom or the address of the string
PbOldProc);
3 new scrollbar
 
//ProgressBar
LRESULT a CALLBACK PBProc (HWND HWND, UINT Msg, WPARAM WPARAM, LPARAM LPARAM)
{
PAINTSTRUCT ps;
HDC HDC.
int nPos;
The RECT clientRC;
The RECT leftRC;
Double dFraction;
Int nLeft;
HBRUSH br;
Char prompt [40].
The SIZE marking;
//get oldproc
WNDPROC OldPbProc=(WNDPROC) GetProp (hWnd, "PbOldProc");
Sprintf (prompt, "PBProc: % d \ n", Msg);//case WM_NOTIFY=4 e
OutputDebugString (prompt);
//
The switch (Msg)
{
In case the WM_PAINT:
HDC=BeginPaint (hWnd, & amp; Ps);
NPos=SendMessage (hWnd PBM_GETPOS, 0, 0).
GetClientRect (hWnd, & amp; ClientRC);
FillRect (HDC, & amp; 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 (0, 255));
FillRect (HDC, & amp; LeftRC, br);
Sprintf (prompt, "% d % %", nPos);
GetTextExtentPoint32 (HDC, prompt, strlen (prompt), & amp; Sz);
SetTextColor (HDC, RGB (0, 0));
SetBkMode (HDC, TRANSPARENT);
TextOut (HDC, (int) (nLeft * (cx) clientRC. Right - sz./(double) clientRC. Right), and 0, prompt, strlen (prompt));
EndPaint (hWnd, & amp; Ps);
return 1;
Case WM_TIMER:
SendMessage (hWnd PBM_STEPIT, 0, 0);
return 1;
}
nullnullnull
  • Related