Customer region dragging Technology and Its Application in WINDOWS Advanced window

Source: Internet
Author: User

WINDOWS application WINDOWS generally have two types of window: normal window and normal top-level untitled window. The former is customized by WINDOWS internal functions and has all the common features of WINDOWS application WINDOWS: the title bar, window border, maximize button, minimize button, system default shortcut keys, and mouse support functions are available. You can move the title bar of the window on the screen by dragging the left mouse button, you can change the window size when you move the cursor over the window border. The latter is a custom advanced window that does not have any attributes of a common window, the control of the entire window must be determined by the programmer one by one, typical examples of using this window include windows ime Input Method Application, UCWIN4.0 platform, various floating toolbox, desktop toolbar in OFFICE, and third-party Chinese Character Input platform.

WINDOWS is a prominent feature of the Untitled top-level advanced window. It does not need to change the window size but must have the client area drag function of the window. Since the drag function of a common window is completed by the system, it is difficult for programmers to compile common applications based on the drag problem of the customer region, let alone how to implement this function. Developers often want their own software to have the window client area drag function in the classic software, I used to imitate the system mouse to click the title bar to drag the window and the API provided by the WINDOWS system to send the internal drag command to achieve the customer drag function without the title of the top-level advanced window, the results are not ideal. Later, we had to directly process WM_LBUTTONDOWN, WM_MOUSEMOVE, and WM_LBUTTONUP messages in the window function, you can control the customer's command area, start, move, draw, move, and end of the virtual box that you want to drag the window by yourself to implement the customer area drag scheme of the advanced top-level window. The following describes in detail the methods and main skills for implementing the solution based on your practical experience.

1. Implementation of WINDOWS client drag command and mouse and cursor dynamic prompt

In WINDOWS, the customer regions with Untitled entries that normally reside in the top-level advanced window are generally divided into two types: the specific customer command region and the non-specific customer command region. The specific customer command area refers to the exclusive rectangular area defined by "RECT". The window function detects and processes the mouse commands in the area; the non-specific customer command area refers to the customer area of the window that is not clearly defined, that is, all the parts outside the specific customer command area, the window function determines whether to process mouse commands in the region based on actual needs. How to detect and process mouse commands in the command area of a specific customer and in the command area of a non-specific customer, and how to use the mouse cursor to dynamically prompt users to drag the window at this time.

1. How to detect mouse commands in specific customer regions

When you 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, this area is generally the rectangular area of the mark in the display command button. The definition of this area is "RECT DragRT", where DragRT is the defined rectangular area of the detection mouse command. It uses DragRT. LEFT, DragRT. TOP, DragRT. RIGHT and DragRT. the four BOTTOM parameters describe the relative coordinate value of the rectangular area relative to the upper left corner of the window client area. These four parameters must be defined in advance, or can be directly filled with the "SETRECT" function.

When processing the mouse message WM_LBUTTONDOWN, the window function converts the mouse position parameter lParam received by the system to the window coordinate value through the MAKEPOINT () function, you can use the PtInRect () function to determine whether a coordinate point is located in a specific area of a rectangle to determine whether the mouse pointer is clicked within the drag command button to complete the start task of the window drag function. Its descriptive function code example is as follows:

Case WM_LBUTTONDOWN: // handle the cursor

POINT pt; // pointer of the mouse over the screen, which includes two parameters: pt. X and pt. Y,

// This pointer value is converted using MAKEPOINT through the lParam Parameter

Pt = MAKEPOINT (lParam); // get the pointer to the current mouse position on the screen

