// Windows C 图形程序设计 矩形圆形 JXYX.cpp // 定义应用程序进入点 #include #include #include "JXYX.h" #include "string.h" #include "stdafx.h" #include "resource.h" #define MAX_LOADSTRING 100 // 公有变量 HINSTANCE hInst; // 当前实例 HWND hWndMain; WPARAM wParam; TCHAR szTitle[MAX_LOADSTRING]; // 标题栏 TCHAR szWindowClass[MAX_LOADSTRING]; // Foward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); // Windows 应用程序入口点 WinMain int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. MSG msg; HACCEL hAccelTable; // 初始化公有字符串 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_JXYX, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // 初始化窗口,注册窗口 nCmdShow if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_JXYX); // 主消息循环,检索消息 GetMessage while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } // 注册窗口类,填写窗口属性 RegisterClass ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_JXYX); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); // 工作区背景颜色(画刷) // +2 +1 +0 -1 -2 -3 // 黑 白 浅灰 灰 蓝 浅蓝 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW-3); wcex.lpszMenuName = (LPCSTR)IDC_JXYX; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex); } BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; // 保存实例句柄 hInst = hInstance; // 创建窗口 CreateWindow hWnd = CreateWindow( szWindowClass, // 窗口标题栏 "Visual C++ 6.0 Windows C 图形程序设计 ddxss", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } // 显示窗口 ShowWindow ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } // 窗口过程函数 WndProc,接收和处理消息 LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; static int fnPenStyle=PS_SOLID; //画笔风格:实线 static int nPenWidth=2; //画笔宽度: static COLORREF crPenColor=0; //画笔颜色: static COLORREF crBrushColor=0; //画刷颜色: HPEN hPen; TCHAR szJXYX[MAX_LOADSTRING]; // 装载字符串 "JXYX" LoadString(hInst, IDS_JXYX, szJXYX, MAX_LOADSTRING); int x0=400,y0=270,x,y; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // 菜单选择 switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: // 画图准备 BeginPaint hdc = BeginPaint(hWnd, &ps); // 添加画图代码 hdc = GetDC(hWnd); // 检取设备描述表 // 矩形紫色边框线 hPen=CreatePen(fnPenStyle,nPenWidth,crPenColor); SelectObject(hdc,hPen); Rectangle(hdc,x0-390,y0-240,x0+390,y0+240); // 上边小圆框 for(x=x0-370;x