Page 1 of 1

Bypassing the clipboard

Posted: Mon Jan 31, 2005 1:19 pm
by Leo
Sometimes you need to feed edit controls with a lot of text from a text file.
Using copy and paste is then enconveniant. I wrote a little program to overcome this inconveniance.

How does it work.
1. Open a txt file with the "Open Text File" button
2. Click the "GetContol" button and then click at the receiving edit control.
3. Now you can click at any line in the listbox and it will be send to the receiving edit control.
4. Checking the return checkbox will cause that after the line, a return for the receiving edit control is generated.
5. Checking the edit mode checkbox allows you to edit and save the text file.

Code: Select all

;/ Created with PureVisionXP v2.03
;/ Thu, 27 Jan 2005 14:12:57
;/ by Mijnders Automation




XIncludeFile "SendLine_Constants.pb"
XIncludeFile "SendLine_Windows.pb"

Procedure MyWindowCallback(WindowID, Message, wParam, lParam) 
  Result = #PB_ProcessPureBasicEvents 
  Select message 
    Case #WM_SIZE 
      ResizeGadget(#Gadget_SendLine_edText,-1,-1,WindowWidth()-11,WindowHeight()-72) 
      ResizeGadget(#Gadget_SendLine_ListView5,-1,-1,WindowWidth()-11,WindowHeight()-72) 
      ResizeGadget(#Gadget_SendLine_cbEditMode,-1,305+WindowHeight()-327,-1,-1) 
      ResizeGadget(#Gadget_SendLine_btSave,-1,300+WindowHeight()-327,-1,-1) 
  EndSelect 
  ProcedureReturn Result 
EndProcedure

;-Main Loop
If Window_SendLine()
  HideGadget(#Gadget_SendLine_edText,1)
  HideGadget(#Gadget_SendLine_btSave,1)
  File$=""
  SetWindowCallback(@MyWindowCallback())
  quitSendLine=0
  Repeat
    EventID=WaitWindowEvent()
    Select EventID
      Case #PB_Event_CloseWindow
        If EventWindowID()=#Window_SendLine
          quitSendLine=1
        EndIf


      Case #PB_Event_Gadget
        Select EventGadgetID()
          Case #Gadget_SendLine_btOpen
            StandardFile$ = File$
            Pattern$ = "Text (*.txt)|*.txt"
            Pattern = 0
            File$ = OpenFileRequester("Please choose file to load", StandardFile$, Pattern$, Pattern) 
            If ReadFile(1,File$)
              If GetGadgetState(#Gadget_SendLine_cbEditMode)=1
                Buffer=AllocateMemory(Lof())
                ReadData(Buffer,Lof())
                SetGadgetText(#Gadget_SendLine_edText, PeekS(Buffer))
              Else
                ClearGadgetItemList(#Gadget_SendLine_ListView5)
                While ~Eof(1)
                  AddGadgetItem(#Gadget_SendLine_ListView5,-1,ReadString())
                Wend  
              EndIf
              CloseFile(1)
            EndIf
          Case #Gadget_SendLine_btSave
            StandardFile$ = File$
            Pattern$ = "Text (*.txt)|*.txt"
            Pattern = 0
            File$ = SaveFileRequester("Please choose file to load", StandardFile$, Pattern$, Pattern) 
            File$=StringField(File$,1,".")+".txt"
            If OpenFile(1,File$)
              WriteString(GetGadgetText(#Gadget_SendLine_edText))
              CloseFile(1)
            EndIf
          Case #Gadget_SendLine_btControl
            Repeat
              If GetAsyncKeyState_(1)=-32767
                GetCursorPos_ (@p.POINT) 
                source = WindowFromPoint_ (p\x, p\y) 
                Debug "**************"
                Debug Hex(source)
                Break
              EndIf  
            ForEver
          Case #Gadget_SendLine_cbEditMode
            If GetGadgetState(#Gadget_SendLine_cbEditMode)=1
              HideGadget(#Gadget_SendLine_edText,0)
              HideGadget(#Gadget_SendLine_ListView5,1)
              HideGadget(#Gadget_SendLine_btSave,0)
              S$=""
              For i=0 To CountGadgetItems(#Gadget_SendLine_ListView5)-1
                S$+GetGadgetItemText(#Gadget_SendLine_ListView5,i,0)+Chr(13)+Chr(10)
              Next
              SetGadgetText(#Gadget_SendLine_edText,S$)
            Else
              HideGadget(#Gadget_SendLine_edText,1)
              HideGadget(#Gadget_SendLine_ListView5,0)
              HideGadget(#Gadget_SendLine_btSave,1)
              ClearGadgetItemList(#Gadget_SendLine_ListView5)
              S$=GetGadgetText(#Gadget_SendLine_edText)
              i=1
              While #True
                T$=StringField(S$,i,Chr(13))
                If T$=""
                  Break
                Else
                  T$=Trim(ReplaceString(T$,Chr(10)," "))
                  AddGadgetItem(#Gadget_SendLine_ListView5,-1,T$)
                EndIf
                i+1   
              Wend
            EndIf
          Case #Gadget_SendLine_cbReturn
          Case #Gadget_SendLine_ListView5
            Line$=GetGadgetItemText(#Gadget_SendLine_ListView5,GetGadgetState(#Gadget_SendLine_ListView5),0)
            Debug Line$
            SendMessage_(source, #WM_SETTEXT, 0, @Line$)
            If GetGadgetState(#Gadget_SendLine_cbReturn)=1
              SetForegroundWindow_(source)
              keybd_event_(#VK_RETURN,0,0,0)    
              keybd_event_(#VK_RETURN,0,#KEYEVENTF_KEYUP,0)    
            EndIf
            Select EventType()
              Case #PB_EventType_LeftDoubleClick
              Default
            EndSelect
        EndSelect

    EndSelect
  Until quitSendLine
  CloseWindow(#Window_SendLine)
EndIf
End
The xincludefiles

Code: Select all

;/ Created with PureVisionXP v2.03
;/ Sun, 30 Jan 2005 11:21:15
;/ by Mijnders Automation




XIncludeFile "SendLine_Constants.pb"


Procedure.l Window_SendLine()
  If OpenWindow(#Window_SendLine,80,80,401,327,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered|#PB_Window_Invisible|#PB_Window_SizeGadget,"Leooos SendLine Utility")
    If CreateGadgetList(WindowID(#Window_SendLine))
      ButtonGadget(#Gadget_SendLine_btOpen,5,5,80,20,"Open Text File  ")
      ButtonGadget(#Gadget_SendLine_btControl,110,5,60,20,"GetControl")
      CheckBoxGadget(#Gadget_SendLine_cbReturn,195,10,80,15,"Return")
      ListViewGadget(#Gadget_SendLine_ListView5,5,35,390,255)
      ButtonGadget(#Gadget_SendLine_btSave,95,300,80,20,"Save Text File")
      CheckBoxGadget(#Gadget_SendLine_cbEditMode,5,305,80,15,"Edit Mode")
      EditorGadget(#Gadget_SendLine_edText,5,35,390,255)
      HideWindow(#Window_SendLine,0)
      ProcedureReturn WindowID()
    EndIf
  EndIf
EndProcedure
and

Code: Select all

;/ Created with PureVisionXP v2.03
;/ Sun, 30 Jan 2005 11:21:15
;/ by Mijnders Automation




;-Global Variables and Constants
Global BubbleTipStyle.l:BubbleTipStyle=0
#PB_Image_BorderRaised =$1

;-Window Constants
Enumeration 1
  #Window_SendLine
EndEnumeration
#WindowIndex=#PB_Compiler_EnumerationValue


;-Gadget Constants
Enumeration 1
  ;Window_SendLine
  #Gadget_SendLine_btOpen
  #Gadget_SendLine_btControl
  #Gadget_SendLine_cbReturn
  #Gadget_SendLine_ListView5
  #Gadget_SendLine_btSave
  #Gadget_SendLine_cbEditMode
  #Gadget_SendLine_edText


EndEnumeration
#GadgetIndex=#PB_Compiler_EnumerationValue