Home > Back-end >  The window of the Delphi dynamically create how to specify a custom event?
The window of the Delphi dynamically create how to specify a custom event?

Time:11-08

I have a no title of the window, can drag, can be arbitrary adjust the size, everyone knows any drag is

Procedure TForm1. FormMouseDown (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
The begin
ReleaseCapture;
SendMessage (Handle, wm_SysCommand, $F012, 0).//drag form mobile
The end;

Below is adjust the size of the code, use that to change the code style

Procedure TForm1. WMNchist (var Msg: TMessage);
Const
COffset=10;
Var
VPoint: TPoint;
MouseX and MouseY: integer;

The begin
Inherited;//inherited is the function calls the ancestor class, if the same function called with no arguments is the default
MouseX:=LOWORD (Msg. LParam);//mouse X
MouseY:=HIWORD (Msg. LParam);//mouse Y
VPoint:=ScreenToClient (Point (MouseX, MouseY));//screen coordinates customer
If PtInRect (the Rect (0, 0, cOffset, cOffset), vPoint) then
Msg. Result:=HTTOPLEFT//in the upper left corner
Else if PtInRect (the Rect (Height, Width - cOffset - cOffset, Width, Height), vPoint) then
Msg. Result:=HTBOTTOMRIGHT//lower right foot at the border
Else if PtInRect (the Rect (Width - cOffset, 0, Width, cOffset), vPoint) then
Msg. Result:=HTTOPRIGHT//in the upper right-hand corner
Else if PtInRect (the Rect (0, Height - cOffset, cOffset, Height), vPoint) then
Msg. Result:=HTBOTTOMLEFT////
lower left foot on the borderElse if PtInRect (the Rect (cOffset, 0, Width - cOffset cOffset), vPoint) then
Msg. Result:=HTTOP//border on
Else if PtInRect (the Rect (0, cOffset cOffset, Height - cOffset), vPoint) then
Msg. Result:=HTLEFT//
the left borderElse if PtInRect (the Rect (Width - cOffset cOffset, Width, Height - cOffset), vPoint) then
Msg. Result:=HTRIGHT//in the right boundary
Else if PtInRect (the Rect (cOffset, Height - cOffset, Width - cOffset, Height), vPoint) then
Msg. Result:=HTBOTTOM;//in a window below the level of border

The end;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
{WM_NCHITTEST message indicating
The message is used to describe when GuanBiao move or when pressed or when to release the mouse button,
It will send a WM_NCHITTEST message to a window if the mouse is not captured,
Is this message sent to the window of the cursor,
Otherwise, the news release window to capture the mouse,

Parameter
XPos=LOWORD (Lparam);//LParam low word values,
Is pointed out that the X coordinates of the cursor, the coordinates are relative to the top left corner of the screen coordinates,

YPos=HIWORD (LParam);//LParam the value of the high word is pointed out that the y coordinates of the cursor,

The return value of the DefWindowProc function return value is one of the following values, to indicate the location of the cursor hotspot
:
HTBORDER cursor hotspot in a window on the border of the window does not have the size of a variable boundary
HBOTTOM in a window below the level of border
HBOTTOMLEFT in the lower left corner of a window border
HBOTTOMRIGHT lower right foot at the border
HTCAPTION
in the title barHTCLIENT in the client area
HTERROR on the dividing line between Beijing or window screen (similar to HTNOWHERE,
The difference is the DefWindowProc function to create a ring a bell system to indicate an error)
HTGROWBOX in the size box (the same as the HTSIZE)
HTHSCROLL in a horizontal scroll bar
HTLEFT in the left border
HTMENU in the menu
HTNOWHERE on the screen or window on the dividing line between
On a minimize button HTREDUCE
HTRIGHT right at the window border
HTSIZE
in the size boxHTSYSMENU in a a System menu, or in a child window's Close button
HTTOP in the upper boundary
HTTOPLEFT in the upper left corner
HTTOPRIGHT in the upper right-hand corner
HTTRANSPARENT in the current window is covered by other Windows
HTVSCROLL
in the vertical scroll barHTZOOM on the maximize button

}
/////////////////////////////////////////////////////////////////////////////////////////////////////

Above is built in advance on the window everything is all right, I'm going to ask is to dynamically create window, has the two functions, through test
Dynamic window. FormMouseDown=Form1 FormMouseDown, can move the window, then the problem here:


WMNchist custom event, the event was itself form their own event is not complete, so the above code methods in nature is not available, could not now, don't know how to make the dynamic window to perform the above the message interception events

CodePudding user response:

Base class (if the name is TBaseWin form) implements the message interceptor, you dynamically create form, is TBaseWin types can be,

CodePudding user response:

Reference
base class form (if the name is TBaseWin) implements the message interceptor, you dynamically create form, is TBaseWin type can,

Don't know the eldest brother, now I just want to let dynamically created no title window size can be changed freely
  • Related