Automatic hide (C code)
Recently write a small program, want the form to automatically hide, to 9CBS search, find that many netizens ask this question, but the specific implementation is not much, I have been pondered, realize the recordable position, can be left on the left and right tripartite to stop and hide . Examples will be implemented for your reference. There are many types of automatic hidden methods to implement, which can be used to monitor the mouse when the mouse moves to the edge of the form, and the form is hidden when the mouse is left behind. You can also activate the form when you receive WM_NCMOUSEMOVE or WM_MOUSEMOVE (boundless form), and then set display or hide in the form message WM_ACTIVE, which is not hidden when the form is not lost. I use this method in the original design, just find that the non-main form is not appropriate, and two keyboard focus will appear when the form is activated, and the focus I need is false, maybe my design Improper, if a friend is perfect, you may wish to communicate. The process of this code is as follows: 1. Set the form position when the form is initialized, and sets the status form state. 2. When receiving the WM_MOUSEMOVE message, check if the form is displayed, if, display, and open the timer. 3. Detect the form position in WM_MOVing and automatically close the boundary. 4. Detect the mouse in the timer, turn off the timer and hide the form after the mouse leaves the form. Of course, when you hide the form, it is first judged, and if it stops on the edge, hide, otherwise, it is not hidden. Now let's take a step in step. INT aligntype; // global variable, used to record formal stop state enum {align_none, // does not stop align_top, // Stop Align_LIFT, // Stop left align_right // stop right}; # define near_size 20 // Definition Auto Stop the valid distance #define near_side 2 // The pixel retained on the screen so that the mouse can touch / * below the code processing form message WM_MOVING, prect is the pointer from the parameter lParam * / void onmoving (hwnd " HWnd, LPRECT prect) {// unlike boundary by prect test if (alignty == align_none) {if (prect-> TOP
{Aligntype = align_right; prect-> left = (Screenx - prect-> right); prect-> right = screenx;}} else {// Boundary by the mouse to test POINT PT; getCursorpos (& PT); if (aligntype = = Align_top) {if (pt.y> Near_size) // Due to our mobile form, the mouse is in the title bar, and when the mouse position exceeds the effective distance, we can consider the user to drag the mouse down. We will relieve the upper stop. {Aligntype = align_none; prect-> bottom = ner_size; prect-> top = near_size;} else {prect-> bottom - = prect-> top; prect-> TOP = 0; if (prect-> left
} F (alignty == align_left) {if (pt.x - prect-> Right> 0) // The mouse can be moved back and forth throughout the title strip, so we cannot use the left boundary and the distance to be released, here us The dock is released when the mouse leaves the right boundary. {Aligntype = align_none; prect-> Right = ner_size; prect-> left = ner_size;} else {prect-> right - = prect-> left; prect-> left = 0; if (prect-> TOP {Prect-> bottom - = prect-> top; prect-> TOP = 0;}}}}} / * In the form initialization is a set form state, if you can stop, stop in the edge, I want to seek other The method is to solve the initialization, not for it to seek a function, but do not send a WM_MOVING message when the form is initialized, I have to repeat similar tasks. * / Void nearside (hwnd hwnd) {int change = 0; Rect Rect; GetWindowRect (hWnd, & rect); alignType = ALIGN_NONE; if (rect.left // How to move the form below, determine the Switch (AlignType) {case align_top: {// Motion xStep = 0; XEND = rc.left; if (hide) {ystep = -rc.bottom / Moves; Yend = -Height Near_SIDE;} else {ystep = -rc.top / move; yend = 0;} Break;} case align_left: {// Move YSTEP = 0 to left; Yend = rc.top; if (hide) {xstep = -rc.right / move; xend = -width ner_side;} else {xstep = -rc.Left / move; xend = 0;} Break;} case align_right: {// Mimted YESTEP = 0; Yend = rc.top; if (hide) {xstep = (Screenx - rc.left) / Moves; XEND = Screenx - Near_SIDE;} else {xstep = (Screenx - r.right) / Moves; Xend = Screenx - width;} Break;} // animation scroll form. For (i = 0; i