Seite 1 von 1

Wie Werkzeug beenden wenn PB beendet wird ? nun mit Demo

Verfasst: 19.05.2020 07:05
von hjbremer
Guten Morgen,

Ich habe ein kleines Programm als Werkzeug in die PB-IDE eingebunden, es zeigt nur ein paar Infos an,
und möchte nun erreichen das es sich automatisch beendet wenn ich PB schließe.

In der Hilfe finde ich unter Verwenden externer Werkzeuge dazu keine brauchbare Info.
Oder ich verstehe mal wieder nix.

Zum Start des Programms habe ich unter 'Ereignis zum Auslösen des Werkzeugs'
Menü oder Tastenkürzel gewählt.

Hat jemand eine Idee wie ?

hier ein MusterCode, wie gesagt das Programm macht nix, außer ein paar Infos anzuzeigen

Code: Alles auswählen

#window = 1
#liste = 2

If OpenWindow(#window, 810, 150, 420, 514, "test", #PB_Window_MinimizeGadget)
   StickyWindow(#window, 1)
   
   ListIconGadget(#liste, 3, 2, 400, 500, "Infos", 100, #PB_ListIcon_FullRowSelect) 
      
   Repeat
      event = WaitWindowEvent()
      
      If event = #PB_Event_Gadget
         Select EventGadget()
               
            Case #liste               
               Select EventType() 
                  Case #PB_EventType_LeftClick

               EndSelect
               
         EndSelect
      EndIf
      
   Until Event = #PB_Event_CloseWindow
EndIf

End


Re: Wie Werkzeug beenden wenn PB beendet wird ?

Verfasst: 19.05.2020 07:21
von Bisonte
unter Windows ist das Problem per "Mehrfachaufruf" lösbar...

Mit der Prozedur

Code: Alles auswählen

Procedure.i Instance_Running(LockStr$)
  Protected *MyMutex = CreateMutex_(#Null, 1, LockStr$)
  If *MyMutex <> 0 And GetLastError_() = #ERROR_ALREADY_EXISTS
    CloseHandle_(*MyMutex)
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure
Kann man prüfen, ob das Programm bereits läuft...

Dann braucht man nur noch per ProgramParameter einen "Quit" befehl auswerten.

Dafür braucht man dann auch in der IDE einen 2. Tooleintrag, der bei "Editor Closing" das Programm erneut aufruft, diesmal mit dem Parameter "Quit".

Re: Wie Werkzeug beenden wenn PB beendet wird ?

Verfasst: 19.05.2020 11:28
von chi
Oder so...

Code: Alles auswählen

IDE_hWnd = Val(GetEnvironmentVariable("PB_TOOL_MainWindow"))

OpenWindow(0, 0, 0, 320, 200, "", #WS_OVERLAPPEDWINDOW|#PB_Window_ScreenCentered, IDE_hWnd)

Repeat  
  event = WaitWindowEvent() 
Until event = #PB_Event_CloseWindow Or IsWindow_(IDE_hWnd) = 0

Re: Wie Werkzeug beenden wenn PB beendet wird ?

Verfasst: 19.05.2020 13:35
von hjbremer
Ja das isses

einfach und simpel !

Vielen Dank an Bisonte und Chi :praise:

Ich werde allerdings WS_OVERLAPPEDWINDOW weglassen, denn ich will keinen aktiven MaximizeButton

und die ParentID fürs Window ebenfalls, denn ich will nach dem Minimieren, unten ein extra Bild haben um wieder zu maximieren

PS: zum Testen des Programms muß man natürlich "Or IsWindow_(IDE_hWnd) = 0" auskommentieren
denn GetEnvironmentVariable("PB_TOOL_MainWindow") gibt bei mir innerhalb PB nur "". Als Exe aber Top

:D :D :D

Re: Wie Werkzeug beenden wenn PB beendet wird ? nun mit Demo

Verfasst: 26.05.2020 17:56
von hjbremer
Hier nun mein Werkzeug

einfach starten, als showInfo.pb speichern, Musterdatei wird angelegt

Wichtig; in Werkzeuge definieren muß Arbeitsverzeichnis = Programmverzeichnis sein

Code: Alles auswählen

;showInfo.pb - InfoFenster als Werkzeug. Windows 10 - HJ Bremer

;compiliert mit PB 570/572 x64, bei älteren PB Versionen muß ev. Höhe/Breite vom Fenster/Liste angepasst werden

;Hinweis: nur Exefile liefert Handle bei GetEnvironmentVariable("PB_TOOL_Scintilla") / ("PB_TOOL_MainWindow") 
;und
;"PB_TOOL_Scintilla" liefert nur den Wert vom aktiven Tab bei Programmstart. Wechselt man den Tab während 
;dieses Programm läuft, hat man den falschen Wert, denn jeder Tab hat sein eigenes Scintilla Handle.

;Quelle: GetProcess_ + SendText_ ts-soft, STARGÅTE http://forums.purebasic.com/german/viewtopic.php?t=24684
;Quelle: GetHwnd_ von Axolotl http://forums.purebasic.com/english/viewtopic.php?f=13&t=68266 

version$ = "showInfo V2.0a "

EnableExplicit

;- Start
#window = 1
#liste  = 2
#winsp = 880 : #winze = 110  ;Breite/Höhe wird unten berechnet

Global listrow, listcol ;vom Callback, welches Feld wurde angeklickt

Procedure.i GetProcess_FromWindow(hwnd)
   Protected processID
   If GetWindowThreadProcessId_(hwnd, @processID)
      ProcedureReturn OpenProcess_(#PROCESS_ALL_ACCESS, #False, processID)
   EndIf
EndProcedure

Procedure.i SendText_toScintilla(text.s, scintilla_hwnd)
   Protected processID = GetProcess_FromWindow(scintilla_hwnd)
   Protected length
   Protected *memoryID, *buffer, codeformat 
   If processID
      Select SendMessage_(scintilla_hwnd, #SCI_GETCODEPAGE, #Null, #Null)
         Case 0     : codeformat = #PB_Ascii
         Case 65001 : codeformat = #PB_UTF8
      EndSelect
      length = StringByteLength(text, codeformat)
      *buffer = AllocateMemory(length + SizeOf(Character))
      If *buffer
         PokeS(*buffer, text, #PB_Default, codeformat)
         *memoryID = VirtualAllocEx_(processID, #Null, length, #MEM_RESERVE|#MEM_COMMIT, #PAGE_EXECUTE_READWRITE)
         If *memoryID
            WriteProcessMemory_(processID, *memoryID, *buffer, length, #Null)
            ;SendMessage_(scintilla_hwnd, #SCI_ADDTEXT, length, *memoryID)
            SendMessage_(scintilla_hwnd, #SCI_REPLACESEL, #Null, *memoryID) 
            VirtualFreeEx_(processID, *memoryID, length, #MEM_RELEASE)
         EndIf
         FreeMemory(*buffer)
      EndIf
      CloseHandle_(processID)
   EndIf
EndProcedure

Procedure.i GetHwnd_Purebasic()  ;EnumWindows wäre sicherer aber dies geht auch.
   ProcedureReturn FindWindowEx_(GetDesktopWindow_(), 0, "WindowClass_2", 0)    
EndProcedure

Procedure.i GetHwnd_Scintilla(hwnd)
   hWnd = FindWindowEx_(hWnd, 0, "PureSplitter", 0)
   hWnd = FindWindowEx_(hWnd, 0, "PureSplitter", 0)
   hWnd = FindWindowEx_(hWnd, 0, "PureContainer", 0)
   hWnd = FindWindowEx_(hWnd, 0, "Scintilla", 0)     
   ProcedureReturn hWnd
EndProcedure

Procedure.i WindowCallback(hWnd, message, wParam, lParam)
   Protected result = #PB_ProcessPureBasicEvents
   
   Protected *nmhdr.NMHDR
   Protected *nmlv.NMLISTVIEW   
   Protected *nmitem.NMITEMACTIVATE   
   Protected *nmlvkey.LVKEYDOWN 
   Protected pbnr
   
   Select message          
      Case #WM_NOTIFY          
         *nmhdr = lParam   ;diese Struktur sagt von welchem Gadget und was ist wo passiert
         pbnr = *nmhdr\idFrom
         
         Select *nmhdr\code                
            Case #LVN_BEGINDRAG
               *nmlv = lparam
               listrow = *nmlv\iItem
               listcol = *nmlv\iSubItem : Debug "BEGINDRAG: " + " = row " + listrow + " col " + listcol
               
            Case #NM_CLICK, #NM_RCLICK    ;click im ListIconGadget
               *nmitem = lParam
               listrow = *nmitem\iItem
               listcol = *nmitem\iSubItem : Debug "CLICK: " + " = row " + listrow + " col " + listcol
               
            Case #LVN_KEYDOWN    ;ListIcon ist aktiv, Columns verschieben
               *nmlvkey = lparam
               If *nmlvkey\wVKey = #VK_RIGHT: SendMessage_(GadgetID(#liste), #LVM_SCROLL, 500,0): EndIf
               If *nmlvkey\wVKey = #VK_LEFT: SendMessage_(GadgetID(#liste), #LVM_SCROLL, -500,0): EndIf               
         EndSelect
         
      Case #WM_KEYDOWN    ;ListIcon NICHT aktiv
         If wparam = #VK_RIGHT: SendMessage_(GadgetID(#liste), #LVM_SCROLL, 500,0): EndIf
         If wparam = #VK_LEFT: SendMessage_(GadgetID(#liste), #LVM_SCROLL, -500,0): EndIf         
         
   EndSelect 
   
   ProcedureReturn result   
EndProcedure 

Procedure.i LoadText(filename$ = "showInfo.txt")
   Protected txt$   
   If OpenPreferences(filename$)
      ExaminePreferenceKeys()
      While NextPreferenceKey() 
         txt$ = PreferenceKeyValue()
         txt$ = ReplaceString(txt$, "; ", ";") : txt$ = ReplaceString(txt$, ";", #LF$)
         AddGadgetItem(#liste, -1, txt$)
      Wend
      ClosePreferences() 
   Else  ;Muster
      CreateFile(0, filename$)   ;Ansi Codierung in Notepad wählen
      WriteStringN(0, "; Format: text = Farbe; Seite1-Text1; Seite1-Text2; Seite2-Text1; Seite2-Text2")
      WriteStringN(0, "; Farben: $C6C6F3; $42CDFF; $D9C8B2; $8DE3A2; $7BD4F1; $ACCB41; "): WriteStringN(0, "")
      
      WriteStringN(0, "text = $C6C6F3; *Info; Befehle; Seite 2; Infos 2")  ;* im 1.String = Textfarbe ist rötlich
      WriteStringN(0, "text = $42CDFF; SetFlag; value | flag")
      WriteStringN(0, "text = $42CDFF; ClearFlag; value & ~flag")
      WriteStringN(0, "text = $42CDFF; ToggleFlag;value ! flag")
      WriteStringN(0, "text = $D9C8B2; AnyFlagSet;Bool(value & flag)")
      WriteStringN(0, "text = $D9C8B2; IsFlagSet; Bool(value & flag = flag)")
      WriteStringN(0, "text = $D9C8B2; IsFlagNotSet; Bool(value & flag = 0)")
      WriteStringN(0, "text = $8DE3A2; "):WriteStringN(0, "text = $8DE3A2; ")
      WriteStringN(0, "text = $7BD4F1; "):WriteStringN(0, "text = $7BD4F1; ")
      WriteStringN(0, "text = $ACCB41; "):WriteStringN(0, "text = $ACCB41; ")
      WriteStringN(0, "text = $C6C6F3; *Seite 2: Taste ->; Drag/Drop, Leftclick To Clipboard, Rightclick To IDE; " +
                      "Seite 1: Taste <-; DoubleClick auf WindowLeiste = Sticky on/off")
      CloseFile(0) 
      LoadText(filename$)
   EndIf
EndProcedure

;- OpenWindow

If OpenWindow(#window, #winsp, #winze, 0, 0, version$, #PB_Window_MinimizeGadget|#PB_Window_Invisible)
   SetWindowCallback(@WindowCallback())
   
   ListIconGadget(#liste, -2, -1, 0, 0, "Farbe", 1, #PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines|#LVS_NOCOLUMNHEADER) 
   
   AddGadgetColumn(#liste, 1, "Seite1-1", 125) : AddGadgetColumn(#liste, 2, "Seite1-2", 300)   
   AddGadgetColumn(#liste, 3, "Seite2-1", 125) : AddGadgetColumn(#liste, 4, "Seite2-2", 300)   
   
   SetWindowTheme_(GadgetID(#liste), "explorer", 0)
   SetGadgetColor(#liste, #PB_Gadget_BackColor, $DBF2D4)  ;für Balken, Farbe nicht zu dunkel
   
   LoadText()
   
   ;Höhe/Breite/Farbe
   Define r.rect, j, color, text$, br, hh, anz = CountGadgetItems(#liste) - 1
   
   SendMessage_(GadgetID(#liste), #LVM_GETITEMRECT, 0, r)   ;Größe einer Zeile
   For j = 0 To anz
      color = Val(GetGadgetItemText(#liste, j, 0))          ;Farbe steht in Col 0
      SetGadgetItemColor(#liste, j, #PB_Gadget_BackColor, color, -1)
      text$ = GetGadgetItemText(#liste, j, 1)
      If Left(text$, 1) = "*"                               ;Wenn Text in Col 1 mit * beginnt
         SetGadgetItemText(#liste, j, Mid(text$, 2), 1)     ;dann Textfarbe ändern in Rot
         SetGadgetItemColor(#liste, j, #PB_Gadget_FrontColor, $0000a0, -1)
      EndIf
      hh + r\bottom  ;Höhe jeder Zeile addieren
   Next
   br = r\right / 2 + 1    ;Gesamtbreite / 2 da man mit Pfeiltasten zwischen den Seiten umschaltet
   ResizeGadget(#liste, #PB_Ignore, #PB_Ignore, br+4, hh+21)    ;hh + HorzScrollleiste, ohne Header
   ResizeWindow(#window, #PB_Ignore, #PB_Ignore, br, hh+1)      ;HorzScrollleiste von Window verdeckt

   Define purebasic_hwnd = GetHwnd_Purebasic()                  ;Handle PB Fenster 
   Define scintilla_hwnd = GetHwnd_Scintilla(purebasic_hwnd)    ;Handle activer IDE-TAB   
   Define sticky = 1, event
   
   HideWindow(#window, 0) : StickyWindow(#window, sticky)       ;Fenster anzeigen, Sticky = 1 ist Startwert   
   
   ;- Event-Loop   
   Repeat
      event = WaitWindowEvent()
      
      If Event = #WM_NCLBUTTONDBLCLK   ;DbClick auf WindowKopf = Sticky on/off
         sticky ! 1 : StickyWindow(#window, sticky)
         
      ElseIf event = #PB_Event_Gadget
         Select EventGadget()               
            Case #liste     ;listrow + listcol sind global, vom Callback
               text$ = Trim(GetGadgetItemText(#liste, listrow, listcol)) 
               
               Select EventType() 
                  Case #PB_EventType_DragStart : If text$ <> "": DragText(text$): EndIf 
                  Case #PB_EventType_LeftClick : SetClipboardText(text$)
                     
                  Case #PB_EventType_RightClick                     
                     scintilla_hwnd = GetHwnd_Scintilla(purebasic_hwnd) ;activer IDE-TAB
                     If text$ <> ""
                        SendText_toScintilla(text$, scintilla_hwnd)
                        SetActiveWindow_(purebasic_hwnd)
                        SetForegroundWindow_(purebasic_hwnd)
                     EndIf                      
               EndSelect               
         EndSelect
      EndIf
      
      If IsWindow_(purebasic_hwnd) = 0 : Break : EndIf   ;wenn null, Programm beenden
      
   Until Event = #PB_Event_CloseWindow
EndIf

;SetWindowLongPtr_(WindowID(#window), #GWL_EXSTYLE, #WS_EX_LAYERED)  ;Fenster durchsichtig
;SetLayeredWindowAttributes_(WindowID(#window), 0, 230, #LWA_ALPHA)  ;230 ist wert für durchsichtig