Automatic hide (C code)

zhaozj2021-02-16  53

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 bottom - = prect-> top; prect-> TOP = 0;} if (prect-> left Right - = prect-> left; prect-> left = 0;} else if (prect-> Right Near_Size> Screenx) // In the right side, Screenx is the screen width, which can be obtained from GetSystemMetrics (SM_CYSCREEN).

{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 right - = prect-> left; prect-> left = 0;} else if (prect-> right near_size> screenx) {prect-> left = (Screenx - prect-> Right); prect- > right = screenx;}}

} 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 bottom - = prect-> top; prect-> TOP = 0;}}} else if (alignype == align_right) {if (pt.x left) // When the mouse leaves the left boundary , Release. {Aligntype = align_none; prect-> left - = Near_Size; prect-> right - = ner_size;} else {prect-> left = (Screenx - prect-> right); prect-> right = screenx; 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 Screenx - Near_Size) {alignype = align_right; if (Rect.right! = Screenx && Rect.Light! = Screenx - Near_side) {RECT .leenx - Rect.right); Rect.right = Screenx; Change = 1;}} // Adjusts ELSE IF (Rect.top

// 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

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

New Post(0)