ImageVerifierCode 换一换
格式:DOCX , 页数:35 ,大小:24.80KB ,
资源ID:9248989      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9248989.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(第四讲鼠标.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

第四讲鼠标.docx

1、第四讲鼠标第四讲:鼠标 只要鼠标跨越窗口,或者在某窗口中按下鼠标按钮,那么窗口过程函数就会收到鼠标消息,而不管该窗口是否为活动窗口和是否拥有输入焦点窗口。 鼠标消息:1. lParam是相对于客户区左上角的坐标,其中X坐标:LOWORD(lParam)Y坐标:HIWORD(lParam)2. wParam是Shift键和Ctrl键或鼠标按钮的状态,若wParam & MK_SHIFT0wParam & MK_CONTROL0wParam & MK_LBUTTON0wParam & MK_MBUTTON0wParam & MK_RBUTTON0表示在产生相应的鼠标消息时,也按下了Shift键和C

2、trl键或鼠标按钮。WM_LBUTTONDOWN WM_MBUTTONDOWN WM_RBUTTONDOWN WM_LBUTTONUPWM_RBUTTONUPWM_MBUTTONUPWM_LBUTTONDBLCLKWM_MBUTTONDBLCLKWM_RBUTTONDBLCLKWM_MOUSEMOVE 鼠标双击消息如果希望窗口过程函数能接受鼠标双击消息,那么在注册窗口类时,窗口风格应为:wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS ; 重点:鼠标消息:WM_LBUTTONDOWNWM _MBUTTONDOWN WM_RBUTTOND

3、OWNWM_LBUTTONUPWM_RBUTTONUP WM_MBUTTONUPWM_LBUTTONDBLCLKWM_MBUTTONDBLCLKWM_RBUTTONDBLCLKWM_MOUSEMOVE子窗口风格:WS_CHILDWINDOW | WS_VISIBLE取程序实例句柄:(HINSTANCE)GetWindowLong (hwnd, GWL_HINSTANCE);函数MoveWindow (hwndChildxy, x * cxBlock, y * cyBlock, cxBlock, cyBlock, TRUE) ;移动窗口和改变窗口大小尺寸,产生WM_SIZE消息。存取预留在窗口额

4、外字节的函数:SetWindowLong (hwnd, 0, 0) ;GetWindowLong (hwnd, 0,0);设置窗口捕获鼠标函数:SetCapture(hwnd);一旦窗口hwnd被设置了捕获鼠标,不管鼠标光标是否在窗口hwnd的边界之内,窗口hwnd都接受鼠标输入。释放窗口捕获鼠标函数:ReleaseCapture();WM_MOUSEMOVE消息:每当鼠标移动时,窗口接收WM_MOUSEMOVE消息,系统此时自动把鼠标光标形状切换到在窗口类中定义的鼠标光标形状,如wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;/*- CONN

5、ECT.C - Connect-the-Dots Mouse Demo Program (c) Charles Petzold, 1998 -*/#include #define MAXPOINTS 1000LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) static TCHAR szAppName = TEXT (Connect) ; HWN

6、D hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW)

7、; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass) MessageBox (NULL, TEXT (Program requires Windows NT!), szAppName, MB_ICONERROR) ; return 0 ; hwnd = CreateWindow (szAppName, TEXT (Con

8、nect-the-Points Mouse Demo), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0) TranslateMessage (&msg) ; DispatchMessage (&msg) ; return msg.wParam ;

9、LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) static POINT ptMAXPOINTS ; static int iCount ; HDC hdc ; int i, j ; PAINTSTRUCT ps ; switch (message) case WM_LBUTTONDOWN: iCount = 0 ; InvalidateRect (hwnd, NULL, TRUE) ; return 0 ; case WM_MOUSEMOVE: if (wParam & MK_L

10、BUTTON & iCount 1000) ptiCount .x = LOWORD (lParam) ; ptiCount+.y = HIWORD (lParam) ; hdc = GetDC (hwnd) ; /SetPixel (hdc, LOWORD (lParam), HIWORD (lParam), 0) ; SetPixel (hdc, LOWORD (lParam), HIWORD (lParam), RGB(255,0,0) ; ReleaseDC (hwnd, hdc) ; return 0 ; case WM_LBUTTONUP: InvalidateRect (hwnd

11、, NULL, FALSE) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; SetCursor (LoadCursor (NULL, IDC_WAIT) ; ShowCursor (TRUE) ; for (i = 0 ; i iCount - 1 ; i+) for (j = i + 1 ; j iCount ; j+) MoveToEx (hdc, pti.x, pti.y, NULL) ; LineTo (hdc, ptj.x, ptj.y) ; ShowCursor (FALSE) ; SetCursor (Loa

12、dCursor (NULL, IDC_ARROW) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; return DefWindowProc (hwnd, message, wParam, lParam) ;/*- CHECKER1.C - Mouse Hit-Test Demo Program No. 1 (c) Charles Petzold, 1998 -*/#include #define DIVISIONS 5LRESULT CALLBACK WndProc (

13、HWND, UINT, WPARAM, LPARAM) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) static TCHAR szAppName = TEXT (Checker1) ; HWND hwnd ; MSG msg ; WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbCls

14、Extra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppN

15、ame ; if (!RegisterClass (&wndclass) MessageBox (NULL, TEXT (Program requires Windows NT!), szAppName, MB_ICONERROR) ; return 0 ; hwnd = CreateWindow (szAppName, TEXT (Checker1 Mouse Hit-Test Demo), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstanc

16、e, NULL) ; ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0) TranslateMessage (&msg) ; DispatchMessage (&msg) ; return msg.wParam ;LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) static BOOL fStateDIVISIONSDIVISIONS ; static int

