当前位置:   article > 正文

c语言如何实现捕捉鼠标事件,怎么通过c++实现获取鼠标点击事件?

c语言单击事件

a791b137af350ceacee0c8f742126968.png

ITMISS

#include #include LRESULT CALLBACK WinProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);POINT pt={0,0};int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ){HWND hwnd;MSG msg;BOOL bRet;WNDCLASS wndcls;wndcls.style=CS_HREDRAW|CS_VREDRAW;wndcls.lpfnWndProc=WinProc;wndcls.cbClsExtra=0;wndcls.cbWndExtra=0;wndcls.lpszClassName=TEXT("wjbxngx");wndcls.lpszMenuName=NULL;wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);wndcls.hInstance=hInstance;RegisterClass(&wndcls);hwnd=CreateWindow(TEXT("wjbxngx"),TEXT("示例"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,600,400,NULL,NULL,hInstance,NULL);ShowWindow(hwnd,SW_SHOWNORMAL);UpdateWindow(hwnd);while ((bRet=GetMessage(&msg,hwnd,0,0))!=0){if (bRet==-1){return -1;}else{TranslateMessage(&msg);DispatchMessage(&msg);}}return msg.wParam;}LRESULT CALLBACK WinProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam){HDC hdc;TCHAR szChar[20];PAINTSTRUCT ps;switch(uMsg){case WM_LBUTTONDOWN:pt.x=LOWORD(lParam);pt.y=HIWORD(lParam);break;case WM_RBUTTONDOWN:InvalidateRect(hwnd,NULL,TRUE);break;case WM_MOUSEMOVE:if (wParam&MK_LBUTTON){hdc=GetDC(hwnd);MoveToEx(hdc,pt.x,pt.y,NULL);LineTo(hdc,LOWORD(lParam),HIWORD(lParam));pt.x=LOWORD(lParam);pt.y=HIWORD(lParam);ReleaseDC(hwnd,hdc);}break;case WM_PAINT:hdc=BeginPaint(hwnd,&ps);EndPaint(hwnd,&ps);break;case WM_CLOSE:if (IDYES==MessageBox(hwnd,TEXT("真的要退出吗?"),TEXT("信息"),MB_YESNO)){DestroyWindow(hwnd);}break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hwnd,uMsg,wParam,lParam);}return 0;}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/368326
推荐阅读
相关标签
  

闽ICP备14008679号