Next, we will discuss how to create an inactive window similar to the input method window"

Source: Internet
Author: User

The previous two days, I saw my blog "Creating a non-active window similar to the input method window". I thought the content was good. I decided to try it and found it defective, now, I will assign my testing process to you (vb2005 is used in this article) to share with you.

According to the first method of the blog post, form1 is created, the createparams attribute of form1 is rewritten, and formborderstyle is set to system. Windows. Forms. formborderstyle. None.

Protected overrides readonly PropertyCreateparams ()AsCreateparams
Get
DimTCAsCreateparams =Mybase. Createparams

TC. exstyle = tc. exstyleOr& H8000000

ReturnTC

End get

End Property

The test is good. It is compared with the opened "Notepad". When I click form1, the cursor is still in "Notepad.

Then, create a new form2 and change it to the startup window. The textbox1 control is added above. In the double-click event of the control, start form1.

Private subTextboxshortdoubleclick (ByvalSenderAs object,ByvalEAsSystem. eventargs)HandlesTextbox1.doubleclick

Form1.show ()
End sub

As expected, when you double-click the text box, form1 is displayed, and the cursor is still in the text box.

No, the cursor is lost, the text box is out of focus, and the focus is on form1 (this is confirmed after the formborderstyle of form1 is set to system. Windows. Forms. formborderstyle. fixedtoolwindow. The focus is indeed moved to form1)

Later I thought about whether it would be better to force the focus to be switched back after form1 is started.CodeChange

Private subTextboxshortdoubleclick (ByvalSenderAs object,ByvalEAsSystem. eventargs)HandlesTextbox1.doubleclick

Form1.show ()

Me. Activate ()
End sub

After form1 is started, the cursor is indeed in the text box, but after you click form1, the cursor is gone and the focus is on form1. "Cup.

It seems that a singleProgramThere are two forms (or more than two forms) in, this effect is achieved.

Later, I checked that the meaning of "& h8000000" is ws_disabled, and I didn't fully understand what it meant.

Later, I found an article on the Internet.ArticleThe entire article is in English and I haven't looked at it carefully. I tested the code and it was successful. URL:

Http://www.yortondotnet.com/2006/11/on-screen-keyboards.html

In his code, a wndproc code for modifying the form is added to intercept the wm_mouseactivate message and change it to ma_noactivate.

The Code is as follows:

Private constWm_mouseactivateAs integer= & H21

Private constMa_noactivateAs integer= & H3

 

Protected overrides subWndproc (ByrefMAsSystem. Windows. Forms. Message)
IfM. MSG = wm_mouseactivateThen
M. Result = ma_noactivate
Else

Mybase. Wndproc (m)

End if

End sub

After testing, the effect was finally achieved. Start form1 and move the cursor in the text box. No matter how you click form1, the light mark has never changed.

The above generation is valid, and even the code for rewriting createparams at the beginning is still valid.

 

After a number of tests, we found that the above Code is effective. to succeed, it is also essential that the form does not have a control (such as button and textbox) that can accept the focus ), you cannot have a title bar. The solution is to remove the Form title bar and disable the control that accepts the focus (or rewrite the wndproc process of the control, intercept the message that accepts the focus, so that it cannot accept the focus ). Although form does not accept focus, after testing, the control can still accept other events (such as click, DoubleClick,Mousehover, mouseleave, and other events), if reasonably used, it can still produce good results.

 

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.