Hi just me,
I'm still very much enjoying this class. Fantastic work!
Is there any way to create on the same Gui different series of independent buttons? To illustrate what I mean, here is a simple example:
- I set the "pressed" option to a blue button background
- If I press button 1, it becomes active and its background becomes blue.
- If I now press button 2, it now becomes the active button and becomes blue
AND button 1 goes back to normal.
- Would it be possible to have a button 3 on the same gui that when pressed doesn't make buttons 1 and 2 go back to normal (i.e., if I press button 3 while button 2 is blue and active, button 2 stays blue and active)?
My guess would be that, if it's possible, I would have to put button 3 in a different array of buttons than buttons 1 and 2. Is that possible? If yes, would I need to use a different Create function with its own array for button 3?
I tried doing that (by adding a Create2 function and modifying the "Create a HBITMAP handle from the bitmap and add it to the array" and the "Create the ImageList" sections of the code) but couldn't get it to work. I tried doing what's below, but I don't know if that's even supposed to work or if I did something wrong (I can't seem to add text formatting to the code below to show what I changed so I marked with *** the lines on which I made changes and added "2" in an attempt to create a new array of buttons):
Code: Select all
Create2(HWND, Options*) {
...
...
; Create a HBITMAP handle from the bitmap and add it to the array
DllCall("Gdiplus.dll\GdipCreateHBITMAPFromBitmap", "Ptr", PBITMAP, "PtrP", HBITMAP, "UInt", 0X00FFFFFF)
***This.BitMaps2 := HBITMAP
; Free resources
DllCall("Gdiplus.dll\GdipDisposeImage", "Ptr", PBITMAP)
DllCall("Gdiplus.dll\GdipDeleteBrush", "Ptr", PBRUSH)
DllCall("Gdiplus.dll\GdipDeleteStringFormat", "Ptr", HFORMAT)
DllCall("Gdiplus.dll\GdipDeleteGraphics", "Ptr", PGRAPHICS)
; Add the bitmap to the array
}
; Now free the font object
DllCall("Gdiplus.dll\GdipDeleteFont", "Ptr", PFONT)
; ----------------------------------------------------------------------------------------------------------------
; Create the ImageList
***HIL2 := DllCall("Comctl32.dll\ImageList_Create"
, "UInt", BtnW, "UInt", BtnH, "UInt", ILC_COLOR32, "Int", 6, "Int", 0, "Ptr")
***Loop, % (This.BitMaps2.MaxIndex() > 1 ? 6 : 1) {
***HBITMAP := This.BitMaps2.HasKey(A_Index) ? This.BitMaps2[A_Index] : This.BitMaps2.1
***DllCall("Comctl32.dll\ImageList_Add", "Ptr", HIL2, "Ptr", HBITMAP, "Ptr", 0)
}
; Create a BUTTON_IMAGELIST structure
***VarSetCapacity(BIL2, 20 + A_PtrSize, 0)
***NumPut(HIL2, BIL2, 0, "Ptr")
***Numput(BUTTON_IMAGELIST_ALIGN_CENTER, BIL2, A_PtrSize + 16, "UInt")
; Hide buttons's caption
ControlSetText, , , ahk_id %HWND%
Control, Style, +%BS_BITMAP%, , ahk_id %HWND%
; Assign the ImageList to the button
SendMessage, %BCM_SETIMAGELIST%, 0, 0, , ahk_id %HWND%
***SendMessage, %BCM_SETIMAGELIST%, 0, % &BIL2, , ahk_id %HWND%
; Free the bitmaps
This.FreeBitmaps()