Gadgets: Colors, Arrows, Esc, Return And Tab

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Gadgets: Colors, Arrows, Esc, Return And Tab

Post by BackupUser »

Restored from previous forum. Originally posted by Manolo.

Hi to all,
This is only for beginners or for all.

Code: Select all

;Edited for Manolo with the colaboration of El_Choni and others. (Thanks to all)
;Aclarations tecla in spanish is key in English

;REPLY TO THE NEXT QUESTIONS:

;How can work with arrows up and down in gadgets??? How can change the colors in gadget focused???
;How can change the value of Return for Tab???. See the solution down:

;---------------------------------------------------------

Global Frente.l, Fondo.l, Esc.l,MyGadget.l

Procedure GetKey()

  If GetAsyncKeyState_(#VK_RETURN)=-32767 
    tecla = 13
  ElseIf GetAsyncKeyState_(#VK_ESCAPE)0
    tecla = 27  
  ElseIf GetAsyncKeyState_(#VK_UP)0
    tecla = 38
  ElseIf GetAsyncKeyState_(#VK_DOWN)0
    tecla = 40
  EndIf 
  Select tecla
    Case #VK_RETURN ;push return
      keybd_event_(#VK_RETURN, 0, #KEYEVENTF_KEYUP, 0)          
      keybd_event_(#VK_TAB,0,0,0) ; TAB key down.
      keybd_event_(#VK_TAB,0,#KEYEVENTF_KEYUP,0);free TAB
    Case #VK_UP ; Push UP Arrow
      keybd_event_(#VK_UP, 0, #KEYEVENTF_KEYUP, 0)
      keybd_event_(#VK_SHIFT,0,0,0)
      keybd_event_(#VK_TAB,0,0,0) ; TAB key down.
      
      keybd_event_(#VK_TAB,0,#KEYEVENTF_KEYUP,0)
      keybd_event_(#VK_SHIFT,0,#KEYEVENTF_KEYUP,0)      
    Case #VK_DOWN ; Push DOWN Arrow
      keybd_event_(#VK_DOWN, 0, #KEYEVENTF_KEYUP, 0)
      keybd_event_(#VK_TAB,0,0,0) ; TAB key down.
      keybd_event_(#VK_TAB,0,#KEYEVENTF_KEYUP,0)
    Case #VK_ESCAPE; Push ESC
      keybd_event_(#VK_ESCAPE, 0, #KEYEVENTF_KEYUP, 0) 
      Esc=1; Return value for close Window or others
  EndSelect
  ProcedureReturn MyGadget
EndProcedure




Procedure Colorear(WindowID, Message, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents 
  Select Message
  
  Case #WM_CTLCOLOREDIT
    Select lparam

    Case GadgetID(MyGadget)
      SetBkMode_(wParam,#TRANSPARENT)
      SetTextColor_(wParam, Frente)
      Result=CreateSolidBrush_(Fondo);Solid background color

    EndSelect
  EndSelect
  
  ProcedureReturn  Result
EndProcedure


If OpenWindow(0,100,150,450,200,#PB_Window_SystemMenu,"Gadgets: Colors, Arrows, Esc, Return And Tab")
  CreateGadgetList(WindowID())
  StringGadget(1,20,20,100,21,"")
  StringGadget(2,20,40,100,21,"")
  StringGadget(3,20,60,100,21,"")
            oldMyGadget = MyGadget
            Frente = 8454143 ;Front Color
            Fondo = 16744448 ;Background Color
  SetWindowCallback(@Colorear())
  ActivateGadget(1)
  
  Repeat
    EventID=WaitWindowEvent()
    Select EventID
        Case #PB_EventGadget
                EventGadgetID = EventGadgetID()
                If EventGadgetID>0 And EventGadgetIDMyGadget; this is neccesary for not persistent colors in the gadgets
                     RedrawWindow_(GadgetID(oldMyGadget), 0, 0, #RDW_INVALIDATE|#RDW_INTERNALPAINT|#RDW_ERASE)
                     RedrawWindow_(GadgetID(EventGadgetID), 0, 0, #RDW_INVALIDATE|#RDW_INTERNALPAINT|#RDW_ERASE)
                     oldMyGadget = MyGadget
                  EndIf
                EndIf
                      Select EventGadgetID
                      Case 1
                      ;you code
                      Case 2
                      ;you code
                      Case 3
                      ; you code
                      EndSelect

       Default
          If GetKey()oldMyGadget
            ActivateGadget(MyGadget)
          EndIf
          GetKey()
       EndSelect 

  Until EventID=#PB_EventCloseWindow Or Esc=1
EndIf

Regards,
Manolo