Dynamic dragging in Win98 Special Window Song Libo WIN98 None Topless Table Window is a special window, typical examples include IME input method applications, UCWIN platforms, various floating toolboxes, Office Desktop toolbars, etc. I. Command detection and cursor dynamic prompting such window drag generally divided into two: specific customer command areas and non-specific customer command areas. A particular customer command area refers to a specific sub-rectangular area defined by "Rect"; non-specific customer command area refers to a portion where the window customer area that is not explicitly defined, that is, the part other than all specific customer command zones. The primary problem that implements this feature is how to detect and process the mouse command in a particular customer command area and the non-specific customer command area, and how to use the mouse cursor to dynamically prompt the user to drag the operation of the window. 1. The specific customer command area detects the mouse command to set the icon command button to implement the drag function in the window, you must define the specific customer area of the command button in the resource file, which is generally the rectangular area of the command button icon, this The definition method of the area is "Rect DragRT", where DragRT is defined to detect the rectangular area of the mouse command, which uses DraGrt.LAGRT.TOP, DRAGRT.RIGT, DRAGRT.BOTTOM four parameters to describe the rectangular area relative to the window customer Relative coordinate values in the upper left corner of the area. You can also populate it with the "SETRECT" function. When the window function is processed the mouse message WM_LButtondown, when the system passed the mouse position parameter lParam, convert it to the window coordinate value via the makepoint () function, then determine whether a certain coordinate point is located in a specific rectangular area in the specific rectangular area. PtinRect ( ), Determine whether the mouse pointer is clicked within the drag command button. 2. Non-specific customer command area Detection Mouse Command When a non-specific customer command area dragging method is taken in the window application, the rectangular coordinates of each particular customer command area must be determined in advance in the resource file. At this time, the non-specific customer command area must be It is an irregular area that needs to be determined based on the actual application window and each command button rectangular area, that is, the "non" subset of each command button rectangular area relative to the window rectangular area. When the window function is processed by the mouse message WM_LButtondown, first use the function ptinRect () to determine whether the current mouse pointer is clicked in the rectangular area of each command button, if not clicked in any command button area, you can determine the mouse click in a non-specific customer command area. Internal, thus start the window drag function. 3, the cursor dynamic prompt of the window drag function Remove the mouse cursor shape before the mouse cursor dynamic prompt function, the dynamic prompt of the window drag function is generally four arrow patterns, which can take the SDK, FPT3.0 and The resource editor "image edit" in advanced development software such as VC 4.1 is implemented. The cursor resource file is typically 32x32 2 color or 16-color .cur graphic file. After establishing your own mouse cursor resource file, you first need to define the mouse cursor in the application's resource file, and then use LoadCursor () to transfer in the application and set it in the class: wc.hcursor = HCURM.
When the mouse cursor needs to perform dynamic prompts in the window's specific customer command button or in the non-specific customer command area, it is necessary to use the above definition method, and it is necessary to perform special processing when the window function is processed by the WM_MOUSEMOVE message: first determine the mouse cylinder pointer Whether the current location is dragging the command button or a non-specific customer command area, if the mouse pointer position meets the requirements of the drag window function area, use the API function setCursor () to change the mouse cursor pattern, prompting the user to drag the window. Operation, and turn the mouse input control to the current window, simultaneously set the changed mouse cursor mark; when the mouse pointer moves out the drag window command to start the area, restore the original mouse cursor pattern simultaneously release the mouse input focus control, and clear the mouse Cursor Dynamic Tips Marking Unit. Second, the key issue before the dynamic drag box is dragging the key problem is that the drag box display and the erase function are implemented in the mouse drag window. Window Drag Maxet is the wire frame that is dragged window size in the entire screen area of Windows. Its size needs to be determined based on the rectangular area size and actual needs according to the drag window, generally the rectangle of the drag window. Regional size. The drawing method in the Windows system is implemented by displaying the device description table, the drawing operation needs to take a certain GDI resource. The GDI resources in Windows 95 are much larger than the GDI resources in Windows3.x, so the system can assign enough GDI resources for windows, menus, dialogs, fonts, and various drawing functions. There are two ways to use the display device descriptor table in Windows: Update the window displays the client area and the direct operation window to display the customer area. Update Window Display Customer Area is Direct to the application window rectangle area, using a graphic operation command when the window function responds to the WM_PAINT message: InvalIDateRect (hwnd, & winRect, true); // WinRect To update the area UpdateWindow (hWnd); Window initial establishment time default to update all areas, when the rectangular area to be updated is NULL, the update window all rectangular areas. Function updateWindow () Notification System Sends a WM_PAINT message to the window to update the rectangular area, and the window function receives the WM_PAINT message first use the beginpaint () function to obtain the device descriptor table, then use the graphic command to update the display device directly, and finally Endpaint () function notification system update operation ends. Update Window Rectangular Area Directly Using the Screen Demand Defined in the Window Class, even if you use the SelectObject () function to select the corresponding screen painting brush, the update rectangular area range is accumulated by the invalidateRect () function, by UpdateWindow () function notification system Start a window update operation. The entire process is scheduled by the system, so the use of this method cannot realize the window of the window to draw and real-time operation. The method of direct operation window customer area is to use the getDc () function to acquire the display device handle, and draw the display device directly with various graphical operation commands. It uses the screen's currently setup brush and brush to implement various graphics drawing operations, which can be updated and drawing the screen window in real time without passing any message application to the system. Its operational process is first acquired a display device descriptor handle HDC = GETDC (HWnd), when the HWND parameter is NULL, the device descriptor table handle is obtained throughout the screen, and then use the selectobject () function to set the current screen brush and painting brush. , Use various drawing functions to complete the drawing operation of the screen, and finally use the ReleaseDC () function to release the acquired device description table.
If you use the painting rectangular function Rectangle () to implement the virtual box, you must use SelectObject (HDC, getStockObject (null_brush) while setting the current screen brush, otherwise the Windows program will quickly swallow all GDI resources. It is equivalent to adding countless rectangular areas in the screen device resources. For the erase operation of the window drag box, simply set the graphical brush operation of the screen to R2_xorpen in the drag box to draw a function, ie setrop2 (HDC2, R2_xorpen). At the end of the drag box, pay attention to recovery, before the window drag box moves to the next position, reuse the drawing function at the original screen position once (see program 1). // Use the painting rectangular function to drag the real frame (due to the sect line, the drawpoint function omitted) VOID DRAWMOVERECT (INT XX1, INT YY1, INT XX2, INT YY2, INT XY) {HDC HDC; Int Oldrop2, M, K HDC = getdc (null); // acquire full screen device Description Handle Oldrop2 = GETROP2 (HDC); // Get the original screen drawing mode SETROP2 (HDC, R2_Xorpen); // Setting the same or screen drawing SelectObject (HDC, getStockObject) (NULL_BRUSH)); // Shielded SelectObject (HDC2, GetStockObject (White_pen)); // Select Brush for (k = 0; KXX1- = 1; XX2 = 1;
YY1- = 1; YY2 = 1; Rectangle (HDC2, XX1, YY1, XX2, YY2);} SETROP2 (HDC2, OLDROP2); // Restore the original mapping method ReleaseDC (NULL, HDC2); // Release device descriptor Table} (Procedure 1) Third, the Dynamic Drain window "Three Steps" completed the judgment of the client area of the Windows Advanced window, the mouse cursor dynamic prompt and custom window dragbox function of the Windows Advanced window, need to Implement the three-step process of the drag process start, window drag frame movement, and drag end processing throughout the drag program. The WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_LBUTTONUP messages must be processed directly in the window function. The following three steps in the above three steps are handled. The first step is to determine the mouse click on the message WM_LBUTTONDOWN in the window function to process the user when obtaining the window drag condition by the mouse cursor dynamic prompt function, press the start drag process message generated by the left mouse button. Its functional code is as follows: Case WM_LButtondown: Pt = makepoint (LPARAM); IF (PtinRect (& DragRT, PT)) {Dragbegin ((LPRECT) & WinRT, LPARAM, HWND, 2); // Startup Procedure} else {// Other processing;} The above Dragbegin () function drags the startup function for the window developed by the author. Since there are often many windows in a advanced window application, it is handled as a single function. Where WinRT is a high-grade window rectangular area, here as the drag frame rectangular area parameter, LPARAM is the mouse spectrum pin long integer, HWnd is the handle of the current drag window, 2 is the drag frame width. At this time, you need to pass the mouse control to the currently drag window, set the drag window flag unit, save the current mouse on the screen and display the dragbum of the drag window. The source code of the drag function start function is as follows: Void Dragbegin (LPRECT WinRect, / / Drag) Rectangular Area LParam LPARAM, // Mouse Cursor Current Pointer HWND HWND, // Current Window Handle Unsigned INT KK) // Drag Box Displayed width {setcapture (hwnd); / / When the window must have a mouse input moveflag = true; // Set the drag flag Oldmx = loword (lparam); // Record the current mouse screen coordinate XOldmy = Hiword (lParam ); // Record the current mouse screen coordinate Y DrawMovecture (WinRect-> LEFT, WinRect-> Top, // Display Drag Box WinRect-> Right, WinRect-> Bottom, KK);} The second step, you need to handle mouse drag The drag block movement during the window, this requires WM_MOUSEMOVE message processing in the window function. The movement of the drag box includes the last display of the drag box and two steps of the display of this drag box. Since the current drawing method is reset, the current drawing function is reset, the change can be called once in the original screen coordinate position, so that the drag box can be cleared at the time of the original screen coordinate position. Therefore, display during the mouse drag window movement. And clear the drag box only needs to call two drag box draw functions. In addition, the calculation method of the drag frame on the screen is also very simple, that is, the currently acquired screen position coordinate value subtracts the previous screen position coordinate value to move the offset, and then use the original window screen to the upper corner coordinate The value is added to the offset, you can determine the new screen position coordinate value of the drag window and the drag box.
Case WM_MouseMove: IF (MoveFlag == True) {Dragmove ((LPRECT) & WinRT, WINWT, WINHI, LPARAM, 2);} else {// Other processing;} In view of the advanced window application is generally multiple sub-windows, The drag block movement process is individually prepared, and the window cannot be fully handled in the screen during the disc mouse drag window. Developers can adjust their position as needed so that the window being dragged can be completely displayed in the screen visual area. Its drag process function source code section is as follows: Void Dragmove (LPRECT RCWIN, / / Drag) Rectangular area Unsigned Int Wi, // Drag Window Width Unsigned Int Hi, // Drake Window Height LParam LParam, // Mouse position pointer unsigned int kk) // Drag Border Border Width {DrawMoveRect (rcwin-> left, rcwin-> top, rcwin-> right, rcwin-> bottom, kk); // Clear the last draw drag box RCWIN -> Left = loword (lparam) -simeg.oldmx; // calculate window RCWIN-> TOP = HiWord (lparam) -simeg.oldmy; // New location Simeg.OLDMX = LOWORD (LPARAM); // Save the current coordinate value Simeg.OLDMY = HiWord (LPARAM); if (rcwin-> left <0) rcwin-> left = 0; // Passing the window Beyond the screen if (rcwin-> left> Simeg.xscrwi-Wi) // Visual area processing RcWin-> Left = Simeg.xscrwi-Wi; II = SIMEG.YSCRHI-Hi- (Simeg.winver <0x35f? 0: botoff); if (rcwin-> top <0) rcwin-> TOP = 0; // Win95 performs bottom IF (rcwin-> TOP> II) rcwin-> top = II; // Special retention processing RCWIN-> Right = rcwin-> Left Wi-1; rcwin-> bottom = rcwin-> TOP HI- 1; DrawMoveRect (rcwin-> left, rcwin-> top, rcwin-> right, rcwin-> Bottom, KK); // Drawing location Drag Box} The third step is required at the end of the mouse Drag window. The actual movement process, which requires the actual movement when processing the WM_LBUTTONUP message. Similarly, in view of multi-window reasons, this processing will still be used alone a function, and you need to use the drawing function to clear the drag box on the screen before the mobile window. If the window is not fully located visible location, it is also necessary to appropriately adjust the dragged window to be fully located in the screen visual area, and release the mouse control and clear the drag window flag unit.