17、 cxBlock, cyBlock ; HDC hdc ; int x, y ; PAINTSTRUCT ps ; RECT rect ; switch (message) case WM_SIZE : cxBlock = LOWORD (lParam) / DIVISIONS ; cyBlock = HIWORD (lParam) / DIVISIONS ; return 0 ; case WM_LBUTTONDOWN : x = LOWORD (lParam) / cxBlock ; y = HIWORD (lParam) / cyBlock ; if (x DIVISIONS & y D

18、IVISIONS) fState xy = 1 ; rect.left = x * cxBlock ; rect.top = y * cyBlock ; rect.right = (x + 1) * cxBlock ; rect.bottom = (y + 1) * cyBlock ; InvalidateRect (hwnd, &rect, FALSE) ; else MessageBeep (0) ; return 0 ; case WM_PAINT : hdc = BeginPaint (hwnd, &ps) ; for (x = 0 ; x DIVISIONS ; x+) for (y

19、 = 0 ; y DIVISIONS ; y+) Rectangle (hdc, x * cxBlock, y * cyBlock, (x + 1) * cxBlock, (y + 1) * cyBlock) ; if (fState xy) MoveToEx (hdc, x * cxBlock, y * cyBlock, NULL) ; LineTo (hdc, (x+1) * cxBlock, (y+1) * cyBlock) ; MoveToEx (hdc, x * cxBlock, (y+1) * cyBlock, NULL) ; LineTo (hdc, (x+1) * cxBloc

20、k, y * cyBlock) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY : PostQuitMessage (0) ; return 0 ; return DefWindowProc (hwnd, message, wParam, lParam) ;/*- CHECKER3.C - Mouse Hit-Test Demo Program No. 3 (c) Charles Petzold, 1998 -*/#include #define DIVISIONS 5LRESULT CALLBACK WndProc (HWND, UIN

21、T, WPARAM, LPARAM) ;LRESULT CALLBACK ChildWndProc (HWND, UINT, WPARAM, LPARAM) ;TCHAR szChildClass = TEXT (Checker3_Child) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) static TCHAR szAppName = TEXT (Checker3) ; HWND hwnd ; MSG msg ; WNDCLASS wndcla

22、ss ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH

23、) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass) MessageBox (NULL, TEXT (Program requires Windows NT!), szAppName, MB_ICONERROR) ; return 0 ; wndclass.lpfnWndProc = ChildWndProc ; wndclass.cbWndExtra = sizeof (long) ;

24、 wndclass.hIcon = NULL ; wndclass.lpszClassName = szChildClass ; RegisterClass (&wndclass) ; hwnd = CreateWindow (szAppName, TEXT (Checker3 Mouse Hit-Test Demo), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, iCmdShow

25、) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0) TranslateMessage (&msg) ; DispatchMessage (&msg) ; return msg.wParam ;LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) static HWND hwndChildDIVISIONSDIVISIONS ; int cxBlock, cyBlock, x, y ; switch (message

26、) case WM_CREATE : for (x = 0 ; x DIVISIONS ; x+) for (y = 0 ; y DIVISIONS ; y+) hwndChildxy = CreateWindow (szChildClass, NULL, WS_CHILDWINDOW | WS_VISIBLE, 0, 0, 0, 0, hwnd, (HMENU) (y 8 | x), (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL) ; return 0 ; case WM_SIZE : cxBlock = LOWORD (lPar

27、am) / DIVISIONS ; cyBlock = HIWORD (lParam) / DIVISIONS ; for (x = 0 ; x DIVISIONS ; x+) for (y = 0 ; y DIVISIONS ; y+) MoveWindow (hwndChildxy, x * cxBlock, y * cyBlock, cxBlock, cyBlock, TRUE) ; return 0 ; case WM_LBUTTONDOWN : MessageBeep (0) ; return 0 ; case WM_DESTROY : PostQuitMessage (0) ; r

28、eturn 0 ; return DefWindowProc (hwnd, message, wParam, lParam) ;LRESULT CALLBACK ChildWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) HDC hdc ; PAINTSTRUCT ps ; RECT rect ; switch (message) case WM_CREATE : SetWindowLong (hwnd, 0, 0) ; / on/off flag return 0 ; case WM_LBUTTONDOWN : SetWindowLong (hwnd, 0, 1 GetWindowLong (hwnd, 0) ; InvalidateRect (hwnd, NULL, FALSE) ; return 0 ; case WM_PAINT : hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; Rectangle (hdc, 0, 0, rect.right, rect.bottom) ; if (GetWindowLong (hw

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1