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 well-known 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 region. 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 dealing with 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 presently squeezed. Sounds natural? Truly, this is simply an OnMouseDown occasion in Delphi. So 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 In the event that we can make Windows imagine that the client is hauling (has tapped on) the title bar instead of the customer region, at that point the client could drag the window by clicking in the customer region. The most effortless 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. Addition the accompanying line into your structures Private presentations segment (message taking care of method revelation): method WMNCHitTest(var Msg: TWMNCHitTest) ; message WM_NCHitTest; 2. Include the accompanying code into the execution area of your structures unit (where Form1 is theâ assumed structure name): method 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 technique to get the default taking care of for the wm_NCHitTest message. The If part in the method captures 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 organizes, the window restores a code that states which part 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 tell 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 On the off chance that you need a captionless borderless window like a gliding toolbar, set the Forms Caption to an unfilled 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 strategy. More WM_NCHitTest Tricks In the event 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 piece will forestall clients to close your structures by tapping on the Close catch. on the off chance that Msg.Result htClose, at that point Msg.Result : htNowhere; On the off chance that the client is attempting to move the structure by tapping on the inscription bar and hauling, the code replaces the consequence of the message with an outcome which shows the client tapped on the customer territory. 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 By and large, 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 zone 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 segments.

No comments:

Post a Comment

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