GuiButton.au3 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. #include-once
  2. #include "APIResConstants.au3"
  3. #include "ButtonConstants.au3"
  4. #include "SendMessage.au3"
  5. #include "UDFGlobalID.au3"
  6. #include "WinAPIConv.au3"
  7. #include "WinAPIIcons.au3"
  8. #include "WinAPISysInternals.au3"
  9. ; #INDEX# =======================================================================================================================
  10. ; Title .........: Button
  11. ; AutoIt Version : 3.3.14.5
  12. ; Language ......: English
  13. ; Description ...: Functions that assist with Button control management.
  14. ; A button is a control the user can click to provide input to an application.
  15. ; ===============================================================================================================================
  16. ; #VARIABLES# ===================================================================================================================
  17. Global $__g_hButtonLastWnd
  18. ; ===============================================================================================================================
  19. ; #CONSTANTS# ===================================================================================================================
  20. Global Const $tagBUTTON_IMAGELIST = "ptr ImageList;" & $tagRECT & ";uint Align"
  21. Global Const $tagBUTTON_SPLITINFO = "uint mask;handle himlGlyph;uint uSplitStyle;" & $tagSIZE
  22. ; mask
  23. ; A set of flags that specify which members of this structure contain data to be set or which members are being requested. Set this member to one or more of the following flags.
  24. ; BCSIF_GLYPH
  25. ; himlGlyph is valid.
  26. ; BCSIF_IMAGE
  27. ; himlGlyph is valid. Use when uSplitStyle is set to BCSS_IMAGE.
  28. ; BCSIF_SIZE
  29. ; size is valid.
  30. ; BCSIF_STYLE
  31. ; uSplitStyle is valid.
  32. ; himlGlyph
  33. ; A handle to the image list. The provider retains ownership of the image list and is ultimately responsible for its disposal.
  34. ; uSplitStyle
  35. ; The split button style. Value must be one or more of the following flags.
  36. ; BCSS_ALIGNLEFT
  37. ; Align the image or glyph horizontally with the left margin.
  38. ; BCSS_IMAGE
  39. ; Draw an icon image as the glyph.
  40. ; BCSS_NOSPLIT
  41. ; No split.
  42. ; BCSS_STRETCH
  43. ; Stretch glyph, but try to retain aspect ratio.
  44. ; size
  45. ; Fields ........: X - Width
  46. ; Y - Height
  47. Global Const $__BUTTONCONSTANT_ClassName = "Button"
  48. Global Const $__BUTTONCONSTANT_GWL_STYLE = 0xFFFFFFF0
  49. Global Const $__BUTTONCONSTANT_WM_SETFONT = 0x0030
  50. Global Const $__BUTTONCONSTANT_DEFAULT_GUI_FONT = 17
  51. ; ===============================================================================================================================
  52. ; #NO_DOC_FUNCTION# =============================================================================================================
  53. ; Not working/documented/implemented at this time
  54. ;
  55. ; _GUICtrlButton_SetDropDownState
  56. ; ===============================================================================================================================
  57. ; #CURRENT# =====================================================================================================================
  58. ; _GUICtrlButton_Click
  59. ; _GUICtrlButton_Create
  60. ; _GUICtrlButton_Destroy
  61. ; _GUICtrlButton_Enable
  62. ; _GUICtrlButton_GetCheck
  63. ; _GUICtrlButton_GetFocus
  64. ; _GUICtrlButton_GetIdealSize
  65. ; _GUICtrlButton_GetImage
  66. ; _GUICtrlButton_GetImageList
  67. ; _GUICtrlButton_GetNote
  68. ; _GUICtrlButton_GetNoteLength
  69. ; _GUICtrlButton_GetSplitInfo
  70. ; _GUICtrlButton_GetState
  71. ; _GUICtrlButton_GetText
  72. ; _GUICtrlButton_GetTextMargin
  73. ; _GUICtrlButton_SetCheck
  74. ; _GUICtrlButton_SetDontClick
  75. ; _GUICtrlButton_SetFocus
  76. ; _GUICtrlButton_SetImage
  77. ; _GUICtrlButton_SetImageList
  78. ; _GUICtrlButton_SetNote
  79. ; _GUICtrlButton_SetShield
  80. ; _GUICtrlButton_SetSize
  81. ; _GUICtrlButton_SetSplitInfo
  82. ; _GUICtrlButton_SetState
  83. ; _GUICtrlButton_SetStyle
  84. ; _GUICtrlButton_SetText
  85. ; _GUICtrlButton_SetTextMargin
  86. ; _GUICtrlButton_Show
  87. ; ===============================================================================================================================
  88. ; #FUNCTION# ====================================================================================================================
  89. ; Author ........: Gary Frost
  90. ; Modified.......:
  91. ; ===============================================================================================================================
  92. Func _GUICtrlButton_Click($hWnd)
  93. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  94. _SendMessage($hWnd, $BM_CLICK)
  95. EndFunc ;==>_GUICtrlButton_Click
  96. ; #FUNCTION# ====================================================================================================================
  97. ; Author ........: Gary Frost
  98. ; Modified.......:
  99. ; ===============================================================================================================================
  100. Func _GUICtrlButton_Create($hWnd, $sText, $iX, $iY, $iWidth, $iHeight, $iStyle = -1, $iExStyle = -1)
  101. If Not IsHWnd($hWnd) Then
  102. ; Invalid Window handle for _GUICtrlButton_Create 1st parameter
  103. Return SetError(1, 0, 0)
  104. EndIf
  105. If Not IsString($sText) Then
  106. ; 2nd parameter not a string for _GUICtrlButton_Create
  107. Return SetError(2, 0, 0)
  108. EndIf
  109. Local $iForcedStyle = BitOR($__UDFGUICONSTANT_WS_TABSTOP, $__UDFGUICONSTANT_WS_VISIBLE, $__UDFGUICONSTANT_WS_CHILD, $BS_NOTIFY)
  110. If $iStyle = -1 Then
  111. $iStyle = $iForcedStyle
  112. Else
  113. $iStyle = BitOR($iStyle, $iForcedStyle)
  114. EndIf
  115. If $iExStyle = -1 Then $iExStyle = 0
  116. Local $nCtrlID = __UDF_GetNextGlobalID($hWnd)
  117. If @error Then Return SetError(@error, @extended, 0)
  118. Local $hButton = _WinAPI_CreateWindowEx($iExStyle, $__BUTTONCONSTANT_ClassName, $sText, $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd, $nCtrlID)
  119. _SendMessage($hButton, $__BUTTONCONSTANT_WM_SETFONT, _WinAPI_GetStockObject($__BUTTONCONSTANT_DEFAULT_GUI_FONT), True)
  120. Return $hButton
  121. EndFunc ;==>_GUICtrlButton_Create
  122. ; #FUNCTION# ====================================================================================================================
  123. ; Author ........: Gary Frost
  124. ; Modified.......:
  125. ; ===============================================================================================================================
  126. Func _GUICtrlButton_Destroy(ByRef $hWnd)
  127. If Not _WinAPI_IsClassName($hWnd, $__BUTTONCONSTANT_ClassName) Then Return SetError(2, 2, False)
  128. Local $iDestroyed = 0
  129. If IsHWnd($hWnd) Then
  130. If _WinAPI_InProcess($hWnd, $__g_hButtonLastWnd) Then
  131. Local $nCtrlID = _WinAPI_GetDlgCtrlID($hWnd)
  132. Local $hParent = _WinAPI_GetParent($hWnd)
  133. $iDestroyed = _WinAPI_DestroyWindow($hWnd)
  134. Local $iRet = __UDF_FreeGlobalID($hParent, $nCtrlID)
  135. If Not $iRet Then
  136. ; can check for errors here if needed, for debug
  137. EndIf
  138. Else
  139. ; Not Allowed to Destroy Other Applications Control(s)
  140. Return SetError(1, 1, False)
  141. EndIf
  142. Else
  143. $iDestroyed = GUICtrlDelete($hWnd)
  144. EndIf
  145. If $iDestroyed Then $hWnd = 0
  146. Return $iDestroyed <> 0
  147. EndFunc ;==>_GUICtrlButton_Destroy
  148. ; #FUNCTION# ====================================================================================================================
  149. ; Author ........: Gary Frost
  150. ; Modified.......:
  151. ; ===============================================================================================================================
  152. Func _GUICtrlButton_Enable($hWnd, $bEnable = True)
  153. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  154. If _WinAPI_IsClassName($hWnd, $__BUTTONCONSTANT_ClassName) Then Return _WinAPI_EnableWindow($hWnd, $bEnable) = $bEnable
  155. EndFunc ;==>_GUICtrlButton_Enable
  156. ; #FUNCTION# ====================================================================================================================
  157. ; Author ........: Gary Frost
  158. ; Modified.......:
  159. ; ===============================================================================================================================
  160. Func _GUICtrlButton_GetCheck($hWnd)
  161. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  162. Return _SendMessage($hWnd, $BM_GETCHECK)
  163. EndFunc ;==>_GUICtrlButton_GetCheck
  164. ; #FUNCTION# ====================================================================================================================
  165. ; Author ........: Gary Frost
  166. ; Modified.......:
  167. ; ===============================================================================================================================
  168. Func _GUICtrlButton_GetFocus($hWnd)
  169. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  170. If _WinAPI_IsClassName($hWnd, $__BUTTONCONSTANT_ClassName) Then Return _WinAPI_GetFocus() = $hWnd
  171. EndFunc ;==>_GUICtrlButton_GetFocus
  172. ; #FUNCTION# ====================================================================================================================
  173. ; Author ........: Gary Frost
  174. ; Modified.......:
  175. ; ===============================================================================================================================
  176. Func _GUICtrlButton_GetIdealSize($hWnd)
  177. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  178. Local $tSize = DllStructCreate($tagSIZE), $aSize[2]
  179. Local $iRet = _SendMessage($hWnd, $BCM_GETIDEALSIZE, 0, $tSize, 0, "wparam", "struct*")
  180. If Not $iRet Then Return SetError(-1, -1, $aSize)
  181. $aSize[0] = DllStructGetData($tSize, "X")
  182. $aSize[1] = DllStructGetData($tSize, "Y")
  183. Return $aSize
  184. EndFunc ;==>_GUICtrlButton_GetIdealSize
  185. ; #FUNCTION# ====================================================================================================================
  186. ; Author ........: Gary Frost
  187. ; Modified.......:
  188. ; ===============================================================================================================================
  189. Func _GUICtrlButton_GetImage($hWnd)
  190. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  191. Local $iRet = _SendMessage($hWnd, $BM_GETIMAGE, 0, 0, 0, "wparam", "lparam", "hwnd") ; check IMAGE_BITMAP
  192. If $iRet <> 0x00000000 Then Return $iRet
  193. $iRet = _SendMessage($hWnd, $BM_GETIMAGE, 1, 0, 0, "wparam", "lparam", "hwnd") ; check IMAGE_ICON
  194. If $iRet = 0x00000000 Then Return 0
  195. Return $iRet
  196. EndFunc ;==>_GUICtrlButton_GetImage
  197. ; #FUNCTION# ====================================================================================================================
  198. ; Author ........: Gary Frost
  199. ; Modified.......:
  200. ; ===============================================================================================================================
  201. Func _GUICtrlButton_GetImageList($hWnd)
  202. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  203. Local $tBUTTON_IMAGELIST = DllStructCreate($tagBUTTON_IMAGELIST), $aImageList[6]
  204. If Not _SendMessage($hWnd, $BCM_GETIMAGELIST, 0, $tBUTTON_IMAGELIST, 0, "wparam", "struct*") Then Return SetError(-1, -1, $aImageList)
  205. $aImageList[0] = DllStructGetData($tBUTTON_IMAGELIST, "ImageList")
  206. $aImageList[1] = DllStructGetData($tBUTTON_IMAGELIST, "Left")
  207. $aImageList[2] = DllStructGetData($tBUTTON_IMAGELIST, "Right")
  208. $aImageList[3] = DllStructGetData($tBUTTON_IMAGELIST, "Top")
  209. $aImageList[4] = DllStructGetData($tBUTTON_IMAGELIST, "Bottom")
  210. $aImageList[5] = DllStructGetData($tBUTTON_IMAGELIST, "Align")
  211. Return $aImageList
  212. EndFunc ;==>_GUICtrlButton_GetImageList
  213. ; #FUNCTION# ====================================================================================================================
  214. ; Author ........: Gary Frost
  215. ; Modified.......:
  216. ; ===============================================================================================================================
  217. Func _GUICtrlButton_GetNote($hWnd)
  218. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  219. Local $iLen = _GUICtrlButton_GetNoteLength($hWnd) + 1
  220. Local $tNote = DllStructCreate("wchar Note[" & $iLen & "]")
  221. Local $tLen = DllStructCreate("dword")
  222. DllStructSetData($tLen, 1, $iLen)
  223. If Not _SendMessage($hWnd, $BCM_GETNOTE, $tLen, $tNote, 0, "struct*", "struct*") Then Return SetError(-1, 0, "")
  224. Return _WinAPI_WideCharToMultiByte($tNote)
  225. EndFunc ;==>_GUICtrlButton_GetNote
  226. ; #FUNCTION# ====================================================================================================================
  227. ; Author ........: Gary Frost
  228. ; Modified.......:
  229. ; ===============================================================================================================================
  230. Func _GUICtrlButton_GetNoteLength($hWnd)
  231. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  232. Return _SendMessage($hWnd, $BCM_GETNOTELENGTH)
  233. EndFunc ;==>_GUICtrlButton_GetNoteLength
  234. ; #FUNCTION# ====================================================================================================================
  235. ; Author ........: Gary Frost
  236. ; Modified.......:
  237. ; ===============================================================================================================================
  238. Func _GUICtrlButton_GetSplitInfo($hWnd)
  239. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  240. Local $tSplitInfo = DllStructCreate($tagBUTTON_SPLITINFO), $aInfo[4]
  241. DllStructSetData($tSplitInfo, "mask", BitOR($BCSIF_GLYPH, $BCSIF_IMAGE, $BCSIF_SIZE, $BCSIF_STYLE))
  242. If Not _SendMessage($hWnd, $BCM_GETSPLITINFO, 0, $tSplitInfo, 0, "wparam", "struct*") Then Return SetError(-1, 0, $aInfo)
  243. $aInfo[0] = DllStructGetData($tSplitInfo, "himlGlyph")
  244. $aInfo[1] = DllStructGetData($tSplitInfo, "uSplitStyle")
  245. $aInfo[2] = DllStructGetData($tSplitInfo, "X")
  246. $aInfo[3] = DllStructGetData($tSplitInfo, "Y")
  247. Return $aInfo
  248. EndFunc ;==>_GUICtrlButton_GetSplitInfo
  249. ; #FUNCTION# ====================================================================================================================
  250. ; Author ........: Gary Frost
  251. ; Modified.......:
  252. ; ===============================================================================================================================
  253. Func _GUICtrlButton_GetState($hWnd)
  254. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  255. Return _SendMessage($hWnd, $BM_GETSTATE)
  256. EndFunc ;==>_GUICtrlButton_GetState
  257. ; #FUNCTION# ====================================================================================================================
  258. ; Author ........: Gary Frost
  259. ; Modified.......:
  260. ; ===============================================================================================================================
  261. Func _GUICtrlButton_GetText($hWnd)
  262. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  263. If _WinAPI_IsClassName($hWnd, $__BUTTONCONSTANT_ClassName) Then Return _WinAPI_GetWindowText($hWnd)
  264. Return ""
  265. EndFunc ;==>_GUICtrlButton_GetText
  266. ; #FUNCTION# ====================================================================================================================
  267. ; Author ........: Gary Frost
  268. ; Modified.......:
  269. ; ===============================================================================================================================
  270. Func _GUICtrlButton_GetTextMargin($hWnd)
  271. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  272. Local $tRECT = DllStructCreate($tagRECT), $aRect[4]
  273. If Not _SendMessage($hWnd, $BCM_GETTEXTMARGIN, 0, $tRECT, 0, "wparam", "struct*") Then Return SetError(-1, -1, $aRect)
  274. $aRect[0] = DllStructGetData($tRECT, "Left")
  275. $aRect[1] = DllStructGetData($tRECT, "Top")
  276. $aRect[2] = DllStructGetData($tRECT, "Right")
  277. $aRect[3] = DllStructGetData($tRECT, "Bottom")
  278. Return $aRect
  279. EndFunc ;==>_GUICtrlButton_GetTextMargin
  280. ; #FUNCTION# ====================================================================================================================
  281. ; Author ........: Gary Frost
  282. ; Modified.......:
  283. ; ===============================================================================================================================
  284. Func _GUICtrlButton_SetCheck($hWnd, $iState = $BST_CHECKED)
  285. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  286. _SendMessage($hWnd, $BM_SETCHECK, $iState)
  287. EndFunc ;==>_GUICtrlButton_SetCheck
  288. ; #FUNCTION# ====================================================================================================================
  289. ; Author ........: Gary Frost
  290. ; Modified.......:
  291. ; ===============================================================================================================================
  292. Func _GUICtrlButton_SetDontClick($hWnd, $bState = True)
  293. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  294. _SendMessage($hWnd, $BM_SETDONTCLICK, $bState)
  295. EndFunc ;==>_GUICtrlButton_SetDontClick
  296. ; #NO_DOC_FUNCTION# =============================================================================================================
  297. ; Name...........: _GUICtrlButton_SetDropDownState
  298. ; Description ...: Sets the drop down state for a button with style $TBSTYLE_DROPDOWN
  299. ; Syntax.........: _GUICtrlButton_SetDropDownState ( $hWnd [, $bState = True] )
  300. ; Parameters ....: $hWnd - Handle to the control
  301. ; $iState - Drop down state
  302. ; | True - For state of $BST_DROPDOWNPUSHED
  303. ; | False - otherwise
  304. ; Return values .: Success - True
  305. ; Failure - False
  306. ; Author ........: Gary Frost
  307. ; Modified.......:
  308. ; Remarks .......: Minimum Operating Systems: Windows Vista
  309. ; Related .......:
  310. ; Link ..........: @@MsdnLink@@ BCM_SETDROPDOWNSTATE
  311. ; Example .......: Yes
  312. ; ===============================================================================================================================
  313. Func _GUICtrlButton_SetDropDownState($hWnd, $bState = True)
  314. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  315. Return _SendMessage($hWnd, $BCM_SETDROPDOWNSTATE, $bState) <> 0
  316. EndFunc ;==>_GUICtrlButton_SetDropDownState
  317. ; #FUNCTION# ====================================================================================================================
  318. ; Author ........: Gary Frost
  319. ; Modified.......:
  320. ; ===============================================================================================================================
  321. Func _GUICtrlButton_SetFocus($hWnd, $bFocus = True)
  322. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  323. If _WinAPI_IsClassName($hWnd, $__BUTTONCONSTANT_ClassName) Then
  324. If $bFocus Then
  325. Return _WinAPI_SetFocus($hWnd) <> 0
  326. Else
  327. Return _WinAPI_SetFocus(_WinAPI_GetParent($hWnd)) <> 0
  328. EndIf
  329. EndIf
  330. EndFunc ;==>_GUICtrlButton_SetFocus
  331. ; #FUNCTION# ====================================================================================================================
  332. ; Author ........: Gary Frost
  333. ; Modified.......:
  334. ; ===============================================================================================================================
  335. Func _GUICtrlButton_SetImage($hWnd, $sImageFile, $iIconID = -1, $bLarge = False)
  336. Local $hImage, $hPrevImage
  337. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  338. If StringUpper(StringMid($sImageFile, StringLen($sImageFile) - 2)) = "BMP" Then
  339. If BitAND(_WinAPI_GetWindowLong($hWnd, $__BUTTONCONSTANT_GWL_STYLE), $BS_BITMAP) = $BS_BITMAP Then
  340. $hImage = _WinAPI_LoadImage(0, $sImageFile, 0, 0, 0, BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION))
  341. If Not $hImage Then Return SetError(-1, -1, False)
  342. $hPrevImage = _SendMessage($hWnd, $BM_SETIMAGE, 0, $hImage)
  343. If $hPrevImage Then
  344. If Not _WinAPI_DeleteObject($hPrevImage) Then _WinAPI_DestroyIcon($hPrevImage)
  345. EndIf
  346. _WinAPI_UpdateWindow($hWnd) ; force a WM_PAINT
  347. Return True
  348. EndIf
  349. Else
  350. If $iIconID = -1 Then
  351. $hImage = _WinAPI_LoadImage(0, $sImageFile, 1, 0, 0, BitOR($LR_LOADFROMFILE, $LR_CREATEDIBSECTION))
  352. If Not $hImage Then Return SetError(-1, -1, False)
  353. $hPrevImage = _SendMessage($hWnd, $BM_SETIMAGE, 1, $hImage)
  354. If $hPrevImage Then
  355. If Not _WinAPI_DeleteObject($hPrevImage) Then _WinAPI_DestroyIcon($hPrevImage)
  356. EndIf
  357. _WinAPI_UpdateWindow($hWnd) ; force a WM_PAINT
  358. Return True
  359. Else
  360. Local $tIcon = DllStructCreate("handle Handle")
  361. Local $iRet
  362. If $bLarge Then
  363. $iRet = _WinAPI_ExtractIconEx($sImageFile, $iIconID, $tIcon, 0, 1)
  364. Else
  365. $iRet = _WinAPI_ExtractIconEx($sImageFile, $iIconID, 0, $tIcon, 1)
  366. EndIf
  367. If Not $iRet Then Return SetError(-1, -1, False)
  368. $hPrevImage = _SendMessage($hWnd, $BM_SETIMAGE, 1, DllStructGetData($tIcon, "Handle"))
  369. If $hPrevImage Then
  370. If Not _WinAPI_DeleteObject($hPrevImage) Then _WinAPI_DestroyIcon($hPrevImage)
  371. EndIf
  372. _WinAPI_UpdateWindow($hWnd) ; force a WM_PAINT
  373. Return True
  374. EndIf
  375. EndIf
  376. Return False
  377. EndFunc ;==>_GUICtrlButton_SetImage
  378. ; #FUNCTION# ====================================================================================================================
  379. ; Author ........: Gary Frost
  380. ; Modified.......:
  381. ; ===============================================================================================================================
  382. Func _GUICtrlButton_SetImageList($hWnd, $hImage, $iAlign = 0, $iLeft = 1, $iTop = 1, $iRight = 1, $iBottom = 1)
  383. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  384. If $iAlign < 0 Or $iAlign > 4 Then $iAlign = 0
  385. Local $tBUTTON_IMAGELIST = DllStructCreate($tagBUTTON_IMAGELIST)
  386. DllStructSetData($tBUTTON_IMAGELIST, "ImageList", $hImage)
  387. DllStructSetData($tBUTTON_IMAGELIST, "Left", $iLeft)
  388. DllStructSetData($tBUTTON_IMAGELIST, "Top", $iTop)
  389. DllStructSetData($tBUTTON_IMAGELIST, "Right", $iRight)
  390. DllStructSetData($tBUTTON_IMAGELIST, "Bottom", $iBottom)
  391. DllStructSetData($tBUTTON_IMAGELIST, "Align", $iAlign)
  392. Local $bEnabled = _GUICtrlButton_Enable($hWnd, False)
  393. Local $iRet = _SendMessage($hWnd, $BCM_SETIMAGELIST, 0, $tBUTTON_IMAGELIST, 0, "wparam", "struct*") <> 0
  394. _GUICtrlButton_Enable($hWnd)
  395. If Not $bEnabled Then _GUICtrlButton_Enable($hWnd, False)
  396. Return $iRet
  397. EndFunc ;==>_GUICtrlButton_SetImageList
  398. ; #FUNCTION# ====================================================================================================================
  399. ; Author ........: Gary Frost
  400. ; Modified.......:
  401. ; ===============================================================================================================================
  402. Func _GUICtrlButton_SetNote($hWnd, $sNote)
  403. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  404. Local $tNote = _WinAPI_MultiByteToWideChar($sNote)
  405. Return _SendMessage($hWnd, $BCM_SETNOTE, 0, $tNote, 0, "wparam", "struct*") <> 0
  406. EndFunc ;==>_GUICtrlButton_SetNote
  407. ; #FUNCTION# ====================================================================================================================
  408. ; Author ........: Gary Frost
  409. ; Modified.......:
  410. ; ===============================================================================================================================
  411. Func _GUICtrlButton_SetShield($hWnd, $bRequired = True)
  412. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  413. Return _SendMessage($hWnd, $BCM_SETSHIELD, 0, $bRequired) = 1
  414. EndFunc ;==>_GUICtrlButton_SetShield
  415. ; #FUNCTION# ====================================================================================================================
  416. ; Author ........: Gary Frost
  417. ; Modified.......:
  418. ; ===============================================================================================================================
  419. Func _GUICtrlButton_SetSize($hWnd, $iWidth, $iHeight)
  420. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  421. If Not _WinAPI_IsClassName($hWnd, $__BUTTONCONSTANT_ClassName) Then Return SetError(-1, -1, False)
  422. Local $hParent = _WinAPI_GetParent($hWnd)
  423. If Not $hParent Then Return SetError(-1, -1, False)
  424. Local $aPos = WinGetPos($hWnd)
  425. If Not IsArray($aPos) Then Return SetError(-1, -1, False)
  426. Local $tPoint = DllStructCreate($tagPOINT)
  427. DllStructSetData($tPoint, "X", $aPos[0])
  428. DllStructSetData($tPoint, "Y", $aPos[1])
  429. If Not _WinAPI_ScreenToClient($hParent, $tPoint) Then Return SetError(-1, -1, False)
  430. Local $iRet = WinMove($hWnd, "", DllStructGetData($tPoint, "X"), DllStructGetData($tPoint, "Y"), $iWidth, $iHeight)
  431. Return SetError($iRet - 1, $iRet - 1, $iRet <> 0)
  432. EndFunc ;==>_GUICtrlButton_SetSize
  433. ; #FUNCTION# ====================================================================================================================
  434. ; Author ........: Gary Frost
  435. ; Modified.......:
  436. ; ===============================================================================================================================
  437. Func _GUICtrlButton_SetSplitInfo($hWnd, $hImlGlyph = -1, $iSplitStyle = $BCSS_ALIGNLEFT, $iWidth = 0, $iHeight = 0)
  438. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  439. Local $tSplitInfo = DllStructCreate($tagBUTTON_SPLITINFO), $iMask = 0
  440. If $hImlGlyph <> -1 Then
  441. $iMask = BitOR($iMask, $BCSIF_GLYPH)
  442. DllStructSetData($tSplitInfo, "himlGlyph", $hImlGlyph)
  443. EndIf
  444. $iMask = BitOR($iMask, $BCSIF_STYLE)
  445. If BitAND($iSplitStyle, $BCSS_IMAGE) = $BCSS_IMAGE Then $iMask = BitOR($iMask, $BCSIF_IMAGE)
  446. DllStructSetData($tSplitInfo, "uSplitStyle", $iSplitStyle)
  447. If $iWidth > 0 Or $iHeight > 0 Then
  448. $iMask = BitOR($iMask, $BCSIF_SIZE)
  449. DllStructSetData($tSplitInfo, "X", $iWidth)
  450. DllStructSetData($tSplitInfo, "Y", $iHeight)
  451. EndIf
  452. DllStructSetData($tSplitInfo, "mask", $iMask)
  453. Return _SendMessage($hWnd, $BCM_SETSPLITINFO, 0, $tSplitInfo, 0, "wparam", "struct*") <> 0
  454. EndFunc ;==>_GUICtrlButton_SetSplitInfo
  455. ; #FUNCTION# ====================================================================================================================
  456. ; Author ........: Gary Frost
  457. ; Modified.......:
  458. ; ===============================================================================================================================
  459. Func _GUICtrlButton_SetState($hWnd, $bHighlighted = True)
  460. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  461. _SendMessage($hWnd, $BM_SETSTATE, $bHighlighted)
  462. EndFunc ;==>_GUICtrlButton_SetState
  463. ; #FUNCTION# ====================================================================================================================
  464. ; Author ........: Gary Frost
  465. ; Modified.......:
  466. ; ===============================================================================================================================
  467. Func _GUICtrlButton_SetStyle($hWnd, $iStyle)
  468. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  469. _SendMessage($hWnd, $BM_SETSTYLE, $iStyle, True)
  470. _WinAPI_UpdateWindow($hWnd) ; force a WM_PAINT
  471. EndFunc ;==>_GUICtrlButton_SetStyle
  472. ; #FUNCTION# ====================================================================================================================
  473. ; Author ........: Gary Frost
  474. ; Modified.......:
  475. ; ===============================================================================================================================
  476. Func _GUICtrlButton_SetText($hWnd, $sText)
  477. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  478. If _WinAPI_IsClassName($hWnd, $__BUTTONCONSTANT_ClassName) Then Return _WinAPI_SetWindowText($hWnd, $sText)
  479. EndFunc ;==>_GUICtrlButton_SetText
  480. ; #FUNCTION# ====================================================================================================================
  481. ; Author ........: Gary Frost
  482. ; Modified.......:
  483. ; ===============================================================================================================================
  484. Func _GUICtrlButton_SetTextMargin($hWnd, $iLeft = 1, $iTop = 1, $iRight = 1, $iBottom = 1)
  485. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  486. Local $tRECT = DllStructCreate($tagRECT)
  487. DllStructSetData($tRECT, "Left", $iLeft)
  488. DllStructSetData($tRECT, "Top", $iTop)
  489. DllStructSetData($tRECT, "Right", $iRight)
  490. DllStructSetData($tRECT, "Bottom", $iBottom)
  491. Return _SendMessage($hWnd, $BCM_SETTEXTMARGIN, 0, $tRECT, 0, "wparam", "struct*") <> 0
  492. EndFunc ;==>_GUICtrlButton_SetTextMargin
  493. ; #FUNCTION# ====================================================================================================================
  494. ; Author ........: Gary Frost
  495. ; Modified.......:
  496. ; ===============================================================================================================================
  497. Func _GUICtrlButton_Show($hWnd, $bShow = True)
  498. If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
  499. If _WinAPI_IsClassName($hWnd, $__BUTTONCONSTANT_ClassName) Then
  500. If $bShow Then
  501. Return _WinAPI_ShowWindow($hWnd, @SW_SHOW)
  502. Else
  503. Return _WinAPI_ShowWindow($hWnd, @SW_HIDE)
  504. EndIf
  505. EndIf
  506. EndFunc ;==>_GUICtrlButton_Show