Delphi Tips - Mobile No Title Window

zhaozj2021-02-16  42

Delphi Tips - Mobile No Title Window

Keywords: moving, message, no title

Author: Zhu Nengwen

We all know that Windows moves the form through the title bar. When we press the left mouse button on the title bar, Windows will send a WM_NCHITTEST message to tell the system to move the form. But when we actually program, sometimes for the needs or special requirements of the interface, the form does not have a title bar, we must move the form through the program. Below I will introduce several ways and techniques for mobile forms.

Method 1: Calculate the location of the form based on the position difference at the mouse presses and moves. The variables that need to be defined are as follows:

VAR

Opos, CPOS: TPOINT;

Flag: boolean = false;

Process the onMouseDown event code:

Flag: = True;

Opos.x: = x;

Opos.y: = Y;

Process the onMouseMove event code:

IF flag dam

Begin

Cpos.x: = x;

CPOS.Y: = Y;

Left: = left cpos.x - opos.x;

Top: = TOP CPOP.Y - OPOS.Y;

END;

Process the onMouseMove event code:

Flag: = false;

Method 2: User-defined messages, block "WM_NCHITTEST", and turn the message value "htclient" to "htcaption". The implementation is as follows:

First define a message constant: const wm_mytest = wm_user 200;

Declaration in the Private section:

Procedure MoveClient (Var Message: TMESSAGE); Message WM_NCHITTEST;

Realization of the process:

Inherited; // Inherit, the form can continue to handle the future event

If message.result = HTClient Then

Message.Result: = htcaption;

Method 3: Send a "WM_SYSCOMMAND" message directly to the form, you need to use unmarkable "SC_Dragmove" flags, defined as follows:

Const sc_dragmove = $ f012;

We can only send this message to the TwinControl derived component, and can only respond to the mouse to press events because the system is captured at this time (when the mouse button is released, the drag operation is meaningless). InmouseDown event processing code in the form:

ReleaseCapture; // Release the mouse capture status;

(Sender as twinControl) .Perform (wm_syscommand, sc_dragmove, 0); // Send a mobile message to the form;

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

New Post(0)