If (PtInRect (& DragRT, pt) {// determines whether the mouse is clicked inside the drag button

// Enable the mouse drag window scheme

} Else {

// Judge and process other specific or non-specific command regions

}

Break;

2. How to detect mouse commands in non-specific customer regions

When the Window application adopts the non-specific customer region drag method, the rectangular coordinates of each specific customer region must be determined in advance in the resource file. In this case, the non-specific customer region is an irregular region, it depends on the actual application window and the rectangular area of each command button, that is, the "Non" subset of each command button relative to the window rectangle area. When processing the mouse message WM_LBUTTONDOWN, the window function first uses the PtInRect () function to determine whether the current mouse pointer is clicked in the rectangle of each command button. If it is not clicked in any command button area, you can click the mouse in a non-specific customer area to start the window dragging function. Its descriptive function code example is as follows:

Case WM_LBUTTONDOWN: // handle the cursor

POINT pt; // defines the pointer of the mouse over the screen

Pt = MAKEPOINT (lParam); // get the pointer to the current position of the mouse cursor

For (I = 0; I

If (PtInRect (& DragRT [I], pt) {// DragRT [I] is an array of Button rectangles.

Break; // click another button to interrupt

}

}

If (I

// Click other buttons in a specific customer area.

} Else {

// Click the mouse in a non-customer area to start the window dragging scheme.

}

Break;

3. Mouse and cursor dynamic prompt method for window dragging

In the top-level advanced Window application without a title bar, you can use a specific customer area as the method to drag the command button, you can also use the method of dragging commands in the detection window of a non-specific customer area, or use both methods. When using the first method, you can use a specific icon or text in the command button to prompt you about the function of the command button, in the latter method, the icon or text cannot be displayed in the rectangular area, or the icon and text cannot be displayed at all (for example, the unspecified customer area is the window boundary area ), the user cannot know that the non-specific customer region has the drag window function. At this time, only the dynamic prompt function of the mouse and cursor can be fully utilized, this function is very important in the design of the advanced window interface, just as the mouse cursor changes to the Double arrow shape when the mouse cursor stops on the window border.

Before implementing the mouse and cursor dynamic prompt function, you need to customize the mouse and cursor shape. The window dragging function dynamically prompts that the cursor shape is generally a four arrow pattern, this can be achieved by using the resource editor "image edit" in Microsoft sdks, FPT3.0, VC ++ 4.1, and other advanced development software. The cursor resource file is generally a 32x32 2 or 16 color. the CUR graphic file can be used to determine the cursor pattern based on the implemented functions or directly use the cursor resource file provided by the WINDOWS system. After drawing the cursor pattern using the resource editor, you also need to use DEBUG. the EXE program modifies the mouse cursor in the cursor resource file to display the offset coordinates, so that the cursor pattern can be like the dynamic prompt cursor in WINDOWS system, dynamic prompt Time Label pattern center is in the current position of the screen. The offset coordinate value is in the double-byte position at 10 and 12 in the resource file. If the cursor resource file name is dynamically prompted as MOUSEM. CUR: to make the center point of a 32X32 (2 color) cursor chart appear in the current screen position, the modification method is as follows:

C> debug mousem. CUR

-E 10A

XXXX: 10A 00.10 00.00 00.10 00.00

-W

After creating your own mouse cursor resource file, you must first define the mouse cursor in the application's resource file. The definition method in the resource file is:

Imecurm CURSOR mousem. cur

You can use the LoadCursor () function to call the mouse cursor resource file to the memory only after it is defined. The call method is as follows:

HCURSOR hCurm; // transfers the cursor resource file data to the memory.

HCurm = LoadCursor (hInstance, "imecurm ");

When the customer area that needs to dynamically change the mouse cursor shape is the entire window or all customer areas of a subwindow, the corresponding mouse cursor resource handle is defined when registering the customer application window class, when the mouse cursor moves to the corresponding window, it immediately becomes a custom cursor shape. When the corresponding window is removed, the original cursor shape is automatically restored. The method for defining the dynamic prompt function of mouse and cursor is as follows:

Wc. hCursor = hCurm;

When the mouse cursor needs to be dynamically prompted in a specific customer command button area of the window or in a non-specific customer command area, the above definition method cannot be used, special processing must be performed when the window function processes the WM_MOUSEMOVE message: first, determine whether the current position of the mouse pointer is being moved in the drag command button or non-specific customer area, if the cursor position meets the requirements of the function area of the window to be dragged, the API function SETCURSOR () is used to change the mouse cursor pattern, prompting you to drag the window at this time, the mouse input control is handed over to the current window, And the mouse cursor flag is changed. When the mouse pointer is removed from the drag window and the command area is started, the original mouse cursor pattern is restored and the control of the mouse input focus is released, and clear the mouse and cursor dynamic prompt cell. The functional code is described as follows:

BOOL DragFlag; // a dynamic cursor flag

Case WM_MOUSEMOVE: // move the cursor

Pt = MAKEPOINT (lParam); // pointer to the current position of the mouse cursor

If (PtInRect (& DragRT, pt) {// when the mouse pointer is in the drag command area

SetCursor (hCurm); // dynamically changes the mouse cursor shape

SetCapture (hWnd); // control the mouse input to the current window

IFlag = TRUE; // set the mouse cursor shape change flag

} Else if (iFlag = TRUE) {// The mouse pointer is not in the drag Command Area

SetCursor (LoadCursor (NULL, IDC_ARROW); // restore the original shape

ReleaseCapture () // release control of mouse input

IFlag = FALSE; // restore the mouse cursor shape change flag

}

Break;

Ii. How to customize the drag box in WINDOWS Advanced window dragging Scheme

The preceding section describes how to use the mouse cursor dynamic prompt function to detect the cursor position before the window is dragged and the drag function in the Client Command area. When you use the mouse cursor dynamic prompt function to meet the conditions of the drag window, click the left mouse button to start the drag scheme. The most critical technical problem is the implementation of the drag box display and erase function during the move of the mouse drag window. The dotted box for dragging a window is a box that describes the size of the dragged window displayed in the entire WINDOWS screen area. The size of the dotted box depends on the size of the rectangular area and actual needs of the dragged window.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.