SplitButton() Two of them

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
nodes[0]
Posts: 5
Joined: 03 Nov 2021, 22:14

SplitButton() Two of them

Post by nodes[0] » 23 Apr 2023, 17:13

Hello everybody.

I'm using the SplitButton() lib, and struggle in getting two of them working. The code from evilC would solve it, but then the function GuiButtonIcon() doesn't work straightaway. I thought the parameter MenuName assign the dependent menu to its button, but it's like the first menu gets never created. Am I missing something here? Won't I get around arrays?

Code: Select all

#NoEnv
; #Warn
#SingleInstance force
SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1



Gui Main:New, +LabelMain +hWndhMainWnd +Resize +MinSize +Theme +LastFound
Gui Main:Margin, 6, 6

Menu BtnPasteMenu, Add, Btn Paste Menu Item 1, BtnCtrlEvent
Menu BtnPasteMenu, Add, Second Item of BtnPasteMenu, BtnCtrlEvent
Gui Main:Add, Button, xm ym w210 r1.5 hwndhBtnPaste vBtnPaste gBtnCtrlEvent, % " &Paste"
; GuiButtonIcon(hBtnPaste, "CWAppRes.dll", 11, "s16 a1 r6")
SplitButton(hBtnPaste, 16, "BtnPasteMenu")

Menu BtnCreateMenu, Add, Btn Create Menu Item 1, BtnCtrlEvent
Menu BtnCreateMenu, Add, Second Item of BtnCreateMenu, BtnCtrlEvent
Gui Main:Add, Button, x+0 yp w210 r1.5 hwndhBtnCreate vBtnCreate gBtnCtrlEvent, % " &Create"
; GuiButtonIcon(hBtnCreate, "CWAppRes.dll", 11, "s16 a1 r6")
SplitButton(hBtnCreate, 16, "BtnCreateMenu")
Gui Main:Show, AutoSize, SplitButton²
Return

BtnCtrlEvent:
  OutputDebug, % "[" . A_Now . "] Do nothing."
Return

SplitButton(hButton, GlyphSize=16, Menu="", hDontUse="") {
 Static     _ := OnMessage(0x4E, "SplitButton") ;WM_NOTIFY
 Static Menu_ := "SplitButton_Menu"
 Static hButton_
 If (Menu=0x4E)
 {
  hCtrl := NumGet(GlyphSize+0, 0, "Ptr") ;-> lParam -> NMHDR -> hCtrl
  If (hCtrl = hButton_) ;BCN_DROPDOWN for SplitButton
  {
   id := NumGet(GlyphSize+0, A_PtrSize * 2, "uInt")
   If (id = 0xFFFFFB20)
   {
    ControlGetPos, cX, cY, cW, cH,, ahk_id %hButton_%
    Menu, %Menu_%, Show, % cX+1, % cY + cH
   }
  }
 }
 Else ;Initialize
 {
  If (Menu <> "")
   Menu_ := Menu
  hButton_ := hButton
  Winset,   Style, +0x0C, ahk_id %hButton%          ;BS_SPLITBUTTON
  VarSetCapacity(   pBUTTON_SPLITINFO,  40, 0)
  NumPut(8,         pBUTTON_SPLITINFO,   0, "Int")  ;set glyph size
  NumPut(GlyphSize, pBUTTON_SPLITINFO,  4 + A_PtrSize * 2, "Int")
  SendMessage, BCM_SETSPLITINFO := 0x1607, 0, &pBUTTON_SPLITINFO, , ahk_id %hButton%
  Return
 }
}

 ;;parameters need to be expanded to cover these options:
 ;;BUTTON_SPLITINFO struct   ;INFO mask flags        ;STYLE flags
 ;;  UINT       mask;        ;BCSIF_GLYPH := 0x0001  ;BCSS_NOSPLIT         := 0x0001
 ;;  HIMAGELIST himlGlyph;   ;BCSIF_IMAGE := 0x0002  ;BCSS_STRETCH         := 0x0002
 ;;  UINT       uSplitStyle; ;BCSIF_STYLE := 0x0004  ;BCSS_ALIGNLEFT       := 0x0004
 ;;  SIZE       size;        ;BCSIF_SIZE  := 0x0008  ;BCSS_IMAGE           := 0x0008
Cheers.

Return to “Ask for Help (v1)”