#include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); /* The 'main' function of Win32 GUI programs: this is where execution starts */ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { static TCHAR szClassName[] = TEXT("HelloWin"); /*窗口類名*/ HWND hwnd; /*窗口句柄*/ MSG msg; /*消息*/ WNDCLASS wndclass; /*窗口類*/ /***********第一步:註冊窗口類*************/ /*爲窗口類各個字段賦值*/ wndclass.style = CS_HREDRAW | CS_VREDRAW; /*窗口風格*/ wndclass.lpfnWndProc = WndProc; /*窗口過程*/ wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; /*當前窗口句柄*/ wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); /*窗口圖標*/ wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);/*鼠標樣式*/ wndclass.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);/*窗口背景畫刷*/ wndclass.lpszMenuName = NULL; /*窗口菜單*/ wndclass.lpszClassName= szClassName; /*窗口類名*/ /*註冊窗口*/ RegisterClass(&wndclass); /*************第二步:建立窗口(並讓窗口顯示出來)***************/ hwnd = CreateWindow( szClassName, /*窗口名字*/ TEXT("Welcome"), /*窗口標題*/ WS_OVERLAPPEDWINDOW, /*窗口風格*/ CW_USEDEFAULT, /*初始化x軸的位置*/ CW_USEDEFAULT, /*初始化y軸的位置*/ 640, /*窗口寬度*/ 480, /*窗口高度*/ NULL, /*父窗口句柄*/ NULL, /*窗口菜單句柄*/ hInstance, /*當前窗口句柄*/ NULL /*不使用該值*/ ); if(hwnd == NULL) { MessageBox(NULL, "建立窗口出錯!", "Error", MB_OK); return -1; } /*顯示窗口*/ ShowWindow(hwnd, nCmdShow); /*更新(繪製)窗口*/ UpdateWindow(hwnd); /*************第三步:消息循環*************/ while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); /*翻譯消息*/ DispatchMessage(&msg); /*分派消息*/ } return msg.wParam; /*當GetMessage程序返回FALSE是程序結束*/ } /*************第四步:窗口過程*****************/ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; /*定義一個畫筆句柄,定義爲靜態變量*/ static HPEN hPen; /*定義一個畫刷句柄,定義爲靜態變量*/ static HBRUSH hSolidBrush; switch(message) { case WM_CREATE: { /*建立筆觸大小爲2個像素的紅色點線畫筆,保存句柄到hPen變量*/ hPen = CreatePen(PS_SOLID, 2, RGB(255, 0, 0)); /*建立實心畫刷,保存到句柄hSolidBrush變量*/ hSolidBrush = CreateSolidBrush(RGB(12, 0, 255)); break; } case WM_PAINT: { hdc = BeginPaint(hWnd, &ps); SelectObject(hdc, hPen); /*選入畫筆到設備環境*/ SelectObject(hdc, hSolidBrush); /*選入畫刷到設備環境*/ Ellipse(hdc, 0, 100, 200, 200); EndPaint(hWnd, &ps); break; } /*窗口銷燬消息*/ case WM_DESTROY: { /*處理WM_DESTROY消息時刪除以前咱們建立的一切GDI對象*/ DeleteObject(hPen); DeleteObject(hSolidBrush); PostQuitMessage(0); break; } default: { return DefWindowProc(hWnd, message, wParam, lParam); } } return 0; }
CreateHatchBrush 函數能夠用來建立一個指定顏色的含有特定陰影樣式的畫刷,原型爲:windows
HBRUSH CreateHatchBrush(int fnStyle, //畫刷樣式COLORREF crColor //畫刷顏色);
fnStyle 能夠有6種取值:函數
HS_BDIGONAL:45度向上,自左至右的陰影(///)ui
HS_CROSS:表示水平直線和垂直直線交叉陰影(+++)this
HS_DIAGCROSS:45度交叉陰影(XXX)spa
HS_FDIAGONAL:45度向下自左至右的陰影(\\\)翻譯
HS_HORIZONTAL:水平陰影(---)code
HS_VERTICAL:垂直陰影orm
定義:對象
//建立綠色交叉陰影畫刷,保存句柄到 hHatchBrush 變量 hHatchBrush = CreateHatchBrush(HS_DIAGCROSS,RGB(0,255,0));