The window appears at the top of the screen and automatically hides

Source: Internet
Author: User
the window must always dock at the top of the screen window hides after mouse leaves window API InterfaceBOOL SSWINAUTOHIDEWORKB (HWND hwnd, UINT_PTR Utimerid = 0); BOOL Sswinautohideworke (HWND hwnd); Implementation Technology1. In function sswinautohideworkb, call g/setwindowlongptr to hook the window process so that the message of the window goes through our own callback function. 2. Window display hidden animation effects need to be done in another thread, so you can not affect the interface response. 3. Control window behavior requires some variables to connect with the window, at the same time, in order to support the control of multiple Windows does not affect each other, we cannot use global variables, where we use SetProp to associate these variables with a particular window, so that the window handle can be taken out of the variable associated with it. 4. Monitor the mouse into the left window because you have already hook the window process, so only need to check the message wm_mousemove, Wm_ncmousemove, you can know whether the mouse entered the window, and the monitor window left the main window There are two different ways A) set a timer, monitor the mouse into the window when the timer does not run to start, the timer will be separated for a period of time (100ms?) To detect the current mouse and window position, if detected the mouse left the window, stop the timer, dynamic hidden window. B use Wm_mouseleave,wm_ncmouseleave message to monitor whether the mouse leaves the window there is a little bit of complexity here, the Wm_ncmouseleave message system will automatically send to our hook window process, wm_ MouseLeave requires us to invoke the TrackMouseEvent function to trigger it, and after receiving a wm_mouseleave message, we have to call this function again to make it easier to receive again. We have to detect the location of the mouse again when we receive the mouse to leave the message. Because it is possible to receive wm_ncmouseleave (this means that the mouse left the NC part of the window), but in fact the window is only moved to the customer area, at this time we can not simply hide the window. There is also a problem, if we monitor the window has a child window, when the mouse from the monitor window moved to its child window, the monitored window will also receive the Wm_mouselveave message, this time we can compute the query mouse position to know that the mouse moved to the child window, But we do not know when the mouse will leave the child window, you can call the TrackMouseEvent function to monitor the mouse left the child window message, but this departure message will not be sent to the window of our hook process, because the window process is only the window of the monitor window process rather than its child window, I only think of a way to solve, this is the case, and then hook the mouse in the window of the child window process, after the mouse moved out of the child window unhook. 5. In order to keep the window always docked at the top of the screen, can only drag left and right to drag up and down, we can in the hook window process to manipulate the message wm_windowposchanging to achieve. 6.wm_entersizemove and Wm_exitsizemove message intervals, which represent the window being dragged, do not attempt to determine whether the mouse is in the window and the clever hiding/ Displays the window. The solution I have taken is to determine whether to hide a window after the user stops dragging to determine the position of the mouse and the window. 7. Judge the mouse is in the window of the client or NC area, do not use the GetClientRect to compare the mouse position, because it is possible not to monitor the window is That is, in the client area to implement the title bar, this time to use the following code to determine the Lmouse_pos Lmouseinwindow (HWND hwnd) {    point ptcursor ={0};     ::getcursorpos (&ptcursor);     rect Rtwnd = {0};     ::getwindowrect (HWnd, &rtwnd);     if (!::P tinrect (&rtwnd, ptcursor))          return mpos_none;     uint uhittest = (UINT):: SendMessage (hWnd, wm_nchittest, 0, Makelparam (ptcursor.x, PTCURSOR.Y) );     if (uhittest = = htclient)         return MPOS_C;     if (uhittest = = htnowhere)         return MPOS_C;     return MPOS_NC; Send a message wm_nchittest, if the window tries to deceive the system, then deceive us well ... 8. About the display, hide the window animation. In Sswinautohideworkb, a thread is started and the thread starts to wait for three events with Waitformultiobjects, one for the exit event, one for the Dynamic Display window event, and one for the Dynamic hidden window event. So if we want to do these three actions, we just need to trigger the response event. 9. Some time the window hides/displays, especially when the display flashes the departure, especially when the window is the drawing window, this time may consider the wm_erasebackground message in the painting window to return directly to try to solve.    source Code:http://download.csdn.net/detail/patdz/4279573
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.