Delpi Displays graphics controls in the MDI window and the solution to the specified background

zhaozj2021-02-17  96

When using the MDI interface, sometimes you need to display some graphics or software cover in the MDI customer window, so that the software interface will not be empty, the software function can also be at a glance. However, these interfaces are not given directly in Delphi. Putting any graphic control in the MDI form cannot be displayed at runtime. Therefore, the MDI form is required to be modified.

Received:

This program is only for the MDI form. If the application is in a non-MDI form, the consequences are difficult to say, you have tried it.

Remember, the FormStyle property of the form is set to: FSMDIFORM.

solution:

1. Unable to receive the message of the MDI customer window in the MDI main form, so you need to define the processing process of the customer window and take over the MDI customer window (you need to implement it in the overloaded CREATEWND process. ):

Procedure TMDIFORM.CREATEWND;

Begin

inherited;

FNewWndProc: = MakeObjectInstance (ClientWndProc);

FoldWndProc: = Pointer (getWindowlong (ClientHandle, GWL_WNDPROC);

Setwindowlong (ClientHandle, GWL_WndProc, Longint (FNewWndProc);

END;

Among them, ClientWndProc is a custom window process: Procedure ClientWndProc (Var Message: TMessage);

FoldWndProc is used to store pointers in an old window process.

2. Realize your own customer window process:

Procedure TMDIFORM.CLIENTWNDPROC (Var Message: TMESSAGE);

VAR

R: TRECT;

PROCEDURE DEFAULT;

Begin

WITH MESSAGE DO

Result: = CallWindowProc (FoldwndProc, ClientHandle, MSG, WPARAM, LPARAM);

END;

VAR

PS: tpaintstruct;

Begin

R: = ClientRect;

Case message.msg of

WM_PAINT:

Begin

BeginPaint (ClientHandle, PS);

Try

Canvas.lock;

Try

Canvas.handle: = ps.hdc;

Try

Paint;

IF controlcount> 0 THEN

PaintControls (ps.hdc, controls [0]);

Finally

Canvas.Handle: = 0;

END;

Finally

Canvas.unlock;

END;

Finally

Endpaint (ClientHandle, PS);

END;

END;

WM_ERASEBKGND:

Begin

Drawbg (twmesebkgnd (message) .dc);

Message.Result: = 1;

END;

WM_VSCROLL, WM_HSCROLL:

Begin

INVALIDATERECT (ClientHandle, @ r, true);

DEFAULT;

END;

WM_SIZE:

Begin

INVALIDATERECT (ClientHandle, @ r, true);

DEFAULT;

END;

Else

DEFAULT;

END;

END;

The above DRAWBG is used to draw a window background.

3. Implement the window background.

In order to allow the successor to define the background, this process shows Virtual:

protected

Procedure DrawBG (DC: HDC); Virtual;

Here, the drawbg process is just a simple fill window background:

Procedure TMDIFORM.DRAWBG (DC: HDC);

Begin

IF brush.color <> clnone dam

FillRect (DC, ClientRect, brush.handle);

END;

4. In summary, summarizing the TMDIFROM class is as follows:

TMDIFORM = Class (TFORM)

Private

FoldWndProc: tfarproc;

FNewWndproc: TfarProc;

Procedure ClientWndProc (var message: tMessage);

protected

Procedure DrawBG (DC: HDC); Virtual;

PROCEDURE CREATEWND; OVERRIDE;

END;

5. After the above transformation, you can draw the designated background in DrawBG (you need to call the Windows GUI interface directly), or use the graphic control directly, or the onpaint event of the form, the MDI window has a colorful.

转载请注明原文地址:https://www.9cbs.com/read-31336.html

New Post(0)