Win32 SDK - captures the mouse to leave and rearwate incidents

zhaozj2021-02-17  53

Equity of articles: primary

First you first understand the TrackMouseEvent function;

This function delivers messages when the mouse pointer leaves or in a specific time is hovering (retention) in the form. The parameter points to the TRACKMOUSEEVENT structure. (Detailed definition and explanation, please check the MSDN document)

Typedef struct tagtrackmouseevent {

DWORD CBSIZE; // TRACKMOUSEEVENT SIZE.

DWORD dwflags; // specifies the service request.

HWND HWNDTRACK; // Specifies a Handle to the window to track.

DWORD DWHOVERTIME; // Hover Time-Out.

TRACKMOUSEEVENT, * LPTRACKMOUSEEVENT;

The following is the original code: (Note To join ComctL32.lib) in the import library of the link in the property page

// filename: mouseelevel.c

#include #include // must import this header file

#ifndef app_name # define app_name text ("My Mousehover Test") # ENDIF

Const int successde = 0;

Atom RegisterformClass (Hinstance); Bool InitInstance (Hinstance, Int); LRESULT CALLBACK WNDPROC (HWND, UINT, WPARAM, LPARAM)

int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow) {MSG msg; RegisterFormClass (hInstance); if (InitInstance (hInstance, iCmdShow)!) return FALSE; while (GetMessage (& msg, NULL, 0,0) ) {TranslateMessage (& MSG); DispatchMessage (& MSG);} Return succeed;

ATOM RegisterFormClass (HINSTANCE hInstance) {WNDCLASSEX wcex; wcex.cbSize = sizeof (WNDCLASSEX); wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wcex.hCursor = LoadCursor (NULL , IDC_ARROW); wcex.hIcon = LoadIcon (hInstance, IDI_APPLICATION); wcex.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wcex.hInstance = hInstance; wcex.lpfnWndProc = WndProc; wcex.lpszClassName = APP_NAME; wcex.lpszMenuName = NULL; Wcex.style = CS_HREDRAW | CS_VREDREDRAW; RETURN RegisterClassex (& WCEX);

BOOL InitInstance (HINSTANCE hInstance, int iCmdShow) {HWND hWnd; hWnd = CreateWindowEx (WS_EX_APPWINDOW, APP_NAME, APP_NAME, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if (! HWnd) return FALSE; ShowWindow (hWnd, iCmdShow); UpdateWindow (hWnd); return TRUE;} LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {switch (uMsg) {case WM_MOUSELEAVE: MessageBox (hWnd, TEXT ( "MouseLeave! "), Text (" MouseEleave "), 0); Break; Case WM_Mousehover: MessageBox (Hwnd, Text (" Mousehover "), Text (" Mousehover "), 0); Break; Case WM_NCMouseLeave: MessageBox (hwnd, text "MouseNClient!"), Text ("Mousenclient!"), 0); Break; Case WM_MouseMove: // Because TRACKMOUSEEvent only sends a message, and invisible as other messages, the function is called in this message.

TRACKMOUSEEVENT trmouse; trmouse.cbSize = sizeof (TRACKMOUSEEVENT); trmouse.dwFlags = TME_LEAVE | TME_HOVER | TME_NONCLIENT; trmouse.dwHoverTime = 2000; trmouse.hwndTrack = hWnd; if (_ TrackMouseEvent (& trmouse)!) Return FALSE; break; case WM_DESTROY: PostquitMessage (0); Break; Default: Return DefWindowProc (HWND, UMSG, WPARAM, LPARAM); Break;} Return succeed;

// This file is written in pure Win32 SDK, does not require MFC and other support. Can be compiled in DOS mode. Under Windows98, 200, VC6, VC7 beta2 is compiled and executed correctly.

转载请注明原文地址:https://www.9cbs.com/read-29836.html

New Post(0)