Conclusion on the self-righteous experience of window (form) in Delphi

Source: Internet
Author: User
You cannot release yourself in the mode form.

The method form1 is as follows:

VaR

X: tform2;

Begin

X: = tform2.createparented (self. Handle );

X. showmodal;

If you use self. Release to release yourself in an event Method in form2, form2 disappears, and form1 no longer responds to the keyboard or mouse. If it is changed to the following:

X: = tform2.createparented (self. Handle); (or X: = tform2.create (NiL ))

X. showmodal;

X. release; (or X. Free)

After changing the 2nd sentence to X. Show, everything will work normally.

Conclusion: you cannot release yourself in the mode form,

Principle: After code tracing, it is found that the form is implemented in this way: repeat the message and modalresult attribute values in the showmodal method until the conditions are met, and then close your own series of actions. Therefore, calling release or similar methods in the mode form will lead to confusion. To close yourself in the mode form, you can call the close method or set the modalresult attribute to a non-zero value.

After the mode form is displayed, the mode form cannot return to the front of the screen.

Or the first code in the previous issue,

VaR

X: tform2;

Begin

X: = tform2.createparented (self. Handle );

X. showmodal;

 

After form2 is displayed (when its formstyle attribute is fsnormal), switch to another task screen in the operating system and

Only the following method can return to the Program Screen (that is, to bring form2 back to the front of the screen ):

1. Select "show desktop" and click the program task on the taskbar;

2. Click form1. Although form1 cannot receive the focus, it leads form2 to the front of the screen;

3. Click the title bar of form2.

The following method cannot bring form2 back to the front of the screen

1. Click the area outside the title bar of form2. Although form2 is activated, it cannot return to the front;

2. Click the program task on the operating system taskbar.

3. Switch to the program through the Task Manager

Cause: It is almost certainly a bug in Delphi. Solution

Override the wndproc method of form2 to capture the wm_activate message. After obtaining the message, setwindowpos (self. Handle, hwnd_top,

0, 0, 0, swp_nosize + swp_nomove); this statement causes form2 to return to the front.

Avoid using the bsdialog border for a non-mode form

2003.7.28

It is also found that in Excel, the form with the non-mode border set to bsdialog established by Delphi also has the same situation. When switching back to another task in the operating system, excel is hard to display,

However, when displayed, the form status is normal.

Therefore, avoid using the bsdialog border for non-mode forms,

Message response

I overwrite the wndproc method and try to capture the Shift key in any combination key that the user presses. The Code is as follows:

Procedure tform1.wndproc (VAR message: tmessage );

Begin

If message. MSG = wm_keyup then

If getkeystate (vk_shift) = 1 then

Showmessage ('shift ');

Inherited;

End;

The result shows that getkeystate is captured only once every two key combinations (for example, Shift + 1), and even worse, when shift is captured at one time, at present, only press 1 instead of shift, but getkeystate captures the Shift key every time.

Conclusion:

Whether it is the wndproc or mainwndproc method, the message parameters are processed. That is to say, there is another process (this process is generated at runtime. For details, refer to Article 1267299 in monopoly) after responding to a Windows message, the message is processed into a tmessage structure and then passed to the mainwndproc method. The processed messages are different from the original Windows messages.

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.