For my dzComputerInfo tool I created a window without a title that can still be moved with the mouse. This is quite easy to do:
- To remove the title, set BorderStyle to bsNone.
- To let the user move it with the mouse, add the following message handler:
type TMyForm = class(TForm) private procedure WMNCHitTest(var Msg: TWMNcHitTest); message WM_NCHITTEST; end; procedure TMyForm .WMNCHitTest(var Msg: TWMNcHitTest); begin inherited; if (Msg.Result = htClient) then Msg.Result := htCaption; end;
It tells Windows, that the user clicked on the title rather than the client area. Windows then does the rest, and the user can move the window with the mouse as if he clicked on the window title.
If you also want the window to have a context menu, you’ll have to change the message handler, so it does not affect right mouse clicks:
procedure TMyForm .WMNCHitTest(var Msg: TWMNcHitTest); var Res: SmallInt; begin inherited; Res := GetKeyState(VK_RBUTTON); if Res >= 0 then // only if the right mouse button was not pressed // (otherwise the popup menu wont show) if (Msg.Result = htClient) then Msg.Result := htCaption; end;