DEMO5_5.C
上传用户:cncajx
上传日期:2007-01-03
资源大小:190k
文件大小:19k
源码类别:

GDI/图象编程

开发平台:

Visual C++

  1.   1 /****************************************************************/
  2.   2 /*         Demo5_5   ---  Simple Paint V.2                      */
  3.   3 /****************************************************************/
  4.   4 
  5.   5 #include <windows.h>
  6.   6 #include <math.h>
  7.   7 #include "demo5_5.h"
  8.   8 
  9.   9 
  10.  10 int  PASCAL  WinMain(HANDLE, HANDLE, LPSTR, int);
  11.  11 long FAR PASCAL MainWndProc(HWND, unsigned, WORD, LONG);
  12.  12 long FAR PASCAL ChooseCtrlProc(HWND, unsigned, WORD, LONG);
  13.  13 long FAR PASCAL LineWSCtrlProc(HWND, unsigned, WORD, LONG);
  14.  14 BOOL FAR PASCAL PenDlgProc(HWND, unsigned, WORD, LONG);
  15.  15 BOOL FAR PASCAL BrushDlgProc(HWND, unsigned, WORD, LONG);
  16.  16 
  17.  17 void DrawGraph(HDC, HMENU, BOOL);
  18.  18 void DrawPencil(HDC, HMENU);
  19.  19 void DrawLine(HDC, HMENU, BOOL);
  20.  20 void DrawRect(HDC, HMENU, BOOL);
  21.  21 void DrawEllip(HDC, HMENU, BOOL);
  22.  22 void DrawCircle(HDC, HMENU, BOOL);
  23.  23 void DrawRoundRect(HDC, HMENU, BOOL);
  24.  24 
  25.  25 FARPROC lpPenDlgProc;
  26.  26 FARPROC lpBrushDlgProc;
  27.  27 
  28.  28 HANDLE  hInst;
  29.  29 
  30.  30 int     ToolID  = IDM_PENCIL;
  31.  31 
  32.  32 int     nPenColor = 1;
  33.  33 int     nPenStyle = PS_SOLID;
  34.  34 int     nPenWidth = 1;
  35.  35 
  36.  36 int     nBrushColor = 1;
  37.  37 int     nHatch      = -1;
  38.  38 
  39.  39 typedef struct tagCOLORSTRUCT {
  40.  40    int  cR;
  41.  41    int  cG;
  42.  42    int  cB;
  43.  43 } COLORSTRUCT;
  44.  44 
  45.  45 #define MKCOLOR(A) (RGB(A.cR, A.cG, A.cB))
  46.  46 
  47.  47 extern COLORSTRUCT crDefColor[28];
  48.  48 extern COLORSTRUCT crPCurColor[28];
  49.  49 extern COLORSTRUCT crBCurColor[28];
  50.  50 
  51.  51 POINT OrgPoint;
  52.  52 POINT PrePoint;
  53.  53 POINT CurPoint;
  54.  54 
  55.  55 BOOL    CanUndo = FALSE;
  56.  56 HBITMAP hBitmap;
  57.  57 HDC     hMemDC;
  58.  58 
  59.  59 /****************************************************************/
  60.  60 /*                      WinMain()                               */
  61.  61 /****************************************************************/
  62.  62 
  63.  63 int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  64.  64                    LPSTR lpszCmdLine, int nCmdShow)
  65.  65 {
  66.  66    WNDCLASS wclass;
  67.  67    MSG      msg;
  68.  68    HWND     hWnd;
  69.  69    char     szName[] = "Demo5_5";
  70.  70 
  71.  71    if (!hPrevInstance)
  72.  72     {
  73.  73         wclass.style         = CS_HREDRAW | CS_VREDRAW;
  74.  74         wclass.lpfnWndProc   = MainWndProc;
  75.  75         wclass.cbClsExtra    = 0;
  76.  76         wclass.cbWndExtra    = 0;
  77.  77         wclass.hInstance     = hInstance;
  78.  78         wclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  79.  79         wclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  80.  80         wclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  81.  81         wclass.lpszMenuName  = szName;
  82.  82         wclass.lpszClassName = szName;
  83.  83 
  84.  84         if (!RegisterClass (&wclass))
  85.  85            return (FALSE);
  86.  86 
  87.  87         wclass.style         = CS_HREDRAW | CS_VREDRAW;
  88.  88         wclass.lpfnWndProc   = ChooseCtrlProc;
  89.  89         wclass.cbClsExtra    = 0;
  90.  90         wclass.cbWndExtra    = 0;
  91.  91         wclass.hInstance     = hInstance;
  92.  92         wclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  93.  93         wclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  94.  94         wclass.hbrBackground = GetStockObject(WHITE_BRUSH);
  95.  95         wclass.lpszMenuName  = NULL;
  96.  96         wclass.lpszClassName = "Choose";
  97.  97 
  98.  98         if (!RegisterClass (&wclass))
  99.  99            return (FALSE);
  100. 100 
  101. 101         wclass.style         = CS_HREDRAW | CS_VREDRAW;
  102. 102         wclass.lpfnWndProc   = LineWSCtrlProc;
  103. 103         wclass.cbClsExtra    = 0;
  104. 104         wclass.cbWndExtra    = 0;
  105. 105         wclass.hInstance     = hInstance;
  106. 106         wclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  107. 107         wclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  108. 108         wclass.hbrBackground = COLOR_WINDOW + 1;
  109. 109         wclass.lpszMenuName  = NULL;
  110. 110         wclass.lpszClassName = "LineWS";
  111. 111 
  112. 112         if (!RegisterClass (&wclass))
  113. 113            return (FALSE);
  114. 114     }
  115. 115 
  116. 116     hWnd = CreateWindow(
  117. 117                 szName,
  118. 118                 "Simple Paint V.2" ,
  119. 119                 WS_OVERLAPPEDWINDOW,
  120. 120                 CW_USEDEFAULT,
  121. 121                 CW_USEDEFAULT,
  122. 122                 CW_USEDEFAULT,
  123. 123                 CW_USEDEFAULT,
  124. 124                 NULL,
  125. 125                 NULL,
  126. 126                 hInstance,
  127. 127                 NULL );
  128. 128 
  129. 129     if (!hWnd)
  130. 130         return (FALSE);
  131. 131 
  132. 132     ShowWindow(hWnd, nCmdShow);
  133. 133     UpdateWindow(hWnd);
  134. 134 
  135. 135     while (GetMessage(&msg, NULL, NULL,NULL))
  136. 136        {
  137. 137            TranslateMessage(&msg);
  138. 138            DispatchMessage(&msg);
  139. 139        }
  140. 140     return (msg.wParam);
  141. 141 }
  142. 142 
  143. 143 
  144. 144 /****************************************************************/
  145. 145 /*                      MainWndProc()                           */
  146. 146 /****************************************************************/
  147. 147 
  148. 148 long FAR PASCAL MainWndProc(HWND hWnd, unsigned message,
  149. 149                             WORD wParam, LONG lParam)
  150. 150 {
  151. 151    HDC           hDC;
  152. 152    HMENU         hMenu;
  153. 153    PAINTSTRUCT   ps;
  154. 154    static BOOL   bLBDown;
  155. 155    static int    CX, CY;
  156. 156    static int    MemX=800, MemY=600;
  157. 157 
  158. 158    switch (message)
  159. 159     {
  160. 160       case WM_CREATE :
  161. 161                 hMenu = GetMenu(hWnd);
  162. 162                 CheckMenuItem(hMenu, IDM_PENCIL, MF_CHECKED);
  163. 163                 EnableMenuItem(hMenu, IDM_UNDO, MF_GRAYED);
  164. 164 
  165. 165                 memcpy(crPCurColor, crDefColor,
  166. 166                                 sizeof(crDefColor));
  167. 167                 memcpy(crBCurColor, crDefColor,
  168. 168                                 sizeof(crDefColor));
  169. 169 
  170. 170                 hDC = GetDC(hWnd);
  171. 171                 hMemDC = CreateCompatibleDC(hDC);
  172. 172                 hBitmap = CreateCompatibleBitmap(hDC,
  173. 173                                                 MemX, MemY);
  174. 174                 SelectObject(hMemDC, hBitmap);
  175. 175                 PatBlt(hMemDC, 0, 0, 800, 600, WHITENESS);
  176. 176                 ReleaseDC(hWnd, hDC);
  177. 177 
  178. 178                 hInst = ((LPCREATESTRUCT) lParam)->hInstance;
  179. 179                 return (0);
  180. 180 
  181. 181       case WM_COMMAND :
  182. 182                 hMenu = GetMenu(hWnd);
  183. 183                 switch (wParam)
  184. 184                   {
  185. 185                     case IDM_PENCIL     :
  186. 186                     case IDM_LINE       :
  187. 187                     case IDM_RECT_F     :
  188. 188                     case IDM_RECT       :
  189. 189                     case IDM_ELLIP_F    :
  190. 190                     case IDM_ELLIP      :
  191. 191                     case IDM_CIRCLE_F   :
  192. 192                     case IDM_CIRCLE     :
  193. 193                     case IDM_ROUNDRECT_F:
  194. 194                     case IDM_ROUNDRECT  :
  195. 195 
  196. 196                          if (ToolID == wParam)
  197. 197                             return (0);
  198. 198 
  199. 199                          CheckMenuItem(hMenu, ToolID,
  200. 200                                         MF_UNCHECKED);
  201. 201                          ToolID = wParam;
  202. 202                          CheckMenuItem(hMenu, ToolID,
  203. 203                                         MF_CHECKED);
  204. 204 
  205. 205                          hDC = GetDC(hWnd);
  206. 206                          BitBlt(hMemDC, 0, 0, CX, CY,
  207. 207                                 hDC, 0, 0, SRCCOPY);
  208. 208                          ReleaseDC(hWnd, hDC);
  209. 209 
  210. 210                          hMenu = GetMenu(hWnd);
  211. 211                          EnableMenuItem(hMenu, IDM_UNDO,
  212. 212                                         MF_GRAYED);
  213. 213                          CanUndo = FALSE;
  214. 214 
  215. 215                          break;
  216. 216 
  217. 217                     case IDM_CHOOSEPEN :
  218. 218 
  219. 219                          lpPenDlgProc = MakeProcInstance(
  220. 220                                (FARPROC) PenDlgProc, hInst);
  221. 221 
  222. 222                          DialogBox(hInst, "PENDLG", hWnd,
  223. 223                                    lpPenDlgProc);
  224. 224 
  225. 225                          FreeProcInstance(lpPenDlgProc);
  226. 226                          break;
  227. 227 
  228. 228                     case IDM_CHOOSEBRUSH :
  229. 229 
  230. 230                          lpBrushDlgProc = MakeProcInstance(
  231. 231                                (FARPROC) BrushDlgProc, hInst);
  232. 232 
  233. 233                          DialogBox(hInst, "BRUSHDLG", hWnd,
  234. 234                                    lpBrushDlgProc);
  235. 235 
  236. 236                          FreeProcInstance(lpBrushDlgProc);
  237. 237                          break;
  238. 238 
  239. 239                     case IDM_UNDO :
  240. 240                          InvalidateRect(hWnd, NULL, FALSE);
  241. 241                          EnableMenuItem(hMenu, IDM_UNDO,
  242. 242                                         MF_GRAYED);
  243. 243                          CanUndo = FALSE;
  244. 244                          break;
  245. 245 
  246. 246                     case IDM_CLEAR :
  247. 247                          PatBlt(hMemDC, 0, 0, MemX, MemY,
  248. 248                                 PATCOPY);
  249. 249                          InvalidateRect(hWnd, NULL, TRUE);
  250. 250                          break;
  251. 251 
  252. 252                     case IDM_QUIT :
  253. 253                          DestroyWindow(hWnd);
  254. 254                          break;
  255. 255                   }
  256. 256                 return (0);
  257. 257 
  258. 258       case WM_LBUTTONDOWN :
  259. 259                 SetCapture(hWnd);
  260. 260                 bLBDown = TRUE;
  261. 261 
  262. 262                 OrgPoint = MAKEPOINT(lParam);
  263. 263                 CurPoint = PrePoint = OrgPoint;
  264. 264 
  265. 265                 return (0);
  266. 266 
  267. 267       case WM_LBUTTONUP :
  268. 268                 bLBDown = FALSE;
  269. 269                 ReleaseCapture();
  270. 270 
  271. 271                 hDC = GetDC(hWnd);
  272. 272                 DrawGraph(hDC, GetMenu(hWnd), TRUE);
  273. 273                 ReleaseDC(hWnd, hDC);
  274. 274 
  275. 275                 return (0);
  276. 276 
  277. 277       case WM_MOUSEMOVE :
  278. 278                 if (bLBDown)
  279. 279                   {
  280. 280                     PrePoint = CurPoint;
  281. 281                     CurPoint = MAKEPOINT(lParam);
  282. 282 
  283. 283                     hDC = GetDC(hWnd);
  284. 284                     DrawGraph(hDC, GetMenu(hWnd), FALSE);
  285. 285                     ReleaseDC(hWnd, hDC);
  286. 286                   }
  287. 287                 return (0);
  288. 288 
  289. 289       case WM_SIZE :
  290. 290                 CX = LOWORD(lParam);
  291. 291                 CY = HIWORD(lParam);
  292. 292                 return (0);
  293. 293 
  294. 294       case WM_PAINT :
  295. 295                 hDC = BeginPaint(hWnd, &ps);
  296. 296 
  297. 297                 BitBlt(hDC,
  298. 298                        ps.rcPaint.left, ps.rcPaint.top,
  299. 299                        ps.rcPaint.right-ps.rcPaint.left,
  300. 300                        ps.rcPaint.bottom-ps.rcPaint.top,
  301. 301                        hMemDC,
  302. 302                        ps.rcPaint.left, ps.rcPaint.top,
  303. 303                        SRCCOPY);
  304. 304 
  305. 305                 EndPaint(hWnd, &ps);
  306. 306                 return (0);
  307. 307 
  308. 308       case WM_DESTROY :
  309. 309                 DeleteDC(hMemDC);
  310. 310                 DeleteObject(hBitmap);
  311. 311                 PostQuitMessage(0);
  312. 312                 return (0);
  313. 313 
  314. 314       case WM_SYSCOMMAND :
  315. 315 
  316. 316                 if ((wParam & 0xfff0) != SC_MOUSEMENU &&
  317. 317                     (wParam & 0xfff0) != SC_KEYMENU)
  318. 318                   {
  319. 319                     hDC = GetDC(hWnd);
  320. 320                     BitBlt(hMemDC, 0, 0, CX, CY,
  321. 321                            hDC, 0, 0, SRCCOPY);
  322. 322                     ReleaseDC(hWnd, hDC);
  323. 323 
  324. 324                     hMenu = GetMenu(hWnd);
  325. 325                     EnableMenuItem(hMenu, IDM_UNDO,
  326. 326                                    MF_GRAYED);
  327. 327                     CanUndo = FALSE;
  328. 328                   }
  329. 329 
  330. 330       default :
  331. 331          return(DefWindowProc(hWnd, message, wParam, lParam));
  332. 332     }
  333. 333 }
  334. 334 
  335. 335 
  336. 336 
  337. 337 HBRUSH MyCreateBrush(int nHatchStyle, COLORREF crColor)
  338. 338 {
  339. 339    HBRUSH hBrush;
  340. 340 
  341. 341    if (nHatchStyle == -1)
  342. 342      hBrush = CreateSolidBrush(crColor);
  343. 343    else
  344. 344      hBrush = CreateHatchBrush(nHatchStyle, crColor);
  345. 345 
  346. 346    return (hBrush);
  347. 347 }
  348. 348 
  349. 349 
  350. 350 
  351. 351 void DrawGraph(HDC hDC, HMENU hMenu, BOOL bSure)
  352. 352 {
  353. 353    HPEN   hPen, hPrePen;
  354. 354    HBRUSH hBrush, hPreBrush;
  355. 355 
  356. 356    if (ToolID==IDM_PENCIL || bSure)
  357. 357      {
  358. 358        hPen   = CreatePen(nPenStyle, nPenWidth,
  359. 359                         MKCOLOR(crPCurColor[nPenColor]));
  360. 360        hPrePen   = SelectObject(hDC, hPen);
  361. 361 
  362. 362        if (ToolID==IDM_RECT_F   || ToolID==IDM_ELLIP_F ||
  363. 363            ToolID==IDM_CIRCLE_F || ToolID==IDM_ROUNDRECT_F)
  364. 364          {
  365. 365            hBrush = MyCreateBrush(nHatch,
  366. 366                         MKCOLOR(crBCurColor[nBrushColor]));
  367. 367            hPreBrush  = SelectObject(hDC, hBrush);
  368. 368          }
  369. 369        else
  370. 370          {
  371. 371            hBrush = GetStockObject(NULL_BRUSH);
  372. 372            hPreBrush  = SelectObject(hDC, hBrush);
  373. 373          }
  374. 374      }
  375. 375    else
  376. 376      SelectObject(hDC, GetStockObject(NULL_BRUSH));
  377. 377 
  378. 378    switch (ToolID)
  379. 379      {
  380. 380        case IDM_PENCIL :
  381. 381               DrawPencil(hDC, hMenu);
  382. 382               break;
  383. 383 
  384. 384        case IDM_LINE :
  385. 385               DrawLine(hDC, hMenu, bSure);
  386. 386               break;
  387. 387 
  388. 388        case IDM_RECT_F :
  389. 389        case IDM_RECT   :
  390. 390               DrawRect(hDC, hMenu, bSure);
  391. 391               break;
  392. 392 
  393. 393        case IDM_ELLIP_F :
  394. 394        case IDM_ELLIP   :
  395. 395               DrawEllip(hDC, hMenu, bSure);
  396. 396               break;
  397. 397 
  398. 398        case IDM_CIRCLE_F :
  399. 399        case IDM_CIRCLE   :
  400. 400               DrawCircle(hDC, hMenu, bSure);
  401. 401               break;
  402. 402 
  403. 403        case IDM_ROUNDRECT_F :
  404. 404        case IDM_ROUNDRECT   :
  405. 405               DrawRoundRect(hDC, hMenu, bSure);
  406. 406               break;
  407. 407      }
  408. 408 
  409. 409    if (ToolID==IDM_PENCIL || bSure)
  410. 410      {
  411. 411        SelectObject(hDC, hPrePen);
  412. 412        DeleteObject(hPen);
  413. 413 
  414. 414        if (ToolID==IDM_RECT_F   || ToolID==IDM_ELLIP_F ||
  415. 415            ToolID==IDM_CIRCLE_F || ToolID==IDM_ROUNDRECT_F)
  416. 416          {
  417. 417            SelectObject(hDC, hPreBrush);
  418. 418            DeleteObject(hBrush);
  419. 419          }
  420. 420        else
  421. 421          {
  422. 422            SelectObject(hDC, hPreBrush);
  423. 423          }
  424. 424      }
  425. 425 }
  426. 426 
  427. 427 
  428. 428 
  429. 429 void DrawPencil(HDC hDC, HMENU hMenu)
  430. 430 {
  431. 431    MoveTo(hDC, PrePoint.x, PrePoint.y);
  432. 432    LineTo(hDC, CurPoint.x, CurPoint.y);
  433. 433 
  434. 434    if (! CanUndo)
  435. 435      {
  436. 436        EnableMenuItem(hMenu, IDM_UNDO, MF_ENABLED);
  437. 437        CanUndo = TRUE;
  438. 438      }
  439. 439 }
  440. 440 
  441. 441 
  442. 442 
  443. 443 void DrawLine(HDC hDC, HMENU hMenu, BOOL bSure)
  444. 444 {
  445. 445    int  nDrawMode;
  446. 446 
  447. 447    if (! bSure)
  448. 448      {
  449. 449        nDrawMode = SetROP2(hDC, R2_NOT);
  450. 450 
  451. 451        MoveTo(hDC, OrgPoint.x, OrgPoint.y);
  452. 452        LineTo(hDC, PrePoint.x, PrePoint.y);
  453. 453 
  454. 454        MoveTo(hDC, OrgPoint.x, OrgPoint.y);
  455. 455        LineTo(hDC, CurPoint.x, CurPoint.y);
  456. 456 
  457. 457        SetROP2(hDC, nDrawMode);
  458. 458      }
  459. 459    else
  460. 460      {
  461. 461        MoveTo(hDC, OrgPoint.x, OrgPoint.y);
  462. 462        LineTo(hDC, CurPoint.x, CurPoint.y);
  463. 463 
  464. 464        if (! CanUndo)
  465. 465          {
  466. 466            EnableMenuItem(hMenu, IDM_UNDO, MF_ENABLED);
  467. 467            CanUndo = TRUE;
  468. 468          }
  469. 469      }
  470. 470 }
  471. 471 
  472. 472 
  473. 473 
  474. 474 void DrawRect(HDC hDC, HMENU hMenu, BOOL bSure)
  475. 475 {
  476. 476    int  nDrawMode;
  477. 477 
  478. 478    if (! bSure)
  479. 479      {
  480. 480        nDrawMode = SetROP2(hDC, R2_NOT);
  481. 481 
  482. 482        Rectangle(hDC, OrgPoint.x, OrgPoint.y,
  483. 483                       PrePoint.x, PrePoint.y);
  484. 484 
  485. 485        Rectangle(hDC, OrgPoint.x, OrgPoint.y,
  486. 486                       CurPoint.x, CurPoint.y);
  487. 487 
  488. 488        SetROP2(hDC, nDrawMode);
  489. 489      }
  490. 490    else
  491. 491      {
  492. 492        Rectangle(hDC, OrgPoint.x, OrgPoint.y,
  493. 493                       CurPoint.x, CurPoint.y);
  494. 494 
  495. 495        if (! CanUndo)
  496. 496          {
  497. 497            EnableMenuItem(hMenu, IDM_UNDO, MF_ENABLED);
  498. 498            CanUndo = TRUE;
  499. 499          }
  500. 500      }
  501. 501 }
  502. 502 
  503. 503 
  504. 504 
  505. 505 void DrawEllip(HDC hDC, HMENU hMenu, BOOL bSure)
  506. 506 {
  507. 507    int  nDrawMode;
  508. 508 
  509. 509    if (! bSure)
  510. 510      {
  511. 511        nDrawMode = SetROP2(hDC, R2_NOT);
  512. 512 
  513. 513        Ellipse(hDC, OrgPoint.x, OrgPoint.y,
  514. 514                     PrePoint.x, PrePoint.y);
  515. 515 
  516. 516        Ellipse(hDC, OrgPoint.x, OrgPoint.y,
  517. 517                     CurPoint.x, CurPoint.y);
  518. 518 
  519. 519        SetROP2(hDC, nDrawMode);
  520. 520      }
  521. 521    else
  522. 522      {
  523. 523        Ellipse(hDC, OrgPoint.x, OrgPoint.y,
  524. 524                     CurPoint.x, CurPoint.y);
  525. 525 
  526. 526        if (! CanUndo)
  527. 527          {
  528. 528            EnableMenuItem(hMenu, IDM_UNDO, MF_ENABLED);
  529. 529            CanUndo = TRUE;
  530. 530          }
  531. 531      }
  532. 532 }
  533. 533 
  534. 534 
  535. 535 
  536. 536 void DrawRoundRect(HDC hDC, HMENU hMenu, BOOL bSure)
  537. 537 {
  538. 538    int  nDrawMode;
  539. 539 
  540. 540    if (! bSure)
  541. 541      {
  542. 542        nDrawMode = SetROP2(hDC, R2_NOT);
  543. 543 
  544. 544        RoundRect(hDC, OrgPoint.x, OrgPoint.y,
  545. 545                       PrePoint.x, PrePoint.y,
  546. 546                       (PrePoint.x-OrgPoint.x)/4,
  547. 547                       (PrePoint.y-OrgPoint.y)/4);
  548. 548 
  549. 549        RoundRect(hDC, OrgPoint.x, OrgPoint.y,
  550. 550                       CurPoint.x, CurPoint.y,
  551. 551                       (CurPoint.x-OrgPoint.x)/4,
  552. 552                       (CurPoint.y-OrgPoint.y)/4);
  553. 553 
  554. 554        SetROP2(hDC, nDrawMode);
  555. 555      }
  556. 556    else
  557. 557      {
  558. 558        RoundRect(hDC, OrgPoint.x, OrgPoint.y,
  559. 559                       CurPoint.x, CurPoint.y,
  560. 560                       (CurPoint.x-OrgPoint.x)/4,
  561. 561                       (CurPoint.y-OrgPoint.y)/4);
  562. 562 
  563. 563        if (! CanUndo)
  564. 564          {
  565. 565            EnableMenuItem(hMenu, IDM_UNDO, MF_ENABLED);
  566. 566            CanUndo = TRUE;
  567. 567          }
  568. 568      }
  569. 569 }
  570. 570 
  571. 571 
  572. 572 
  573. 573 void DrawCircle(HDC hDC, HMENU hMenu, BOOL bSure)
  574. 574 {
  575. 575    int    nDrawMode;
  576. 576    int    nLogPixSx, nLogPixSy;
  577. 577    int    Width, Height;
  578. 578    int    SignX, SignY;
  579. 579 
  580. 580    nLogPixSx = GetDeviceCaps(hDC, LOGPIXELSX);
  581. 581    nLogPixSy = GetDeviceCaps(hDC, LOGPIXELSY);
  582. 582 
  583. 583    Width  = CurPoint.x - OrgPoint.x;
  584. 584    Height = CurPoint.y - OrgPoint.y;
  585. 585    SignX  = (Width  >= 0 ? 1 : -1);
  586. 586    SignY  = (Height >= 0 ? 1 : -1);
  587. 587 
  588. 588    if (fabs((float) Width/nLogPixSx) >
  589. 589        fabs((float) Height/nLogPixSy) )
  590. 590       {
  591. 591          CurPoint.x = OrgPoint.x + (float)
  592. 592            fabs(Height) * nLogPixSx / nLogPixSy * SignX;
  593. 593       }
  594. 594    else
  595. 595       {
  596. 596          CurPoint.y = OrgPoint.y + (float)
  597. 597            fabs(Width) * nLogPixSy / nLogPixSx * SignY;
  598. 598       }
  599. 599 
  600. 600 
  601. 601    if (! bSure)
  602. 602      {
  603. 603        nDrawMode = SetROP2(hDC, R2_NOT);
  604. 604 
  605. 605        Ellipse(hDC, OrgPoint.x, OrgPoint.y,
  606. 606                     PrePoint.x, PrePoint.y);
  607. 607 
  608. 608        Ellipse(hDC, OrgPoint.x, OrgPoint.y,
  609. 609                     CurPoint.x, CurPoint.y);
  610. 610 
  611. 611        SetROP2(hDC, nDrawMode);
  612. 612      }
  613. 613    else
  614. 614      {
  615. 615        Ellipse(hDC, OrgPoint.x, OrgPoint.y,
  616. 616                     CurPoint.x, CurPoint.y);
  617. 617 
  618. 618        if (! CanUndo)
  619. 619          {
  620. 620            EnableMenuItem(hMenu, IDM_UNDO, MF_ENABLED);
  621. 621            CanUndo = TRUE;
  622. 622          }
  623. 623      }
  624. 624 }