#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; switch(message) { case WM_PAINT: hdc = BeginPaint(hwnd, &ps); /*畫圓角矩形,左上角座標(50,50),右下角座標(150,150),圓角寬10,高15*/ RoundRect(hdc, 50, 50, 150, 150, 10, 15); EndPaint(hwnd, &ps); return 0; /*窗口銷燬消息*/ case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
橢圓函數原型:windows
BOOL Ellipse(
HDC hdc, //設備環境句柄
int nLeftRect, //左上角x座標
int nTopRect, //左上角y座標
int nRightRect, //右下角x座標
int nBottomRect //右下角y座標
);函數
畫直線:ui
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
MoveToEx(hdc, 150, 150, NULL); //設定起始點,不保存當前點座標
LineTo(hdc,200, 60); //第一條線
LineTo(hdc, 250, 150); //第二條線
LineTo(hdc, 150, 150); //第三條線
EndPaint(hwnd, &ps);
return 0 ;
this