Saturday, August 22, 2020

Click and Drag a Delphi Form Without the Caption Bar

Snap and Drag a Delphi Form Without the Caption Bar The most widely recognized approach to move a window is to drag it by its title bar. Peruse on to discover how you can give hauling capacities to Delphi structures without a title bar, so the client can move a structure by clicking anyplace on the customer territory. For instance, consider the instance of a Windows application that doesnt have a title bar, how might we move such a window? In actuality, its conceivable to make windows with a nonstandard title bar and even non-rectangular structures. For this situation, how could Windows know where the fringes and the sides of the window are? The WM_NCHitTest Windows Message The Windows working framework is intensely founded on taking care of messages. For instance, when you click on a window or a control, Windows sends it a wm_LButtonDown message, with extra data about where the mouse cursor is and which control keys are at present squeezed. Sounds recognizable? Truly, this is simply an OnMouseDown occasion in Delphi. Also, Windows sends a wm_NCHitTest message at whatever point a mouse occasion happens, that is, the point at which the cursor moves, or when a mouse button is squeezed or discharged. Code to Input On the off chance that we can make Windows feel that the client is hauling (has tapped on) the title bar instead of the customer zone, at that point the client could drag the window by clicking in the customer zone. The least demanding approach to do this is to trick Windows into believing that youre really tapping on the title bar of a structure. Heres what you need to do: 1. Supplement the accompanying line into your structures Private revelations segment (message taking care of strategy affirmation): system WMNCHitTest(var Msg: TWMNCHitTest) ; message WM_NCHitTest; 2. Include the accompanying code into the usage area of your structures unit (where Form1 is theâ assumed structure name): system TForm1.WMNCHitTest(var Msg: TWMNCHitTest) ;start  â inherited;â â on the off chance that Msg.Result htClient, at that point Msg.Result : htCaption;end; The primary line of code in the message handler calls the acquired strategy to get the default taking care of for the wm_NCHitTest message. The If part in the method catches and changes your windows conduct. This is the thing that really occurs: when the working framework sends a wm_NCHitTest message to the window, along with the mouse arranges, the window restores a code that states which bit of itself has been hit. The significant snippet of data, for our errand, is in the estimation of the Msg.Result field. Now, we have a chance to adjust the message result. This is our main thing: if the client has clicked in the structures customer zone we make Windows to think the client tapped on the title bar. In Object Pascal words: if the message return esteem is HTCLIENT, we essentially transform it to HTCAPTION. No More Mouse Events By changing the default conduct of our structures we evacuate the capacity of Windows to inform you when the mouse is over the customer territory. One reaction of this stunt is that your structure will no longer produce occasions for mouse messages. Captionless-Borderless Window In the event that you need a captionless borderless window like a gliding toolbar, set the Forms Caption to a vacant string, cripple the entirety of the BorderIcons, and set the BorderStyle to bsNone. A structure can be changed in different manners by applying custom code in the CreateParams technique. More WM_NCHitTest Tricks On the off chance that you look all the more cautiously at the wm_NCHitTest message youll see that arrival estimation of the capacity demonstrates the situation of the cursor problem area. This empowers us to play some more with the message to make abnormal outcomes. The accompanying code section will forestall clients to close your structures by tapping on the Close catch. in the event that Msg.Result htClose, at that point Msg.Result : htNowhere; In the event that the client is attempting to move the structure by tapping on the inscription bar and hauling, the code replaces the aftereffect of the message with an outcome which demonstrates the client tapped on the customer region. This keeps the client from moving the window with the mouse (inverse to what we were doing in the asking of the article). on the off chance that Msg.Result htCaption, at that point Msg.Result : htClient; Having Components On a Form As a rule, well have a few segments on a structure. Lets state, for instance, that one Panel object is on a structure. On the off chance that Align property of a board is set to alClient, the Panel fills the whole customer territory with the goal that it is difficult to choose the parent structure by tapping on it. The code above won't work - why? This is on the grounds that the mouse is continually moving over the Panel part, not the structure. To move our structure by hauling a board on the structure we need to include not many lines of code in the OnMouseDown occasion method for the Panel segment: technique TForm1.Panel1MouseDown  (Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer) ;start  â ReleaseCapture;  â SendMessage(Form1.Handle, WM_SYSCOMMAND, 61458, 0) ; end; Note: This code won't work with non-window controls, for example, TLabel parts.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.