鱼C论坛

 找回密码
 立即注册
查看: 1439|回复: 0

[学习笔记] 六种Hatch style of the Brush

[复制链接]
发表于 2019-2-14 15:23:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 pwnmelife 于 2019-2-14 15:25 编辑
  1. #include <Windows.h>
  2. #include <strsafe.h>
  3. #include "SysMets.h"
  4. #include <math.h>

  5. #define NUM 1000
  6. #define TWOPI (2 * 3.14159)
  7. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


  8. int WINAPI WinMain(HINSTANCE hInstance,
  9.         HINSTANCE hPrevInstance,
  10.         LPSTR lpCmdLine,
  11.         int nShowCmd) {
  12.         static TCHAR szAppName[] = TEXT("Bill");
  13.         HWND hwnd;
  14.         WNDCLASS wndclass;
  15.         MSG msg;
  16.         
  17.         wndclass.cbClsExtra = 0;
  18.         wndclass.cbWndExtra = 0;

  19.         wndclass.hInstance = hInstance;
  20.         wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  21.         wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  22.         wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  23.         wndclass.lpszClassName = szAppName;
  24.         wndclass.lpszMenuName = NULL;
  25.         wndclass.lpfnWndProc = WndProc;
  26.         wndclass.style = CS_HREDRAW | CS_VREDRAW;

  27.         RegisterClass(&wndclass);
  28.         hwnd = CreateWindow(TEXT("Bill"), TEXT("Tip"), WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
  29.                 CW_USEDEFAULT, 40, CW_USEDEFAULT, 100,
  30.                 NULL, NULL, hInstance, NULL);

  31.         ShowWindow(hwnd, nShowCmd);
  32.         UpdateWindow(hwnd);
  33.         while (GetMessage(&msg, NULL, 0, 0)) {
  34.                 TranslateMessage(&msg);
  35.                 DispatchMessage(&msg);
  36.         }
  37.         return 0;

  38. }

  39. LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
  40.         WPARAM wParam, LPARAM lParam) {
  41.         HDC hdc;
  42.         static int cxClient, cyClient;
  43.         int i;
  44.         PAINTSTRUCT ps;
  45.         static HGDIOBJ hBrush;
  46.         static HGDIOBJ hOldBrush;
  47.         switch (message) {
  48.         case WM_CREATE:
  49.                 return 0;
  50.         case WM_PAINT:
  51.                 hdc = BeginPaint(hwnd, &ps);
  52.                 hBrush = CreateHatchBrush(HS_BDIAGONAL, RGB(255,255,0));
  53.                 hOldBrush = SelectObject(hdc, hBrush);
  54.                 Rectangle(hdc, cxClient/16, cyClient/16, 3 * cxClient/16, 3 * cyClient/16);

  55.                 hBrush = CreateHatchBrush(HS_CROSS, RGB(255, 255, 0));
  56.                 hOldBrush = SelectObject(hdc, hBrush);
  57.                 Rectangle(hdc, 5 * cxClient / 16, cyClient / 16, 7 * cxClient / 16, 3 * cyClient / 16);

  58.                 hBrush = CreateHatchBrush(HS_DIAGCROSS, RGB(255, 255, 0));
  59.                 hOldBrush = SelectObject(hdc, hBrush);
  60.                 Rectangle(hdc, 9 * cxClient / 16, cyClient / 16, 11 * cxClient / 16, 3 * cyClient / 16);



  61.                 hBrush = CreateHatchBrush(HS_FDIAGONAL, RGB(255, 255, 0));
  62.                 hOldBrush = SelectObject(hdc, hBrush);
  63.                 Rectangle(hdc, cxClient / 16, cyClient / 2, 3 * cxClient / 16, 5 * cyClient / 8);

  64.                 hBrush = CreateHatchBrush(HS_HORIZONTAL, RGB(255, 255, 0));
  65.                 hOldBrush = SelectObject(hdc, hBrush);
  66.                 Rectangle(hdc, 5 * cxClient / 16, cyClient / 2, 7 * cxClient / 16, 5 * cyClient / 8);

  67.                 hBrush = CreateHatchBrush(HS_VERTICAL, RGB(255, 255, 0));
  68.                 hOldBrush = SelectObject(hdc, hBrush);
  69.                 Rectangle(hdc, 9 * cxClient / 16, cyClient / 2, 11 * cxClient / 16, 5 * cyClient / 8);

  70.                 SelectObject(hdc, hOldBrush);
  71.                 EndPaint(hwnd, &ps);
  72.                 return 0;
  73.         case WM_SIZE:
  74.                 cxClient = LOWORD(lParam);
  75.                 cyClient = HIWORD(lParam);
  76.                 return 0;
  77.         case WM_DESTROY:
  78.                 DeleteObject(hBrush);
  79.                 PostQuitMessage(0);
  80.                 return 0;
  81.         default:
  82.                 return DefWindowProc(hwnd, message, wParam, lParam);
  83.         }
  84. }
复制代码

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-25 04:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表