Precautions for window Embedded desktop and transparency

Source: Internet
Author: User

In the past few days, we have to embed the form into the desktop and make the window transparent.
At first, I thought there should be no major problems as I know, and the results are true. There are no major problems, but there are a few minor problems in the details...

1. Embedded Desktop
The principle is very simple. Find Progman and pass the window SetParent.
(Of course, it can also be embedded into the subwindow of Progman to ensure that the window does not overwrite the desktop icon, but my requirement is that my window must overwrite the desktop icon)
However, the problem arises. I found that my window will be hidden when F5 or Win + D is on the desktop. The attempt to intercept the WM_SYSCOMMAND/SC _MINIMIZED message is invalid.
However, other programs embedded in the desktop do not have this problem.
After checking the Window Style, I found that the Ex Style of my Window has an additional WS_EX_APPWINDOW attribute (because it is the main Window)
However, this attribute cannot be removed in my main window, so after a New Form is created dynamically, OK

Code (just one sentence ...)

1Windows. SetParent (Handle, FindWindow ('progman ', 'program manager '));

2. about transparency
The first thing that comes to mind is Layered Window.
Note that the window style ExStyle must contain WS_EX_LAYERED (0x80000), and the value specified in CreateParams is invalid...
Then, use SetLayeredWindowAttributes to set the transparency. There are many questions about this function online. I will not repeat it here.
During execution, I found that my window was not transparent. setlayered?wattributes returned False
So I guess it is related to the Style of the form (because my window BorderStyle = bsNone)
Sure enough, after WS_POPUP is added to the form in CreateParams, it is transparent ~ Applaud ~~
However, although the window is transparent, the controls in the form are also transparent...

The WS_EX_TRANSPARENT style is followed, and the form is transparent, but the control is not transparent.
However, when the desktop is refreshed in this style, the window will not be notified in time, so the display will be a bit problematic.
Trying MsgHook... (to be continued)

Post a code first

1 procedure TSubForm. CreateParams (var Params: TCreateParams );
2 begin
3 inherited;
4 with Params do Style: = Style or WS_POPUP;
5end;
6
7 procedure TSubForm. FormCreate (Sender: TObject );
8 begin
9 UpdateStyle;
10end;
11
12 procedure TSubForm. UpdateStyle;
13 begin
14 SetWindowLong (Handle, GWL_EXSTYLE,
15 GetWindowLong (Handle, GWL_EXSTYLE) or WS_EX_LAYERED );
16 if Assigned (SetLayeredWindowAttributes) then
17 SetLayeredWindowAttributes (Handle, 0,128, LWA_ALPHA );
18end;
19

// Don't use D for a long time, forget all about it...
// Use AlphaBlend/AlphaBlendValue or TransparentColor/TransparentColorVale of Form directly above D7 to achieve transparency
// It is actually implemented using SetLayeredWindowAttributes.
 

1 procedure TSubForm. CreateParams (var Params: TCreateParams );
2 begin
3 inherited;
4 with Params do ExStyle: = ExStyle or WS_EX_TRANSPARENT;
5end;

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.