Click here to Skip to main content
15,908,768 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How can I know if the user is pressing on a CButton for more than 250msec? (MFC CButton) Pin
Gary R. Wheeler22-Jan-05 2:25
Gary R. Wheeler22-Jan-05 2:25 
GeneralSome question about MCIWndSave() Pin
hcgiap21-Jan-05 22:40
hcgiap21-Jan-05 22:40 
GeneralRe: Some question about MCIWndSave() Pin
hcgiap24-Jan-05 7:59
hcgiap24-Jan-05 7:59 
GeneralUnit tests Pin
Ravi Bhavnani21-Jan-05 17:48
professionalRavi Bhavnani21-Jan-05 17:48 
GeneralRe: Unit tests Pin
Bob Ciora21-Jan-05 19:02
Bob Ciora21-Jan-05 19:02 
GeneralRe: Unit tests Pin
Henry miller24-Jan-05 4:47
Henry miller24-Jan-05 4:47 
GeneralRe: Unit tests Pin
Ravi Bhavnani24-Jan-05 5:11
professionalRavi Bhavnani24-Jan-05 5:11 
GeneralConfused with some GDI functions Pin
LiYS21-Jan-05 17:15
LiYS21-Jan-05 17:15 
hdc = GetDC (hwnd) ;<br />
          hdcMem = CreateCompatibleDC (hdc) ;<br />
          hBitmap = CreateCompatibleBitmap (hdc, cxTotal, cyTotal) ;<br />
          ReleaseDC (hwnd, hdc) ;<br />
          <br />
          SelectObject (hdcMem, hBitmap) ;<br />
          Rectangle (hdcMem, -1, -1, cxTotal + 1, cyTotal + 1) ;<br />
          <br />
          hBrush = CreateHatchBrush (HS_DIAGCROSS, 0L) ;<br />
          SelectObject (hdcMem, hBrush) ;<br />
          SetBkColor (hdcMem, RGB (255, 0, 255)) ;<br />
          Ellipse (hdcMem, cxMove, cyMove, cxTotal - cxMove, cyTotal - cyMove) ;

================
The hwnd has a white background color, I wonder how's the preceding codes turn out to be a cyTotal * cxTotal rectangular(white bkground) and within which is a centered circle(pink bkground) painted with hatched brush. How's the code " Rectangle (hdcMem, -1, -1, cxTotal + 1, cyTotal + 1) " play a part? Could anybody give me a explanations in details
The following is the complete source code

#include <windows.h><br />
#define ID_TIMER    1<br />
<br />
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;<br />
<br />
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,<br />
                    PSTR szCmdLine, int iCmdShow)<br />
{<br />
     static TCHAR szAppName[] = TEXT ("Bounce") ;<br />
     HWND         hwnd ;<br />
     MSG          msg ;<br />
     WNDCLASS     wndclass ;<br />
<br />
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;<br />
     wndclass.lpfnWndProc   = WndProc ;<br />
     wndclass.cbClsExtra    = 0 ;<br />
     wndclass.cbWndExtra    = 0 ;<br />
     wndclass.hInstance     = hInstance ;<br />
     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;<br />
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;<br />
     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;<br />
     wndclass.lpszMenuName  = NULL ;<br />
     wndclass.lpszClassName = szAppName ;<br />
     <br />
     if (!RegisterClass (&wndclass))<br />
     {<br />
          MessageBox (NULL, TEXT ("This program requires Windows NT!"),<br />
                      szAppName, MB_ICONERROR) ;<br />
          return 0 ;<br />
     }<br />
     <br />
     hwnd = CreateWindow (szAppName, TEXT ("Bouncing Ball"),<br />
                          WS_OVERLAPPEDWINDOW,<br />
                          CW_USEDEFAULT, CW_USEDEFAULT,<br />
                          CW_USEDEFAULT, CW_USEDEFAULT,<br />
                          NULL, NULL, hInstance, NULL) ;<br />
     <br />
     ShowWindow (hwnd, iCmdShow) ;<br />
     UpdateWindow (hwnd) ;<br />
<br />
<br />
     while (GetMessage (&msg, NULL, 0, 0))<br />
     {<br />
          TranslateMessage (&msg) ;<br />
          DispatchMessage (&msg) ;<br />
     }<br />
     return msg.wParam ;<br />
}<br />
<br />
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)<br />
{<br />
     static HBITMAP hBitmap ;<br />
     static int     cxClient, cyClient, xCenter, yCenter, cxTotal, cyTotal,<br />
                    cxRadius, cyRadius, cxMove, cyMove, xPixel, yPixel ;<br />
     HBRUSH         hBrush ;<br />
     HDC            hdc, hdcMem ;<br />
     int            iScale ;<br />
     <br />
     switch (iMsg)<br />
     {<br />
     case WM_CREATE:<br />
          hdc = GetDC (hwnd) ;<br />
          xPixel = 1/*GetDeviceCaps (hdc, ASPECTX)*/ ;<br />
          yPixel = 1/*GetDeviceCaps (hdc, ASPECTY)*/ ;<br />
          ReleaseDC (hwnd, hdc) ;<br />
          <br />
          SetTimer (hwnd, ID_TIMER, 50, NULL) ;<br />
          return 0 ;<br />
          <br />
     case WM_SIZE:<br />
          xCenter = (cxClient = LOWORD (lParam)) / 2 ;<br />
          yCenter = (cyClient = HIWORD (lParam)) / 2 ;<br />
          <br />
          iScale = min (cxClient, cyClient) / 16 ;<br />
          <br />
          cxRadius = iScale;<br />
          cyRadius = iScale;<br />
          <br />
          cxMove = max (1, cxRadius / 2) ;<br />
          cyMove = max (1, cyRadius / 2) ;<br />
          <br />
          cxTotal = 2 * (cxRadius + cxMove) ;<br />
          cyTotal = 2 * (cyRadius + cyMove) ;<br />
          <br />
          if (hBitmap)<br />
               DeleteObject (hBitmap) ;<br />
          hdc = GetDC (hwnd) ;<br />
          hdcMem = CreateCompatibleDC (hdc) ;<br />
          hBitmap = CreateCompatibleBitmap (hdc, cxTotal, cyTotal) ;<br />
          ReleaseDC (hwnd, hdc) ;<br />
          <br />
          SelectObject (hdcMem, hBitmap) ;<br />
          Rectangle (hdcMem, -1, -1, cxTotal + 1, cyTotal + 1) ;<br />
          <br />
          hBrush = CreateHatchBrush (HS_DIAGCROSS, 0L) ;<br />
          SelectObject (hdcMem, hBrush) ;<br />
          SetBkColor (hdcMem, RGB (255, 0, 255)) ;<br />
          Ellipse (hdcMem, cxMove, cyMove, cxTotal - cxMove, cyTotal - cyMove) ;<br />
          DeleteDC (hdcMem) ;<br />
          DeleteObject (hBrush) ;<br />
          return 0 ;<br />
          <br />
     case WM_TIMER:<br />
          if (!hBitmap)<br />
               break ;<br />
          <br />
          hdc = GetDC (hwnd) ;<br />
          hdcMem = CreateCompatibleDC (hdc) ;<br />
          SelectObject (hdcMem, hBitmap) ;<br />
          <br />
          BitBlt (hdc, xCenter - cxTotal / 2,<br />
                       yCenter - cyTotal / 2, cxTotal, cyTotal,<br />
                  hdcMem, 0, 0, SRCCOPY) ;<br />
          <br />
          ReleaseDC (hwnd, hdc) ;<br />
          DeleteDC (hdcMem) ;<br />
          <br />
          xCenter += cxMove ;<br />
          yCenter += cyMove ;<br />
          <br />
          if ((xCenter + cxRadius >= cxClient) || (xCenter - cxRadius <= 0))<br />
               cxMove = -cxMove ;<br />
          <br />
          if ((yCenter + cyRadius >= cyClient) || (yCenter - cyRadius <= 0))<br />
               cyMove = -cyMove ;<br />
          <br />
          return 0 ;<br />
          <br />
     case WM_DESTROY:<br />
          if (hBitmap)<br />
               DeleteObject (hBitmap) ;<br />
          <br />
          KillTimer (hwnd, ID_TIMER) ;<br />
          PostQuitMessage (0) ;<br />
          return 0 ;<br />
     }<br />
     return DefWindowProc (hwnd, iMsg, wParam, lParam) ;<br />
}

