Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Register None
#Include "WIN32API.INC"
#Include "COMMCTRL.INC"
Global wHook As Long
Global Btn As Long
Global hDlgMain As Long
Global hWnd_TTip As Long
Declare CallBack Function DlgCallback() As Long
Declare Function BtnProc(ByVal nCode&, ByVal wParam&, Inf As CWPSTRUCT) As Long
Function PBMain()
Dim result As Long
Dim hDlg As Long
Dialog New %HWND_Desktop,"Add button to Titlebar",6, 18, 245, 152, %WS_OverlappedWindow Or %WS_Visible, To hDlg
Dialog Show Modal hDlg , Call DlgCallback To result
End Function
CallBack Function DlgCallback() As Long
Dim ti As TOOLINFO
Dim txtToolTip As Asciiz * 80
Dim lpToolTip As TOOLTIPTEXT Ptr
Select Case CbMsg
Case %WM_InitDialog
Call InitCommonControls()
hDlgMain = CbHndl
Control Add Button, CbHndl, 101, "?", 50, 50, 14, 14, %BS_Default Or %BS_Notify
Btn = GetDlgItem(CbHndl, 101)
ShowWindow Btn, %SW_ShowNormal
'add tooltip (it doesn't work. Please tell me why?)
hWnd_TTip = CreateWindowEx( 0, "tooltips_class32", "Help", %TTS_ALWAYSTIP, 0, 0, 0, 0, 0, ByVal 0&, GetModuleHandle(ByVal 0&), ByVal 0&)
txtToolTip = "Help"
ti.cbsize = SizeOf(ti)
ti.uFlags = %TTF_SUBCLASS Or %TTF_IDISHWND
ti.hwnd = CbHndl
ti.uId = Btn
ti.lpszText = VarPtr(txtToolTip)
Call SendMessage(hWnd_TTip, %TTM_ADDTOOL, 0, ByVal VarPtr(ti))
wHook = SetWindowsHookEx(%WH_CALLWNDPROC, CodePtr(BtnProc), 0, GetWindowThreadProcessId(CbHndl, %NULL))
SetWindowLong Btn, %GWL_EXSTYLE, &H80
SetParent Btn, GetParent(CbHndl)
Case %WM_Destroy
UnhookWindowsHookEx wHook
SetParent Btn, CbHndl
End Select
End Function
Function BtnProc(ByVal nCode&, ByVal wParam&, HkInfo As CWPSTRUCT) As Long
Dim FormRect As RECT
Static LastwParam As Long
Select Case HkInfo.Message
Case %WM_NCPaint, %WM_Move
GetWindowRect hDlgMain, FormRect
SetWindowPos Btn, 0, FormRect.nRight - 135, FormRect.nTop + 6, 17, 14, %SWP_FRAMECHANGED
Case %WM_Command
If LastwParam = Btn Then MsgBox "You clicked me!"
Case %WM_SETCURSOR
LastwParam = HkInfo.wParam
End Select
End Function
'gbs_01193
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm