Tabulator im EditorGadget verhindern

Für allgemeine Fragen zur Programmierung mit PureBasic.
Cläusel
Beiträge: 25
Registriert: 14.08.2010 21:26
Computerausstattung: PB5.73 Win10 64bit
Wohnort: Oberland

Tabulator im EditorGadget verhindern

Beitrag von Cläusel »

Hallo zusammen,

ich möchte gerne mittels der TAB-Taste zwischen mehreren EditorGadgets springen. Das funktioniert auch soweit,
jedoch kann nicht verhindern, das der TAB noch im Editor übernommen wird. Hat da jemand eine Rat für mich?

(AddKeyboardShortcut für TAB funktioniert auch nicht...)

Code: Alles auswählen

Enumeration FormWindow
  #Window_0
EndEnumeration

Enumeration FormGadget
  #Editor_0
  #Editor_1
  #Editor_2
EndEnumeration

Procedure OpenWindow_0(x = 0, y = 0, width = 383, height = 240)
  OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(#Editor_0, 2, 2, 378, 76)
  EditorGadget(#Editor_1, 2, 80, 378, 76)
  EditorGadget(#Editor_2, 2, 158, 378, 76)
EndProcedure

OpenWindow_0()

Repeat
     Select WaitWindowEvent() 
     Case #WM_KEYDOWN
          If GetAsyncKeyState_(#VK_TAB)
               Select GetActiveGadget()
               Case #Editor_0:SetActiveGadget(#Editor_1)
               Case #Editor_1:SetActiveGadget(#Editor_2)
               Case #Editor_2:SetActiveGadget(#Editor_0)
               EndSelect
          EndIf
     Case #PB_Event_CloseWindow 
          End
     EndSelect
ForEver
Gruß Claus
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Re: Tabulator im EditorGadget verhindern

Beitrag von ts-soft »

Code: Alles auswählen

EnableExplicit

Enumeration FormWindow
  #Window_0
EndEnumeration

Enumeration FormGadget
  #Editor_0
  #Editor_1
  #Editor_2
EndEnumeration

Procedure OpenWindow_0(x = 0, y = 0, width = 383, height = 240)
  OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(#Editor_0, 2, 2, 378, 76)
  EditorGadget(#Editor_1, 2, 80, 378, 76)
  EditorGadget(#Editor_2, 2, 158, 378, 76)
EndProcedure

Procedure WinCallback(hwnd, msg, wParam, lParam)
  Protected result = #PB_ProcessPureBasicEvents
  Protected *pMSGFILTER.MSGFILTER
 
  Select msg
    Case #WM_NOTIFY
      *pMSGFILTER = lParam
      Select *pMSGFILTER\nmhdr\code
        Case #EN_MSGFILTER
          If *pMSGFILTER\wParam = #VK_TAB And *pMSGFILTER\msg <> #WM_KEYUP
            Select *pMSGFILTER\nmhdr\idFrom
              Case #Editor_0
                SetActiveGadget(#Editor_1)
                result = 1
              Case #Editor_1
                SetActiveGadget(#Editor_2)
                result = 1
              Case #Editor_2
                SetActiveGadget(#Editor_0)
                result = 1
            EndSelect
          EndIf
      EndSelect
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow_0()
SendMessage_(GadgetID(#Editor_0), #EM_SETEVENTMASK, 0, #ENM_KEYEVENTS)
SendMessage_(GadgetID(#Editor_1), #EM_SETEVENTMASK, 0, #ENM_KEYEVENTS)
SendMessage_(GadgetID(#Editor_2), #EM_SETEVENTMASK, 0, #ENM_KEYEVENTS)
SetWindowCallback(@WinCallback())

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      End
  EndSelect
ForEver
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Benutzeravatar
marcelx
Beiträge: 424
Registriert: 19.02.2010 20:19
Wohnort: Darmstadt

Re: Tabulator im EditorGadget verhindern

Beitrag von marcelx »

Hallo zusammen,

wie kann ich dazu Tabulator in die EditorGadget eingeben (Tastenkombination?)

Gruß
MarcelX
Win-10, PB 5.31 (Windows - x86)
Nino
Beiträge: 1300
Registriert: 13.05.2010 09:26
Wohnort: Berlin

Re: Tabulator im EditorGadget verhindern

Beitrag von Nino »

marcelx hat geschrieben:wie kann ich dazu Tabulator in die EditorGadget eingeben (Tastenkombination?)
Ja, [Alt]+9
Benutzeravatar
marcelx
Beiträge: 424
Registriert: 19.02.2010 20:19
Wohnort: Darmstadt

Re: Tabulator im EditorGadget verhindern

Beitrag von marcelx »

Super, danke Nino
Win-10, PB 5.31 (Windows - x86)
Benutzeravatar
marcelx
Beiträge: 424
Registriert: 19.02.2010 20:19
Wohnort: Darmstadt

Re: Tabulator im EditorGadget verhindern

Beitrag von marcelx »

Hallo,

ich haben Formularen mit viele Gadget und wollte die Gadget-ID als List verwenden (wegen case).
Leider funktioniert es fast.
Einmal wieder beim erste Gadget angelangt, wird ein Tabulator eingefügt.
Kann jemand helfen?
Danke und Gruß
MarcelX

Code: Alles auswählen

EnableExplicit

Enumeration FormWindow
  #Window_0
EndEnumeration

Enumeration FormGadget
  #Editor_0
  #Editor_1
  #Editor_2
EndEnumeration

Global maxId=2
Global Dim listId(maxId)
Global indexId=0

Procedure OpenWindow_0(x = 0, y = 0, width = 383, height = 240)
  OpenWindow(#Window_0, x, y, width, height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(#Editor_0, 2, 2, 378, 76)
  StringGadget(#Editor_1, 2, 100, 378, 20, "")
  EditorGadget(#Editor_2, 2, 158, 378, 76)
EndProcedure

Procedure WinCallback(hwnd, msg, wParam, lParam)
  Protected result = #PB_ProcessPureBasicEvents
  Protected *pMSGFILTER.MSGFILTER
 
  Select msg
    Case #WM_NOTIFY
      *pMSGFILTER = lParam
      Select *pMSGFILTER\nmhdr\code
        Case #EN_MSGFILTER
          If *pMSGFILTER\wParam = #VK_TAB And *pMSGFILTER\msg <> #WM_KEYUP
            Select *pMSGFILTER\nmhdr\idFrom
              Case maxId ; end
                indexId=0
                SetActiveGadget(indexId)
                result = 1
              Case indexId To maxId-1
                indexId+1
                SetActiveGadget(indexId)
                result = 1
            EndSelect
          EndIf
      EndSelect
  EndSelect
  ProcedureReturn result
EndProcedure

OpenWindow_0()

listId(0) = #Editor_0
listId(1) = #Editor_1
listId(2) = #Editor_2

Define i
For i=0 To maxId
  SendMessage_(GadgetID(listId(i)), #EM_SETEVENTMASK, 0, #ENM_KEYEVENTS)
Next

SetWindowCallback(@WinCallback())

SetActiveGadget(listId(indexId))
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      End
  EndSelect
ForEver
Win-10, PB 5.31 (Windows - x86)
Benutzeravatar
mk-soft
Beiträge: 3695
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: Tabulator im EditorGadget verhindern

Beitrag von mk-soft »

Sorry, alles schon fertig... Hatte ich vergessen
Link: viewtopic.php?f=8&t=30853

Update - Mit 'ALT-GR + T' Tab einfügen

Code: Alles auswählen

;-TOP

; Comment : Module SetGadgetCallback (Windows Only)
; Author  : mk-soft
; Version : v0.02
; Created : 10.06.2018
; Updated : 
;
; Syntax Callback:
;           Procedure GadgetCB(hWnd,uMsg,wParam,lParam)
;             Select uMsg
;               ;TODO
;             EndSelect
;             ; Call previous gadget procedure
;             ProcedureReturn CallGadgetProc(hWnd,uMsg,wParam,lParam)
;           EndProcedure
;
; *****************************************************************************

DeclareModule GadgetCallback
  
  Declare SetGadgetCallback(Gadget, *lpNewFunc) 
  Declare CallGadgetProc(hWnd, uMsg, wParam, lParam)
  
EndDeclareModule

Module GadgetCallback
  
  EnableExplicit
  
  Global NewMap *lpPrevFunc()
  Global MutexCB = CreateMutex()
  
  ; ---------------------------------------------------------------------------
  
  Procedure SetGadgetCallback(Gadget, *lpNewFunc)
    Protected GadgetID, GadgetKey.s
    
    GadgetID = GadgetID(Gadget)
    GadgetKey = Hex(GadgetID)
    
    ; Remove exists Callback
    If FindMapElement(*lpPrevFunc(), GadgetKey)
      SetWindowLongPtr_(GadgetID, #GWL_WNDPROC, *lpPrevFunc())
      DeleteMapElement(*lpPrevFunc())
    EndIf
    
    If *lpNewFunc
      If AddMapElement(*lpPrevFunc(), GadgetKey)
        *lpPrevFunc() = SetWindowLongPtr_(GadgetID, #GWL_WNDPROC, *lpNewFunc)
        ProcedureReturn *lpPrevFunc()
      EndIf
    EndIf
    
    ProcedureReturn 0
    
  EndProcedure
  
  ; ---------------------------------------------------------------------------
  
  Procedure CallGadgetProc(hWnd, uMsg, wParam, lParam)
    Protected result
    
    LockMutex(MutexCB)
    If FindMapElement(*lpPrevFunc(), Hex(hWnd))
      result = CallWindowProc_(*lpPrevFunc(), hWnd, uMsg, wParam, lParam)
    EndIf
    UnlockMutex(MutexCB)
    
    ProcedureReturn result
    
  EndProcedure
  
EndModule

; *****************************************************************************

; Example

CompilerIf #PB_Compiler_IsMainFile
  
  UseModule GadgetCallback
  
  Procedure RichEditProc(hWnd,uMsg,wParam,lParam)
    Select uMsg
      Case #WM_CHAR
        Debug Hex(lParam)
        If wParam = #VK_TAB
          Debug Hex(lParam)
          SetFocus_(GetWindow_(hWnd,#GW_HWNDNEXT))
          ProcedureReturn 1
        ElseIf lParam = $20140001 ; Alt-Gr 'T' -> Tab einfügen
          wParam = #VK_TAB
          lParam =$F0001
        EndIf
    EndSelect
    ProcedureReturn CallGadgetProc(hWnd,uMsg,wParam,lParam)
  EndProcedure
  
  If OpenWindow(0,0,0,740,250,"Example SetGadgetCallback (Alt-Gr 'T' -> Tab einfügen)",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
    EditorGadget(1,10,10,230,200)
    EditorGadget(2,250,10,230,200)
    EditorGadget(3,490,10,230,200)
    
    SetGadgetCallback(1, @RichEditProc())
    SetGadgetCallback(2, @RichEditProc())
    SetGadgetCallback(3, @RichEditProc())
    
    ; SetGadgetCallback(1, 0)
    ; SetGadgetCallback(2, 0)
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
  
CompilerEndIf
Shift-Tab geht automatisch.
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul
Downloads auf MyWebspace / OneDrive
Benutzeravatar
marcelx
Beiträge: 424
Registriert: 19.02.2010 20:19
Wohnort: Darmstadt

Re: Tabulator im EditorGadget verhindern

Beitrag von marcelx »

Hallo mk-soft,

ich habe deine Code mit list-ID angepasst und so funktioniert; danke:

Code: Alles auswählen

DeclareModule GadgetCallback
 
  Declare SetGadgetCallback(Gadget, *lpNewFunc)
  Declare CallGadgetProc(hWnd, uMsg, wParam, lParam)
 
EndDeclareModule

Module GadgetCallback
 
  EnableExplicit
 
  Global NewMap *lpPrevFunc()
  Global MutexCB = CreateMutex()
 
  ; ---------------------------------------------------------------------------
 
  Procedure SetGadgetCallback(Gadget, *lpNewFunc)
    Protected GadgetID, GadgetKey.s
   
    GadgetID = GadgetID(Gadget)
    GadgetKey = Hex(GadgetID)
   
    ; Remove exists Callback
    If FindMapElement(*lpPrevFunc(), GadgetKey)
      SetWindowLongPtr_(GadgetID, #GWL_WNDPROC, *lpPrevFunc())
      DeleteMapElement(*lpPrevFunc())
    EndIf
   
    If *lpNewFunc
      If AddMapElement(*lpPrevFunc(), GadgetKey)
        *lpPrevFunc() = SetWindowLongPtr_(GadgetID, #GWL_WNDPROC, *lpNewFunc)
        ProcedureReturn *lpPrevFunc()
      EndIf
    EndIf
   
    ProcedureReturn 0
   
  EndProcedure
 
  ; ---------------------------------------------------------------------------
 
  Procedure CallGadgetProc(hWnd, uMsg, wParam, lParam)
    Protected result
   
    LockMutex(MutexCB)
    If FindMapElement(*lpPrevFunc(), Hex(hWnd))
      result = CallWindowProc_(*lpPrevFunc(), hWnd, uMsg, wParam, lParam)
    EndIf
    UnlockMutex(MutexCB)
   
    ProcedureReturn result
   
  EndProcedure
 
EndModule

; *****************************************************************************

; Example

CompilerIf #PB_Compiler_IsMainFile
 
  UseModule GadgetCallback
 
  Procedure RichEditProc(hWnd,uMsg,wParam,lParam)
    Select uMsg
      Case #WM_CHAR
        If wParam = #VK_TAB
          SetFocus_(GetWindow_(hWnd,#GW_HWNDNEXT))
          ProcedureReturn 1
        EndIf
    EndSelect
    ProcedureReturn CallGadgetProc(hWnd,uMsg,wParam,lParam)
  EndProcedure
  
  Global maxId=2
  Global Dim listId(maxId)
    
  If OpenWindow(0,0,0,740,250,"Example SetGadgetCallback",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
    listId(0) = 1
    listId(1) = 2
    listId(2) = 3    
    EditorGadget(listId(0),10,10,230,200)
    StringGadget(listId(1),250,10,230,20, "")
    EditorGadget(listId(2),490,10,230,200)
 

    Define i
    For i=0 To maxId
      SetGadgetCallback(listId(i), @RichEditProc())
    Next

    SetActiveGadget(listId(0))
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
 
CompilerEndIf
Gruß MarcelX
Win-10, PB 5.31 (Windows - x86)
Antworten