Author: Hongke Roby
In BCB6, there is no title bar window, that is, BorderStyle is set to bsNone.
You can drag it without a title bar.
Below, I have written four methods.
Method 1: receive messages.
Add the following code to the Public declaration in the header FORM:
MESSAGE void WMNCHitTest (TWMNCHitTest & Message );
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER (WM_NCHITTEST, TWMNCHitTest, WMNCHitTest );
END_MESSAGE_MAP (TForm );
Then, add the following function to the CPP file,
MESSAGE void TForm1: WMNCHitTest (TWMNCHitTest & Msg)
{
TForm: Dispatch (& Msg );
If (Msg. Result = HTCLIENT)
Msg. Result = HTCAPTION;
// TODO: Add your source code here
}
Method 2: Reload the wndproc function.
Add the following function declaration to the public declaration.
Void _ fastcall MyWndProc (Messages: TMessage & Message );
Add a sentence to the FORM constructor,
WindowProc = MyWndProc;
Then add the implementation code of the function to CPP.
Void _ fastcall TForm1: MyWndProc (Messages: TMessage & Message)
{
TForm1: WndProc (Message );
If (Message. Result = HTCLIENT)
Message. Result = HTCAPTION;
}
Method 3: The wndproc function is also overloaded.
I just used a clever method in the code that implements the function,
That is:
Void _ fastcall TForm1: MyWndProc (Messages: TMessage & Message)
{
If (Message. Msg = WM_LBUTTONDOWN)
{
ReleaseCapture ();
Perform (wm_syscommand, 0xf017, 0 );
}
}
Method 4: Use the mouse event.
Add the following code to the form mousedown event:
If (Button = mbleft)
{
Releasecapture ();
Perform (wm_syscommand, 0xf017, 0 );
}
// This method is also the simplest .. :)
//************************************
Finally, add a close button. Otherwise ............
(You can only right-click the task bar below)