// Windows C 图形程序设计 五角星 WJX.cpp // 定义应用程序进入点 #include #include #include "WJX.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_WJX, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // 初始化窗口,注册窗口 nCmdShow if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WJX); // 主消息循环,检索消息 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_WJX); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); // 工作区背景颜色(画刷) // +2 +1 +0 -1 -2 -3 // 黑 白 浅灰 灰 蓝 浅蓝 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW-3); wcex.lpszMenuName = (LPCSTR)IDC_WJX; 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 szWJX[MAX_LOADSTRING]; // 装载字符串 "WJX" LoadString(hInst, IDS_WJX, szWJX, MAX_LOADSTRING); double x0=400.0,y0=270.0,x,y,ym=90.0, x1=x0-220.0,x2=x0+220.0; 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); // 检取设备描述表 // 矩形紫色边框线 // 上边框紫线线宽2 for(x=x0-390.0;xx0+388.0;x--) { SetPixel(hdc,int(x),int(y),RGB(255,0,255)); } } // 下边框紫线 for(x=x0+390.0;x>x0-390.0;x-=0.01) { for(y=y0+240.0;y>y0+238.0;y--) { SetPixel(hdc,int(x),int(y),RGB(255,0,255)); } } // 左边框紫线 for(y=y0+240.0;y>y0-240.0;y-=0.01) { for(x=x0-390.0;xx0+380.0;x--) { SetPixel(hdc,int(x),int(y),RGB(0,255,0)); } } // 下边框绿线 for(x=x0+380.0;x>x0-380.0;x-=0.03) { for(y=y0+235.0;y>y0+230.0;y--) { SetPixel(hdc,int(x),int(y),RGB(0,255,0)); } } // 左边框绿线 for(y=y0+235.0;y>y0-235.0;y-=0.03) { for(x=x0-385.0;xx0+375.0;x--) { SetPixel(hdc,int(x),int(y),RGB(0,255,255)); } } //下边框青线 for(x=x0+377.0;x>x0-377.0;x-=0.01) { for(y=y0+227.0;y>y0+225.0;y--) { SetPixel(hdc,int(x),int(y),RGB(0,255,255)); } } //左边框青线 for(y=y0+227.0;y>y0-225.0;y-=0.01) { for(x=x0-377.0;x