Here's a proof-of-concept stdlib function for creating split buttons (drop down buttons). Needs more options built in (changing the glyph, styles, etc) but its a start... Enjoy
Microsoft wrote:The Split Button is a composite control with which the user can select a default value bound to a primary button, or select from a list of mutually exclusive values displayed in a drop-down list bound to a secondary button.
SplitButton ( hButton [, GlyphSize, MenuName ] )Medium wrote:A split button has a default action followed by a divider line and an arrow. When the arrow is clicked it exposes a drop-down list of alternative actions. This pattern is used when there are many possible actions but only one primary action.
- hButton = hWnd of button to turn into SplitButton
- GlyphSize = size of down arrow glyph (default: 16)
- MenuName = name of menu to call when clicked (default: SplitButton_Menu)
Issues/Requirements:
- statically saved hwnd of button from first call needs turned into array... for now only one button can be a SplitButton
- will conflict with other code using WM_Notify OnMessage()
- missing features from API for glyph size, imagelist, styles, etc...
- Requires Vista+, unsupported on XP
Function:
Code: Select all
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
Code: Select all
Menu, SplitButton_Menu, Add, First Item, DoNothing
Menu, SplitButton_Menu, Add, Second Item, DoNothing
Gui, Add, Button, w160 h80 hwndhButton, Button
SplitButton(hButton)
Gui, Show
DoNothing:
Return
Code: Select all
;Demo of SplitButton()
#Include SplitButton.ahk
Who = Google
Menu, Menu, Add, Google, Menu
Menu, Menu, Default, Google
Menu, Menu, Add, Yahoo, Menu
Menu, Menu, Add, Bing, Menu
IfNotExist, %A_Temp%\google_favicon.ico
UrlDownloadToFile, https://www.google.com/favicon.ico, %A_Temp%\google_favicon.ico
IfNotExist, %A_Temp%\yahoo_favicon.ico
UrlDownloadToFile, https://www.yahoo.com/favicon.ico, %A_Temp%\yahoo_favicon.ico
IfNotExist, %A_Temp%\bing_favicon.ico
UrlDownloadToFile, https://www.bing.com/favicon.ico, %A_Temp%\bing_favicon.ico
Menu, Menu, Icon, Google, %A_Temp%\google_favicon.ico
Menu, Menu, Icon, Yahoo, %A_Temp%\yahoo_favicon.ico
Menu, Menu, Icon, Bing, %A_Temp%\bing_favicon.ico
PartNumber := InputBox("Internet search...", "Search for:")
PartNumber = %PartNumber%
If (PartNumber = "")
ExitApp
Run, "https://www.%who%.com/#q=%PartNumber%"
ExitApp
Return
Menu:
Who := A_ThisMenuItem
GuiControl, , %hOK%, Search %Who%
Menu, Menu, Default, %Who%
Return
InputBox(title, text, inputValue = "", owner=0,isPassword=0){
Global
GuiID := "InputBox" ; If you change, also change the subroutines below for #GuiEscape & #GuiClose
If( owner <> 0 ) {
Gui %owner%:+Disabled
Gui %GuiID%:+Owner%owner%
}
Gui, %GuiID%:+AlwaysOnTop -MinimizeBox -MaximizeBox +HwndGuiHwnd +E0x400 -0x80000 +Label%GuiID%
Gui, %GuiID%:+LastFound
Gui, %GuiID%:Color, White
Gui, %GuiID%:Add, Text, x-5 y148 w10 h10 -BackgroundTrans hwndGray -Border +0x2000000
Gui, %GuiID%:Add, Progress, x-5 y147 w10 h3 BackgroundDFDFDF hwndDarkGrayLine
Gui, %GuiID%:Font, s12 w400, Segoe UI
Gui, %GuiID%:Add, Text, x20 y20 w320 c003399 BackgroundTrans, %text%
Gui, %GuiID%:Font, s9 w0, Segoe UI
Gui, %GuiID%:Add, Edit, % "x12 y+23 w333 R1 hwndhMyCombo -Sort v_cInput_Value" . ((isPassword <> 0) ? " Password":"")
Gui, %GuiID%:Add, Button, x100 y+28 w120 h40 gCInputButton Default hwndhOK, % "Search Google" ;+0x0C for BS_SPLITBUTTON doesn't work here
SplitButton(hOK,24,"Menu")
Gui, %GuiID%:Add, Button, x228 y+-40 w120 h40 gCInputButtonCancel, % "Cancel"
Gui %GuiID%:Show,Hide,%title%
WinGetPos, X, Y, Width, Height
GuiControl, %GuiID%:Move, % DarkGrayLine, % "w" Width+10 " y" Height-87
GuiControl, %GuiID%:Move, % Gray, % "w" Width+10 " h" Height-100 " y" Height-86
Control, ExStyle, -0x20000, msctls_progress321
Gui %GuiID%:Show
Loop
{
If( _CInput_Result )
Break
Sleep, 10
}
If( owner <> 0 )
Gui %owner%:-Disabled
Gui, %GuiID%:Submit, Hide
if InStr(_CInput_Result, "Search") {
Result := _cInput_Value
} else {
Result := ""
}
_cInput_Value := ""
_CInput_Result := ""
Gui %GuiID%:Destroy
Return Result
CInputButton:
StringReplace _CInput_Result, A_GuiControl, &,, All
Return
InputBoxGuiEscape:
InputBoxGuiClose:
_CInput_Result := "Close"
ExitApp
Return
cInputButtonCancel:
ExitApp
Return
}