// Windows C 图形程序设计 正弦波 ZXB.cpp // 定义应用程序进入点 #include #include #include "ZXB.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_ZXB, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // 初始化窗口,注册窗口 nCmdShow if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_ZXB); // 主消息循环,检索消息 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_ZXB); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); // 工作区背景颜色(画刷) // +2 +1 +0 -1 -2 -3 // 黑 白 浅灰 灰 蓝 浅蓝 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW-3); wcex.lpszMenuName = (LPCSTR)IDC_ZXB; 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 图形程序设计 fsxss", 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=RGB(255,255,0); //画笔颜色: static COLORREF crBrushColor=RGB(0,111,111); //画刷颜色: HPEN hPen; TCHAR szZXB[MAX_LOADSTRING]; // 装载字符串 "ZXB" LoadString(hInst, IDS_ZXB, szZXB, MAX_LOADSTRING); // * 定义变量 double x0=400,x01=213,x02=588,x,x1=x02-100,x2=x02+100,xw; double y0=270,y01=158,y02=382,y,ym=90,bs; 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); // 检取设备描述表 // 1.用点函数黄绿青色水平垂直扫描刷新全屏 // 水平黄色扫描刷新全屏 for(y=y0-300;yx0+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;xx01-184;x-=0.01) { for(y=y0+220;y>y0+218;y--) { SetPixel(hdc,int(x),int(y),RGB(255,0,255)); } } //左边框紫线 for(y=y0+220;y>y0-220;y-=0.01) { for(x=x01-184;xx02-184;x-=0.01) { for(y=y0+220;y>y0+218;y--) { SetPixel(hdc,int(x),int(y),RGB(0,255,0)); } } //左边框绿线 for(y=y0+220;y>y0-220;y-=0.01) { for(x=x02-184;x