When writing a clock control problems , how can not draw map. . .

Category: VC/MFC -> ATL/ActiveX/COM Author: pierre19459 Date: 2001-07-08 08:10:21
 
pierre19459
2001-07-08 08:10:21
Define the following variables in the header file :
                  int   m_nSLen;                       // seconds length
int   m_nMLen;                       // minute length
int   m_nHLen  ;                   // hour length
CDC   m_dcMem;
CDC   m_dcClock;
CRect   m_rcFace;

I use the code in ONDRAW () function is implemented to draw a clock dial  , how to perform little reaction at all ah ! ! !

  CRect   rc;
  GetClientRect (& rc);
  m_rcFace = rc;
  CClientDC   dc (this);

  CBitmap   bmpDum1, bmpDum2;

  m_dcMem.CreateCompatibleDC (& dc);

  m_dcClock.CreateCompatibleDC (& dc);

  bmpDum1.CreateCompatibleBitmap (& dc, rc.Width (), rc.Height ());

  bmpDum2.CreateCompatibleBitmap (& dc, rc.Width (), rc.Height ());

  m_dcMem.SelectObject (& bmpDum1);

  m_dcClock.SelectObject (& bmpDum2);

  m_dcClock.FillSolidRect (0,0, rc.Width (), rc.Height (), RGB (200,200,200));

  m_dcClock.SetBkMode (TRANSPARENT);

  // custom brush for draw clock hands
CPen   penGry (PS_SOLID, 7, RGB (0,0,0)) ;
CPen   penBlk (PS_SOLID, 4, RGB (90,90,90));
CPen   * pOldpen = m_dcClock.SelectObject (& penGry);

/ / computing hands length

int   nTokenLen = 28;

int   nClockW;

CFont   ftclock;

nClockW = min (rc.Width (), rc.Height ());

POINT   ptcent;

ptcent.x = (rc.left + rc.right) / 2;

ptcent.y = (rc.top + rc.bottom) / 2;

m_nSLen = nClockW / 2-3;

m_nMLen = nClockW / 3-3;

m_nHLen = nClockW / 4-3;

// according to the display mode , draw a clock
m_Style = 1;      

if (m_Style == 0)     // analog display mode

{
POINT   ptBegin, ptEnd;

        ptcent.x = (rc.left + rc.right) / 2;

        ptcent.y = (rc.top + rc.bottom) / 2;                                   // drawing the center

for (int   i = 0; i < 12; i ++)                           @ successively drawn hourly

{
ptBegin.x = ptcent.x + (long) (nClockW * sin (i * PI * 2.0 / 12.0) / 2);

ptBegin.y = ptcent.y- (long) (nClockW * cos (i * PI * 2.0 / 12.0) / 2);

ptEnd.x = ptcent.x + (long) ((nClockW-nTokenLen) * sin (i * PI * 2.0 / 12.0) / 2);

ptEnd.y = ptcent.y + (long) ((nClockW-nTokenLen) * cos (i * PI * 2.0 / 12.0) / 2);

                if (i% 3 == 0)
{
m_dcClock.SelectObject(&penGry);
ptEnd.x = ptcent.x + (long) ((nClockW-nTokenLen-10) * sin (i * PI * 2.0 / 12.0) / 2);
ptEnd.y=ptcent.y-(long)((nClockW-nTokenLen-10)*sin(i*PI*2.0/12.0)/2);

}
else
m_dcClock.SelectObject (& penBlk);

m_dcClock.MoveTo (ptBegin);
                m_dcClock. LineTo (ptEnd);
}
}
else   if (m_Style == 1)                   // digital display way

{
int   nFontW = rc.Width () / 10;
int   nFontH = (int) (2.5 * nFontW);
ftclock.CreateFont (
nFontH,
nFontW,
0,
0,
FW_BOLD,
0,
0,
0,
0,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH,
" Arial ");
CFont   * pOldFont = m_dcClock. SelectObject (& ftclock);

      // displays "00:00:00"
CString & nbsp initialization ; str = " 00: 00: 00 ";
m_dcClock.SetTextAlign (TA_CENTER);
m_dcClock.SetTextColor (RGB (0,0,0));
m_dcClock.TextOut (ptcent.x, ptcent.y-nFontH / 2, str );
m_dcClock.SetTextColor (RGB (192,192,192));
m_dcClock.TextOut (ptcent.x, ptcent.y-nFontH / 2 + 2, str);
m_dcClock.SelectObject (pOldFont );
ftclock.DeleteObject ();
     
}

// save clock face plate, refresh the screen to use when you need
   
m_dcMem.BitBlt (0,0, rc.Width (), rc.Height (), & m_dcClock, 0,0, SRCCOPY);
m_dcClock.SelectObject (pOldpen );
bmpDum1.DeleteObject ();
bmpDum2.DeleteObject ();

heroes express. . . .
yangguangbeibei1122
2001-07-08 08:21:42
nFontH and nFontW is how much ?
Matrix1978a
2001-07-08 08:36:28
0Xa and 0x19
oyc083
2001-07-08 08:47:27
reply to the second floor , this value is calculated based on the size of the client area , I get a debug time tracking : Value 0Xa and 0x19 's .
jinsong3390
2001-07-08 09:03:29
execute this function to begin
xlxfyzs
2001-07-08 09:19:23
Reply upstairs , compile all OK , do it no problem, there is no result .
honeygua
2001-07-08 09:24:24
did not see the memory window DC DC copying code
gdflq
2001-07-08 09:27:36


that how to add ? Give an opinion Ha
zjsw01
2001-07-08 09:30:38


m_dcMem.BitBlt (0,0, rc.Width (), rc.Height (), & m_dcClock, 0,0, SRCCOPY);
this sentence is right
bipstar
2001-07-08 09:47:22
the wrong time
m_dcMem memory DC
CClientDC   dc (this);
this is your main DC
HGHJGH11
2001-07-08 09:54:51
In fact, you only need to dial the map on it