阅读:1038回复:4
块愁死我了,大家帮帮我!
我想当鼠标按下时随便画一条直线,可是就这么简单的一个功能居然实现不了,大家帮我看看我的代码是哪里的问题,快愁死我了!谢谢
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; int wmId, wmEvent; PAINTSTRUCT ps; TCHAR szHello[MAX_LOADSTRING]; HPEN hPen; int nDraw = 0; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_HELP_ABOUT: DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDOK: SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd); SendMessage (hWnd, WM_CLOSE, 0, 0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_CREATE: g_hwndCB = CreateRpCommandBar(hWnd); // Initialize the shell activate info structure memset (&s_sai, 0, sizeof (s_sai)); s_sai.cbSize = sizeof (s_sai); hPen = (HPEN)CreatePen(PS_SOLID, 1, RGB(255, 0, 0)); break; case WM_PAINT: RECT rt; hdc = BeginPaint(hWnd, &ps); //GetClientRect(hWnd, &rt); //LoadString(g_hInst, IDS_HELLO, szHello, MAX_LOADSTRING); //DrawText(hdc, szHello, _tcslen(szHello), &rt, //DT_SINGLELINE | DT_VCENTER | DT_CENTER); EndPaint(hWnd, &ps); break; case WM_LBUTTONDOWN : hdc = BeginPaint(hWnd, &ps); g_pt[0].x = 10; g_pt[0].y = 10; g_pt[1].x = 100; g_pt[1].y = 100; SelectObject(hdc, hPen); Polyline(hdc, g_pt, 2); EndPaint(hWnd, &ps); break; case WM_DESTROY: CommandBar_Destroy(g_hwndCB); PostQuitMessage(0); break; case WM_ACTIVATE: // Notify shell of our activate message SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE); break; case WM_SETTINGCHANGE: SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } |
|
论坛版主
|
沙发#
发布于:2004-07-07 16:15
看看把作图的部分
hdc = BeginPaint(hWnd, &ps); g_pt[0].x = 10; g_pt[0].y = 10; g_pt[1].x = 100; g_pt[1].y = 100; SelectObject(hdc, hPen); Polyline(hdc, g_pt, 2); EndPaint(hWnd, &ps); 移到WM_PAINT这个消息处理中,WM_LBUTTONDOWN 中向主窗口发送一个WM_PAINT消息. |
|
论坛版主
|
板凳#
发布于:2004-07-07 16:20
还有注意端点不要超过显示区,线的颜色不要和底色一样了。
|
|
地板#
发布于:2004-07-08 08:46
谢谢楼上的,以后还要向你多多请教!
|
|
地下室#
发布于:2004-07-08 09:45
Windows 编程上有个例子你抄一下。
|
|
|