Bug sharing-failed to receive wm_nclbuttonup messages

Source: Internet
Author: User

In Windows, the ncarea overload is a dead path from the title bar of the painting window (in Vista, if the theme has a frosted glass effect, no matter how self-painted your window title bar, will overwrite the title bar of the system on the Self-painted title bar), so the only way to self-painted title bar is to simulate non-customer areas in the customer area, "forged" to achieve the title bar function. Some of my articles are incorrect. The purpose of this article is only to describe a problem that has been encountered before.

Nclbuttonup indicates non-client left button up. the left mouse button of the non-customer area (that is, the title bar and Border Area) of the window is clicked to release the message.

 

Trademanager's webpage plug-in is a common window with an embedded IE control in an independent process. In order to make the window style as consistent as trademanager's, therefore, I have re-painted the title bar and the Minimize button of the window. (another way is to simply remove the title bar,

Directly create the title bar in the customer area ).

 

The Minimization button is used to respond to the wm_nclbuttonup message. When the message is received and the mouse is inside the minimization icon, the window is minimized.

 

Today, my colleague found that it was not very clever to click the Minimize button in the window of the webpage plug-in. I looked for the reason and found that after clicking the left mouse button on the title bar, I could receive the message wm_nclbuttondown (pressed), but it may not necessarily receive wm_nclbuttonup

To release the left-click message ). Google once found that Windows does have this problem (msdn does not explain it at all ). When you click the left mouse button in a non-customer area and release it, the system will send wm_lbuttonup in the window (note that it is not wm_nclbuttonup, This is the mouse release message in the customer area, but now we release the mouse in the non-customer zone! The process of sending a message to the thread's message queue, but the thread's Message Queue does not send the message to the window!

 

Since the window is not sent, how did my buddy find it? He found the messages through spy ++. (because spy ++ captures the window by using the Hook method, the hook is also used in my code to process ie hotkeys,

However, due to carelessness, callnexthookex was not called for all the messages, so that when I used spy ++ to view the messages, I didn't have this guy, so I was half-dead and was framed by tools, developer (because spy ++ is also a hook, because this message is monopolized by my hook, and it cannot be hooked, so the wm_lbuttonup message is invisible ).

 

The basic principle of the solution is to send a wm_nclbuttonup message to the window after you press the left mouse button in a non-customer zone to release the message.

Therefore, the core issue to be solved is: how to determine whether the current left mouse button is pressed in a non-customer zone and released (if the window process receives wm_nclbuttondown, and wm_lbuttonup is found in the callback function of the message hook, which indicates

The current mouse is pressed in a non-customer zone and released. At this time, the message wm_nclbuttonup is forged)

 

The solution is as follows:

1. In response to the message wm_nclbuttondown in a non-customer zone, define a flag, m_bnclbuttondowned = true; indicates that the left mouse button is pressed in the non-customer zone.

2. use the hook of wh_getmessage to hook the message queue of the entire thread to obtain the wm_lbuttonup message when the mouse is released in a non-customer zone (because spy ++ is in this way, therefore, we can also adopt this method. Of course, the buddy in Google uses the mouse hook, which is more complicated)

3. The wm_lbuttonup message in the hook callback function determines the current m_bnclbuttondowned = true? Whether the left mouse button is pressed in the non-customer area. If yes, a wm_nclbuttonup message will be sent to the non-customer area.

The process of releasing a message from the mouse to the window

4. In the wm_nclbuttonup processing function in the window process, determine m_bnclbuttondowned = true? If yes, the code is executed and m_bnclbuttondowned is set to indicate that the left mouse button has been released, so the left mouse button has not been pressed.

 

The system tested by the predecessors will send the wm_nclbuttonup time:

1. Double-click the title bar

2. Press and hold the left mouse button in the customer area, but release the left mouse button in the non-customer area.

 

 

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.