⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo3_3.c

📁 WINDOWS图形编程随书光盘
💻 C
📖 第 1 页 / 共 2 页
字号:
285                                          EllipRect.top,
286                                          EllipRect.right,
287                                          EllipRect.bottom);
288                                  Shape[Num].x1 =
289                                         EllipRect.left;
290                                  Shape[Num].y1 =
291                                         EllipRect.top;
292                                  Shape[Num].x2 =
293                                         EllipRect.right;
294                                  Shape[Num].y2 =
295                                         EllipRect.bottom;
296                                  break;
297                            }
298 
299                          ReleaseDC(hWnd, hDC);
300 
301                          Shape[Num].ShapeID = ShapeID;
302                          Shape[Num].MapModeID = MapModeID;
303                          Num ++;
304                          break;
305 
306                     case IDM_CLEAR :
307                          Num = 0;
308                          InvalidateRect(hWnd, NULL, TRUE);
309                          UpdateWindow(hWnd);
310                          break;
311 
312                   }
313                 return (0);
314 
315       case WM_PAINT :
316             hDC = BeginPaint(hWnd, &ps);
317 
318             DrawAllGraph(hDC, ps.rcPaint, Shape, Num);
319 
320             EndPaint(hWnd, &ps);
321             return (0);
322 
323       case WM_DESTROY :
324                 PostQuitMessage(0);
325                 return (0);
326 
327       default :
328         return (DefWindowProc(hWnd, message, wParam, lParam));
329     }
330 }
331 
332 
333 
334 void DrawAllGraph(HDC hDC, RECT psRect, SHAPE Shape[], int Num)
335 {
336    int     i, temp;
337    RECT    Rect, dstRect;
338    HANDLE  hBrush;
339 
340    for (i=0; i<Num; i++)
341      {
342         switch (Shape[i].MapModeID)
343           {
344             case IDM_TEXT :
345               SetMapMode(hDC, MM_TEXT);
346               break;
347 
348             case IDM_LOMET :
349               SetMapMode(hDC, MM_LOMETRIC);
350               break;
351 
352             case IDM_HIMET :
353               SetMapMode(hDC, MM_HIMETRIC);
354               break;
355 
356             case IDM_LOENG :
357               SetMapMode(hDC, MM_LOENGLISH);
358               break;
359 
360             case IDM_HIENG :
361               SetMapMode(hDC, MM_HIENGLISH);
362               break;
363 
364             case IDM_TWIPS :
365               SetMapMode(hDC, MM_TWIPS);
366               break;
367           }
368 
369         Rect.left  = Shape[i].x1;
370         Rect.right = Shape[i].x2;
371         Rect.top   = Shape[i].y1;
372         Rect.bottom= Shape[i].y2;
373 
374         LPtoDP(hDC, (LPPOINT) &Rect, 2);
375 
376         if (Rect.left > Rect.right)
377           {
378             temp = Rect.left;
379             Rect.left = Rect.right;
380             Rect.right = temp;
381           }
382         if (Rect.top > Rect.bottom)
383           {
384             temp = Rect.top;
385             Rect.top = Rect.bottom;
386             Rect.bottom = temp;
387           }
388 
389         IntersectRect(&dstRect, &Rect, &psRect);
390         if (IsRectEmpty(&dstRect))
391             continue;
392 
393         switch (Shape[i].ShapeID)
394          {
395            case IDM_LINE :
396                      MoveTo(hDC, Shape[i].x1, Shape[i].y1);
397                      LineTo(hDC, Shape[i].x2, Shape[i].y2);
398                      break;
399 
400            case IDM_RECT :
401                      hBrush = GetStockObject(NULL_BRUSH);
402                      SelectObject(hDC, hBrush);
403                      Rectangle(hDC, Shape[i].x1, Shape[i].y1,
404                                     Shape[i].x2, Shape[i].y2);
405                      break;
406 
407            case IDM_ELLIP :
408                      hBrush = GetStockObject(NULL_BRUSH);
409                      SelectObject(hDC, hBrush);
410                      Ellipse(hDC, Shape[i].x1, Shape[i].y1,
411                                   Shape[i].x2, Shape[i].y2);
412                      break;
413          }
414      }
415 }
416 
417 
418 BOOL FAR PASCAL LineDlgProc(HWND hDlg, unsigned msg,
419                             WORD wParam, LONG lParam)
420 {
421    BOOL  btran1, btran2, btran3, btran4;
422    int   x1, y1, x2, y2;
423 
424    switch (msg)
425      {
426        case WM_INITDIALOG :
427           SetDlgItemInt(hDlg, DI_LLEFT,
428                                 LineRect.left, TRUE);
429           SetDlgItemInt(hDlg, DI_LTOP,
430                                 LineRect.top, TRUE);
431           SetDlgItemInt(hDlg, DI_LRIGHT,
432                                 LineRect.right, TRUE);
433           SetDlgItemInt(hDlg, DI_LBOTTOM,
434                                 LineRect.bottom, TRUE);
435           return (TRUE);
436 
437        case WM_COMMAND :
438           switch (wParam)
439             {
440               case DI_LOK :
441                   x1 = GetDlgItemInt(hDlg, DI_LLEFT,
442                                      &btran1, TRUE);
443                   y1 = GetDlgItemInt(hDlg, DI_LTOP,
444                                      &btran2, TRUE);
445                   x2 = GetDlgItemInt(hDlg, DI_LRIGHT,
446                                      &btran3, TRUE);
447                   y2 = GetDlgItemInt(hDlg, DI_LBOTTOM,
448                                      &btran4, TRUE);
449 
450                   if (btran1 && btran2 && btran3 && btran4)
451                     SetRect(&LineRect, x1, y1, x2, y2);
452 
453                   EndDialog(hDlg, TRUE);
454                   return (TRUE);
455 
456               case DI_LCANCEL :
457                   EndDialog(hDlg, FALSE);
458                   return (TRUE);
459             }
460           return (TRUE);
461 
462        default :
463           return (FALSE);
464      }
465 }
466 
467 
468 BOOL FAR PASCAL RectDlgProc(HWND hDlg, unsigned msg,
469                             WORD wParam, LONG lParam)
470 {
471    BOOL  btran1, btran2, btran3, btran4;
472    int   x1, y1, x2, y2;
473 
474    switch (msg)
475      {
476        case WM_INITDIALOG :
477           SetDlgItemInt(hDlg, DI_RLEFT,
478                                 RectRect.left, TRUE);
479           SetDlgItemInt(hDlg, DI_RTOP,
480                                 RectRect.top, TRUE);
481           SetDlgItemInt(hDlg, DI_RRIGHT,
482                                 RectRect.right, TRUE);
483           SetDlgItemInt(hDlg, DI_RBOTTOM,
484                                 RectRect.bottom, TRUE);
485           return (TRUE);
486 
487        case WM_COMMAND :
488           switch (wParam)
489             {
490               case DI_ROK :
491                   x1 = GetDlgItemInt(hDlg, DI_RLEFT,
492                                      &btran1, TRUE);
493                   y1 = GetDlgItemInt(hDlg, DI_RTOP,
494                                      &btran2, TRUE);
495                   x2 = GetDlgItemInt(hDlg, DI_RRIGHT,
496                                      &btran3, TRUE);
497                   y2 = GetDlgItemInt(hDlg, DI_RBOTTOM,
498                                      &btran4, TRUE);
499 
500                   if (btran1 && btran2 && btran3 && btran4)
501                     SetRect(&RectRect, x1, y1, x2, y2);
502 
503                   EndDialog(hDlg, TRUE);
504                   return (TRUE);
505 
506               case DI_RCANCEL :
507                   EndDialog(hDlg, FALSE);
508                   return (TRUE);
509             }
510           return (TRUE);
511 
512        default :
513           return (FALSE);
514      }
515 }
516 
517 
518 BOOL FAR PASCAL EllipDlgProc(HWND hDlg, unsigned msg,
519                              WORD wParam, LONG lParam)
520 {
521    BOOL  btran1, btran2, btran3, btran4;
522    int   x1, y1, x2, y2;
523 
524    switch (msg)
525      {
526        case WM_INITDIALOG :
527           SetDlgItemInt(hDlg, DI_ELEFT,
528                                 EllipRect.left, TRUE);
529           SetDlgItemInt(hDlg, DI_ETOP,
530                                 EllipRect.top, TRUE);
531           SetDlgItemInt(hDlg, DI_ERIGHT,
532                                 EllipRect.right, TRUE);
533           SetDlgItemInt(hDlg, DI_EBOTTOM,
534                                 EllipRect.bottom, TRUE);
535           return (TRUE);
536 
537        case WM_COMMAND :
538           switch (wParam)
539             {
540               case DI_EOK :
541                   x1 = GetDlgItemInt(hDlg, DI_ELEFT,
542                                      &btran1, TRUE);
543                   y1 = GetDlgItemInt(hDlg, DI_ETOP,
544                                      &btran2, TRUE);
545                   x2 = GetDlgItemInt(hDlg, DI_ERIGHT,
546                                      &btran3, TRUE);
547                   y2 = GetDlgItemInt(hDlg, DI_EBOTTOM,
548                                      &btran4, TRUE);
549 
550                   if (btran1 && btran2 && btran3 && btran4)
551                     SetRect(&EllipRect, x1, y1, x2, y2);
552 
553                   EndDialog(hDlg, TRUE);
554                   return (TRUE);
555 
556               case DI_ECANCEL :
557                   EndDialog(hDlg, FALSE);
558                   return (TRUE);
559             }
560           return (TRUE);
561 
562        default :
563           return (FALSE);
564      }
565 }
566 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -