貌似vc6.0++只能打开一个工程呢

如题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的VC6.0++程序,可以画出驻波图形。 ```c++ #include <windows.h> #include <math.h> #define PI 3.14159265358979323846 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wc; HWND hWnd; MSG msg; memset(&wc, 0, sizeof(wc)); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszClassName = TEXT("MyClass"); RegisterClass(&wc); hWnd = CreateWindow(TEXT("MyClass"), TEXT("驻波图形"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static int cxClient, cyClient; static TCHAR szText[] = TEXT("驻波图形"); static HPEN hPen; static HDC hdc; static double f = 0; switch (message) { case WM_CREATE: hdc = GetDC(hWnd); hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 255)); SelectObject(hdc, hPen); break; case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); break; case WM_PAINT: { PAINTSTRUCT ps; hdc = BeginPaint(hWnd, &ps); SetBkMode(hdc, TRANSPARENT); int x1, x2, y1, y2; //绘制坐标轴 MoveToEx(hdc, 10, cyClient / 2, NULL); LineTo(hdc, cxClient - 10, cyClient / 2); MoveToEx(hdc, cxClient / 2, 10, NULL); LineTo(hdc, cxClient / 2, cyClient - 10); //绘制驻波图形 for (int i = -cxClient / 2; i <= cxClient / 2; i++) { x1 = i; y1 = (int)(cyClient / 2 * (1 + sin(2 * PI * i / 80 + f))); x2 = x1 + 1; y2 = (int)(cyClient / 2 * (1 + sin(2 * PI * (i + 1) / 80 + f))); MoveToEx(hdc, cxClient / 2 + x1, y1, NULL); LineTo(hdc, cxClient / 2 + x2, y2); } f += 0.02; EndPaint(hWnd, &ps); } break; case WM_DESTROY: DeleteObject(hPen); ReleaseDC(hWnd, hdc); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } ``` 程序中使用了sine函数来绘制驻波图形,sin函数中的参数可以根据需要进行调整,可以得到不同的驻波图形。同时使用`WM_SIZE`消息获取窗口大小,使得驻波图形可以自适应窗口大小。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值