GeneralRe: Confused with some GDI functions Pin
Bob Ciora21-Jan-05 18:59
Bob Ciora21-Jan-05 18:59 
GeneralRe: Confused with some GDI functions Pin
LiYS21-Jan-05 22:48
LiYS21-Jan-05 22:48 
General#pragma pack(1) packing wrong structure sizes ! ! ! Pin
Alan Chambers21-Jan-05 14:58
Alan Chambers21-Jan-05 14:58 
GeneralRe: #pragma pack(1) packing wrong structure sizes ! ! ! Pin
Tim Smith21-Jan-05 15:10
Tim Smith21-Jan-05 15:10 
GeneralRe: #pragma pack(1) packing wrong structure sizes ! ! ! Pin
Alan Chambers21-Jan-05 23:59
Alan Chambers21-Jan-05 23:59 
GeneralRe: #pragma pack(1) packing wrong structure sizes ! ! ! Pin
Alan Chambers28-Jan-05 11:05
Alan Chambers28-Jan-05 11:05 
QuestionHow to use shared-memory to map uncertain page file Pin
shusong21-Jan-05 14:06
shusong21-Jan-05 14:06 
AnswerRe: How to use shared-memory to map uncertain page file Pin
Bob Ciora21-Jan-05 19:47
Bob Ciora21-Jan-05 19:47 
QuestionHow to draw a ListView frame Pin
Björn Eiríksson21-Jan-05 13:25
sussBjörn Eiríksson21-Jan-05 13:25 
QuestionHow to perform qsort on a CList of class objects? Pin
wsquare21-Jan-05 12:51
wsquare21-Jan-05 12:51 
AnswerRe: How to perform qsort on a CList of class objects? Pin
wsquare21-Jan-05 12:56
wsquare21-Jan-05 12:56 
AnswerRe: How to perform qsort on a CList of class objects? Pin
Anonymous21-Jan-05 13:31
Anonymous21-Jan-05 13:31 
AnswerRe: How to perform qsort on a CList of class objects? Pin
Bob Ciora21-Jan-05 18:48
Bob Ciora21-Jan-05 18:48 
GeneralRe: How to perform qsort on a CList of class objects? Pin
wsquare21-Jan-05 19:58
wsquare21-Jan-05 19:58 
GeneralRe: How to perform qsort on a CList of class objects? Pin
markkuk22-Jan-05 0:03
markkuk22-Jan-05 0:03 
GeneralRe: How to perform qsort on a CList of class objects? Pin
Bob Ciora22-Jan-05 3:25
Bob Ciora22-Jan-05 3:25 
GeneralRe: How to perform qsort on a CList of class objects? Pin
markkuk23-Jan-05 4:31
markkuk23-Jan-05 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.