FabDev 8 Posted April 13, 2023 (edited) Hello, I would like to show a StayOnTop form on the left of the Minimize, Maximize and Close button (Top right of tittle bar) of a TForm. To do it I need to compute width of these button, so I have tried this : var TitleInfo : TTitleBarInfo; NonClientWidth, ButtonWidth: Integer; begin NonClientWidth := Width - ClientWidth; SendMessage(Handle, WM_GETTITLEBARINFOEX, 0,NativeInt(@TitleBarInfoEx));// LPARAM(@TitleBarInfoEx)); ButtonWidth := TitleBarInfoEx.rgrect[5].Right - TitleBarInfoEx.rgrect[2].Left + 2 * NonClientWidth - 2 * BorderWidth; .... Following this : https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-titlebarinfo But TitleBarInfoEx.rgrect[5].Right return me wrong value like not initialized : So how to get it ? Edited April 13, 2023 by FabDev Share this post Link to post
dwrbudr 8 Posted April 13, 2023 Inspect Delphi's VCL.Forms.pas -> TTitleBar.GetCaptionButtonsRect -> DwmGetWindowAttribute Share this post Link to post
Remy Lebeau 1436 Posted April 13, 2023 7 hours ago, FabDev said: To do it I need to compute width of these button, so I have tried this : ... But TitleBarInfoEx.rgrect[5].Right return me wrong value like not initialized Your code snippet is declaring a variable named TitleInfo, but you are sending WM_GETTITLEBARINFOEX with a pointer to a variable named TitleBarInfoEx instead. Also, make sure you initialize the TTitleBarInfo/Ex.cbSize member before sending WM_GETTITLEBARINFOEX. https://learn.microsoft.com/en-us/windows/win32/menurc/wm-gettitlebarinfoex Quote lParam A pointer to a TITLEBARINFOEX structure. The message sender is responsible for allocating memory for this structure. Set the cbSize member of this structure to sizeof(TITLEBARINFOEX) before passing this structure with the message. https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-gettitlebarinfo Quote [in, out] pti Type: PTITLEBARINFO A pointer to a TITLEBARINFO structure to receive the information. Note that you must set the cbSize member to sizeof(TITLEBARINFO) before calling this function. So, try this instead: var TitleInfo : TTitleBarInfoEx; ... begin ... TitleInfo.cbSize := SizeOf(TitleInfo); // <-- ADD THIS! SendMessage(Handle, WM_GETTITLEBARINFOEX, 0, LPARAM(@TitleInfo)); ... end; Share this post Link to post
KodeZwerg 54 Posted April 14, 2023 Beside the WinAPI way, you could make your day easier by following the Vcl way of doing and playing with the Titlebar. Share this post Link to post
FabDev 8 Posted April 14, 2023 5 hours ago, KodeZwerg said: Beside the WinAPI way, you could make your day easier by following the Vcl way of doing and playing with the Titlebar. Thank you that was a nice idea but I use DevExpress (Bar/Ribbon and Skin) which is not compatible with the native Titlebar. Share this post Link to post
FabDev 8 Posted April 14, 2023 23 hours ago, Remy Lebeau said: So, try this instead: Thank you Remy it's work fine ! Share this post Link to post