Arrows to select buttons and "Enter" (?)
Posted: Wed Jan 05, 2022 11:07 pm
I want to move the button selection and press "Enter" to simulate pressing the button.
It's not working now.
It's not working now.
Code: Select all
EnableExplicit
Enumeration #PB_Event_FirstCustomValue
#EvenementDebutAction
#Event1
#Event2
EndEnumeration
#Window = 0
#Menu = 0
Define hMenu, mNext, mPrev, mEnter, hbtn, tmp, i
If OpenWindow(#Window, 0, 0, 220, 150, "Пример...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget (0, 10, 10, 200, 30, "Button1", #PB_Button_Default)
ButtonGadget (1, 10, 50, 200, 30, "Button2")
ButtonGadget (2, 10, 90, 200, 30, "Button3")
hMenu = CreatePopupMenu(#Menu)
mNext = 0
mPrev = 1
mEnter = 2
If hMenu
MenuItem(mNext, "Next" + #TAB$ + "->")
AddKeyboardShortcut(#Window, #PB_Shortcut_Right, mNext)
AddKeyboardShortcut(#Window, #PB_Shortcut_Down, mNext)
MenuItem(mPrev, "Prev" + #TAB$ + "<-")
AddKeyboardShortcut(#Window, #PB_Shortcut_Left, mPrev)
AddKeyboardShortcut(#Window, #PB_Shortcut_Up, mPrev)
MenuItem(mEnter, "Enter" + #TAB$ + "Enter")
AddKeyboardShortcut(#Window, #PB_Shortcut_Return, mEnter)
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_RightClick
DisplayPopupMenu(#Menu, WindowID(#Window))
Case #PB_Event_Menu
Select EventMenu()
Case mNext
For i = 0 To 2
hbtn = GadgetID(i)
tmp = GetWindowLongPtr_(hbtn, #GWL_STYLE)
If tmp & #BS_DEFPUSHBUTTON
; MessageRequester("id=" + Str(i), "hbtn=" + Str(hbtn) + ", tmp=" + Str(tmp)+ ", tmp2=" + Str(tmp ! #BS_DEFPUSHBUTTON))
SetWindowLongPtr_(hbtn, #GWL_STYLE, tmp ! #BS_DEFPUSHBUTTON)
If i+1 > 2
i = -1
EndIf
SetWindowLongPtr_(GadgetID(i+1), #GWL_STYLE, tmp)
Break
EndIf
Next
Case mPrev
For i = 0 To 2
hbtn = GadgetID(i)
tmp = GetWindowLongPtr_(hbtn, #GWL_STYLE)
If tmp & #BS_DEFPUSHBUTTON
; MessageRequester("id=" + Str(i), "hbtn=" + Str(hbtn) + ", tmp=" + Str(tmp)+ ", tmp2=" + Str(tmp ! #BS_DEFPUSHBUTTON))
SetWindowLongPtr_(hbtn, #GWL_STYLE, tmp ! #BS_DEFPUSHBUTTON)
If i-1 < 0
i = 3
EndIf
SetWindowLongPtr_(GadgetID(i-1), #GWL_STYLE, tmp)
Break
EndIf
Next
Case mEnter
For i = 0 To 2
hbtn = GadgetID(i)
If GetWindowLongPtr_(hbtn, #GWL_STYLE) & #BS_DEFPUSHBUTTON
; ???
PostEvent(#EvenementDebutAction + i, 0, 1, #PB_EventType_FirstCustomValue, 10)
Break
EndIf
Next
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case 0, #EvenementDebutAction
MessageRequester("", "1")
Case 1, #Event1
MessageRequester("", "2")
Case 2, #Event2
MessageRequester("", "3")
EndSelect
Case #PB_Event_CloseWindow
CloseWindow(#Window)
End
EndSelect
ForEver
EndIf