The division of cooperation between Class companies, the transfer of messages.

xiaoxiao2021-03-06  41

Now, with the CCursor class, with a CDESKTOP class, you have to consider their cooperation issues. First of all, my basic idea is to get the event information of the mouse from the CCursor class, passes the information of the button, the information of the pointer position to CDesktop, and CDESKTOP executes the specified command based on the corresponding message. CDESKTOP Save Desktop Data: Current Focus Window: A CWIN * Pointer, at the top window. Current Focus Control: A CWIN * pointer, the current activation window with a focus control. Current mouse pointer status: a BOOL type variable, representing it is normal, dragging (focus window follows mouse pointer moving). Drag and drop (window / control): A CWIN * pointer, when released the mouse, if the destinated target area is released in one window, pass the DragDrop message to the target window, the parameter is a pointer to the drag source. Drag and drop often applied to equipment, items, etc. Drag and drop the X offset, drag the y offset: int variable, the mouse pointer drags the window to the offset of the window Left, TOP. Used to update the window location. Double-click judgment problem: several modifications, the function to deal with the mouse buffer has been perfected. It can record the number of changes in the mouse button, and the offset of the z-axis, as well as the number of double clicks, the number of clicks, etc. Double-click because the maximum use is the left button double click, so only pay attention to the behavior of the left button. The processing function is as follows: // Test the data of the mouse buffer VOID CCURSOR :: getMouseData (mouse_event_struct * e) {if (! E) // invalid parameter return;

/ / Empty output MEMSET (E, 0, SIZEOF (Mouse_Event_struct));

DIDEVICEOBJECTDATA OD; HRESULT HR; DWORD DWCOUNT = 1; // Buffer Data Rock Static DWORD DWLASTDOWN = 0; // Press Time Static DWRASTDBLCLICD DWORD DWLASTDBLCLICK = 0; // Double-click DWORD DWNOWDOWN = 0; / / Press the time BOOL BDBLCLICKED = false; // Return to Double click

While (True) {dwcount = 1; // Get mouse buffer data hr = m_lpdimouse-> getDeviceData (Sizeof (DIDEVICEOBJECTDATA), & OD, & DWCOUNT, 0); if (hr == dierr_inputlost) {// mouse device is lost, restore And return M_LPDIMOUSE-> acquire (); Return;}

// Data acquisition failed, or the buffer has been acquired if ((FAILED (HR)) || (dwcount == 0)) Break;

// Processing buffer content switch (od.dwofs) {case DIMOFS_X: // X offset;

Case Dimofs_y: // Y Offset Break;

Case Dimofs_Z: // Z Off (Mouse Roller) E-> NMOUSEWHEEL = (Short) Od.dwdata; Break;

Case Dimofs_Button0: if (Od.dwdata & 0x80) {// Left button Press if (dwlastdown == 0) dwlastdown = od.dwtimestamp; else dwnowdown = od.dwtimestamp; e-> blbuttondown ;} else {// Left button release E-> brButtonup ;} Break; case Dimofs_Button1: if (od.dwdata & 0x80) {// Right click Press E-> BRBUTTONDOWN ;} else {// Right click E-> brbuttonup ;} Break;

/ / Check if there is double-clicking event, the time two clicks on the system setting valid double-click interval is considered valid double-click. If (dwnowdown) IF ((DwnowDown - dwlastdown) ndblclicked ; dwlastdown = 0 } Else if (dwnowdown - dwlastdown> m_dblclicktime) {// Timeout, reset time dwlastdown = dwnowdown;}

} // end while return;} where parameter E is a mouse_event_structure, which will return the result of this buffer data processing, which is used to pass CDESKTOP to handle the CDESKTOP to handle the mouse event with the pointer coordinates. This variable structure is as follows: static struct mouse_event_struct {bool dblclicked; // Valid double click (number of times) bool lbuttonup; // Left button once release BOOL RBUTTONUP; // Right button once release BOOL LBUTTONDOWN; // Left button once (single The number of times, click.) BOOL RBUTTONDOWN; / / Right button once pressed Int nmousewheel; // Roller offset};

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

New Post(0)