Page 1 of 1

Posted: Fri Jul 05, 2002 5:07 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.

I am using a combination of API and KeyboardShortcuts and it's getting a little messy. Could anyone help
translate this all into PureBasic only (for portability) because I need the events happening in the
specific gadgets and I keep getting the testing wrong (I don't know what the heck I am doing any more)

Code: Select all

#CategoryTree = 20
#ListBox = 21

#F1Code = 100
#DelCode = 101

getasynckeystate_(#VK_UP)
getasynckeystate_(#VK_DOWN)
getasynckeystate_(#VK_RETURN)

WinW = 806
WinH = 602

WinX = (GetSystemMetrics_(#SM_CXSCREEN) - WinW) / 2
WinY = (GetSystemMetrics_(#SM_CYSCREEN) - WinH) / 2

hWnd = OpenWindow(0, Random(WinX), Random(WinY), WinW, WinH, 0, Version$)

  AddKeyboardShortcut(0, #PB_Shortcut_F1, #F1Code)
  AddKeyboardShortcut(0, #PB_Shortcut_Delete, #DelCode)
then I check for them all here

Code: Select all

Repeat
EventID = WaitWindowEvent()
  ;- Main window events that don't fit anywhere else
  If EventID = #PB_EventCloseWindow And SaveNow = 0
    QuitValue = 1
  ElseIf EventID = #PB_EventCloseWindow And SaveNow = 1
    Fill_Statusbar(0, "Data changed recently, Save now?")
    Code = MessageRequester("Data Changed", "Still Exit?", #MB_ICONQUESTION | #PB_MessageRequester_YesNo)
      If Code = 6
        QuitValue = 1
      EndIf
  EndIf
  ;- If ENTER key is pressed in the search target box
  If GetGadgetText(#SearchBox)  "" And GetFocus_()  0 And getasynckeystate_(#VK_RETURN) = -32767
    Gosub Find_First
  EndIf
  ;- Yet another test of this damned keyboard shortcuts
  If EventID = #PB_EventMenu
    Select EventMenuID()
      Case #F1Code
        Gosub Help_Wanted
      Case #DelCode
        Gosub Delete_Record
    EndSelect
  EndIf
  ;- Check for events in the window from gadgets
  If EventID = #PB_EventGadget 
    Select EventGadgetID()
      Case #CategoryTree         ; TreeGadget
        ;- Up, down and left click events in the tree        
        If GetFocus_()  0 And getasynckeystate_(#VK_UP) = -32767
          Gosub Display_Categories
        ElseIf GetFocus_()  0 And getasynckeystate_(#VK_DOWN) = -32767
          Gosub Display_Categories
        EndIf
        If EventType() = #PB_EventType_LeftClick
          Gosub Display_Categories
        EndIf  
        ;- Up, down and left click events in the ListIcongadget
      Case #ListBox         ; ListIconGadget
        If GetFocus_()  0 And getasynckeystate_(#VK_UP) = -32767
          Create_Web_Report()
        ElseIf GetFocus_()  0 And getasynckeystate_(#VK_DOWN) = -32767
          Create_Web_Report()
        EndIf
        If EventType() = #PB_EventType_LeftClick And GetGadgetState(#ListBox)  -1
          Create_Web_Report()
        EndIf
        ;- Special event, left double click to go to edit mode on highlighted record
        If EventType() = #PB_EventType_LeftDoubleClick And GetGadgetState(#ListBox)  -1
          Mode$ = "Edit"
          Gosub Add_Edit_Form
        EndIf
        ;- Special event, right double click to add a new record to the end of the current list
        If EventType() = #PB_EventType_RightDoubleClick
          Mode$ = "Add"
          Gosub Add_Edit_Form
        EndIf
    EndSelect
  EndIf
Until Quit_Value = 1
End
As it is, my program and code works great but for portability to other OS (I'm helping someone do this
stuff over for Unix), I need the PB shortcut methods and not the api.

Hope someone can help me put them i the right order :)


Fangles

Posted: Mon Jul 08, 2002 4:37 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.

Hi Fangles,
sorry but at this point it's not possible to make a PB only Event handler.
For now you need Win-API because of GetFocus_().
Don't know if Fred will add GetFocus() to PureBasic for the next version.

You could change getasynckeystate_(#VK_UP), getasynckeystate_(#VK_DOWN) and getasynckeystate_(#VK_RETURN) with AddKeyboardShortcut (#PB_Shortcut_Up, #PB_Shortcut_Down and #PB_Shortcut_Return) but that's it.

I would suggest to leave all what you have done now the way it is and simply add:

Code: Select all

CompilerSelect #OS
  CompilerCase #Linux    
    ; some Linux specific code
    ; put your own Linux event handler in here (maybe LinuxAPI needed...)
 
  CompilerCase #Windows ;don't know if #Windows is the right constant, it's not in the docs...
    ; some Windows specific code
    ; put your own Windows event handler in here (WinAPI)
 
CompilerEndSelect

In this way you can be sure that your Windows version (event handler) of your app is still working.
I don't know if these Compiler directives are working or not, but according the help file it should.


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.