Code: Select all
; **********note**********
; 1 for pb5.70 IDE by gurj
; 2 open FindReplaceForPUB should by PureBasic.exe's ToolBar or Tools menu
; 3 then this tool use Ctrl+F To can Enable IDE's FindReplace for get it ID.
; 4 working...***not use F3 And Shift+F3 ***
; 5 active FindReplaceForPUB.exe TITLE And Shift+Enter To close the tool,
; Or auto close when IDE closed or minimize.
; 6 in this tool , ButtonG_"x" And "close" let form To screen's right and bottom, as 'hided';
; again 'open' this tool is change 'hided' to 'show'
; ********ataorj.ys168.com*******
MutexName$ = "FindReplaceForPUB"
hMutex = CreateMutex_(0, 0, @MutexName$)
If GetLastError_() = #ERROR_ALREADY_EXISTS
OpenPreferences(GetPathPart(ProgramFilename())+MutexName$+".ini")
Handle=ReadPreferenceLong("Handle",-6)
If IsWindow_(Handle)=0
SendMessage_(win1,#WM_CLOSE,0,0)
ClosePreferences()
End
EndIf
win1=ReadPreferenceLong("win1",-7)
cx=ReadPreferenceLong("cx",-8)
cy=ReadPreferenceLong("cy",-9)
SetWindowPos_(Handle,#HWND_TOP,cx,cy,0,0,#SWP_NOSIZE)
SetWindowPos_(win1,#HWND_TOP,cx,cy,0,0,#SWP_NOSIZE)
ClosePreferences()
End:EndIf
Han=GetForegroundWindow_()
Global s.s=Space(40960)
GetWindowText_(Han,@s,255)
If Left(s,10)<>"PureBasic "
MessageRequester("FindReplaceForPUB",~"besides for close this tool when purebasic.exe already closed;\nopen FindReplaceForPUB should \nby PureBasic.exe's ToolBar or Tools menu")
End:EndIf
keybd_event_(#VK_CONTROL,0,0,0)
keybd_event_(#VK_F,0,0,0):Delay(150)
keybd_event_(#VK_F,0,#KEYEVENTF_KEYUP,0)
keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0)
Delay(250)
Handle=GetForegroundWindow_()
OpenPreferences(GetPathPart(ProgramFilename())+MutexName$+".ini")
WritePreferenceLong("Handle",Handle)
Structure gad
h.l;gadID
xy.l;x or y
EndStructure
Global y1,y,Dim gad(8),g,r.rect,rec.rect,NewList gads.gad(),historys=22,check;,Dim edit(1)
Procedure ListWindows(hwnd,Param)
Protected Class$ = Space(1024)
GetClassName_(hwnd,@Class$,Len(Class$))
If Class$ ="Edit"
GetWindowRect_(hwnd,rec)
AddElement(gads())
gads()\h = hwnd
gads()\xy = rec\top-2000
g+1
ElseIf Class$ ="ComboBox"
GetWindowRect_(hwnd,rec)
AddElement(gads())
gads()\h = hwnd
gads()\xy = rec\top-1000
g+1
ElseIf Class$ ="Button"
GetWindowRect_(hwnd,rec)
If rec\bottom>y
AddElement(gads())
gads()\h = hwnd
gads()\xy = rec\left
g+1
ElseIf rec\top<y1; And rec\left<x1
If SendMessage_(hwnd,#BM_GETCHECK,0,0)=0
;SendMessage_(hwnd,#BM_SETCHECK,1,0)
SendMessage_(hwnd,#BM_CLICK ,0,0):EndIf
check=hwnd:EnableWindow_(hwnd,0)
EndIf
EndIf
ProcedureReturn #True
EndProcedure
;EnableMenuItem_(GetSystemMenu_(Han, #False), #SC_MINIMIZE, #MF_BYCOMMAND | 1)
;EnableMenuItem_(GetSystemMenu_(Handle, #False), #SC_CLOSE, #MF_BYCOMMAND | 1)
GetWindowRect_(Handle,r)
;x1=r\left+30
y1=r\top+60+GetSystemMetrics_(#SM_CYCAPTION)
y=r\bottom-25
r\right=r\right-r\left
r\bottom=r\bottom-r\top
win1=OpenWindow(1,0,0,0,0,"FindReplaceForPUB",#PB_Window_SystemMenu|#PB_Window_Maximize)
GetWindowRect_(win1,rec)
cx=rec\right-r\right
cy=rec\bottom-r\bottom-25
cy>>1
cx_=rec\right-60
cy_=rec\bottom-18
EnumChildWindows_(Handle,@ListWindows(),0)
SortStructuredList(gads(), 0, OffsetOf(gad\xy), TypeOf(gad\xy))
g=0
ForEach gads()
gad(g)=gads()\h:g+1
Next
MapWindowPoints_(0,Handle,rec,2)
TextGadget(10,0,0,r\right,rec\top,"")
SetGadgetColor(10,#PB_Gadget_BackColor,$BFBFBF)
SetWindowLongPtr_(Win1, #GWL_EXSTYLE,GetWindowLongPtr_(win1, #GWL_EXSTYLE) | #WS_EX_LAYERED)
SetLayeredWindowAttributes_(Win1, $BFBFBF,0, #LWA_COLORKEY)
For a=2 To 3:GetWindowRect_(gad(a),rec):MapWindowPoints_(0,Handle,rec,2)
ComboBoxGadget(a,rec\left ,rec\top,rec\right-rec\left ,rec\bottom-rec\top,#PB_ComboBox_Editable)
b=ReadPreferenceLong("CountStr"+a,0)
s=ReadPreferenceString("Stringes"+a,"")
For c=1 To b
AddGadgetItem(a,-1,StringField(s,c,Chr(1)))
Next: SendMessage_(gad(a-2),#EM_GETLINE, 0, @s)
SetGadgetText(a,s):Next
For a=4 To 8:GetWindowText_(gad(a),@s,255)
GetWindowRect_(gad(a),rec):MapWindowPoints_(0,Handle,rec,2)
ButtonGadget(a,rec\left ,rec\top,rec\right-rec\left ,rec\bottom-rec\top,s)
Next
SetWindowLongPtr_(win1,#GWLP_HWNDPARENT,Handle)
WritePreferenceLong("win1",win1)
WritePreferenceLong("cx",cx)
WritePreferenceLong("cy",cy)
SetWindowPos_(Handle,#HWND_TOP,cx,cy,0,0,#SWP_NOSIZE)
SetWindowPos_(win1,#HWND_TOP,cx,cy,r\right,r\bottom,#SWP_SHOWWINDOW)
;SendMessage_(gad(8),#CB_ADDSTRING,0,@s)
Procedure history(n)
For a=0 To CountGadgetItems(n)-1
If GetGadgetItemText(n,a)=s
RemoveGadgetItem(n,a)
Break
EndIf
Next:AddGadgetItem(n,0,s):If CountGadgetItems(n)>historys
RemoveGadgetItem(n,CountGadgetItems(n)-1):EndIf
While WindowEvent():Wend
SetGadgetState(n,0)
While WindowEvent():Wend
EndProcedure
ClosePreferences()
SetWindowColor(1,$DEB5FF)
AddKeyboardShortcut(1,#PB_Shortcut_Shift|#PB_Shortcut_Return,1)
While WindowEvent():Wend
Repeat:re:
Select WaitWindowEvent(3600000);60 minute for check Handle close
Case #PB_Event_Gadget:eg=EventGadget()
Select eg
; Case 2,3
; If EventType()=#PB_EventType_Change
; edit(eg)=1:EndIf
Case 4,5:Gosub fin
Case 6,7:s=GetGadgetText(3):history(3)
; SendMessage_(gad(1),#EM_SETSEL, 0, -1)
; SendMessage_(gad(1),#EM_REPLACESEL,0,s)
SendMessage_(gad(1),#WM_SETTEXT, 0, @s)
Gosub fin
Case 8:If IsWindow_(Handle)
SetWindowPos_(Handle,#HWND_TOP,cx_,cy_,0,0,#SWP_NOSIZE)
SetWindowPos_(win1,#HWND_TOP,cx_,cy_,0,0,#SWP_NOSIZE)
Else:Break
EndIf
EndSelect
Case #PB_Event_CloseWindow
If IsWindow_(Handle)
SetWindowPos_(Handle,#HWND_TOP,cx_,cy_,0,0,#SWP_NOSIZE)
SetWindowPos_(win1,#HWND_TOP,cx_,cy_,0,0,#SWP_NOSIZE)
Else:Break
EndIf
Case 0
If IsWindow_(Handle)=0:Break
EndIf
Case #PB_Event_MoveWindow
SetWindowPos_(Handle,#HWND_TOP,WindowX(1),WindowY(1),0,0,#SWP_NOSIZE)
Case #PB_Event_Menu:EnableWindow_(check,1)
SetWindowPos_(Handle,#HWND_TOP,cx,cy,0,0,#SWP_NOSIZE):Break
Case #WM_NCLBUTTONDBLCLK
SetWindowPos_(Handle,#HWND_TOP,cx,cy,0,0,#SWP_NOSIZE)
SetWindowPos_(win1,#HWND_TOP,cx,cy,r\right,r\bottom,#SWP_SHOWWINDOW)
While WindowEvent():Wend
Case #PB_Event_ActivateWindow
; MyWindpl.WINDOWPLACEMENT
; MyWindpl\length=SizeOf(MyWindpl)
; If GetWindowPlacement_(han,@MyWindpl) And MyWindpl\showCmd=#SW_SHOWMINIMIZED
; SetWindowState(1,#PB_Window_Minimize)
; EndIf
GetWindowRect_(Han,rec);:MessageRequester("",Str(rec\left))
If rec\left<-4000:SetWindowPos_(Handle,#HWND_TOP,cx_,cy_,0,0,#SWP_NOSIZE)
Break
;SetWindowLongPtr_(win1,#GWLP_HWNDPARENT,0)
;SetWindowLongPtr_(win1,#GWLP_HWNDPARENT,Handle)
; SetWindowState(1,#PB_Window_Minimize)
; SetWindowPos_(win1,#HWND_TOP,cx_,cy_,0,0,#SWP_NOSIZE)
; SetWindowPos_(han,#HWND_TOP,cx_,cy_,0,0,#SWP_NOSIZE)
; While WindowEvent():Wend
EndIf
EndSelect:ForEver
OpenPreferences(GetPathPart(ProgramFilename())+MutexName$+".ini")
For a=2 To 3:b=CountGadgetItems(a)
WritePreferenceLong("CountStr"+a,b)
s=""
For c=0 To b-1:s+GetGadgetItemText(a,c)+Chr(1)
Next:WritePreferenceString("Stringes"+a,s):Next
ClosePreferences()
CloseHandle_(hMutex)
End
fin:
s=GetGadgetText(2)
SetFocus_(gad(0));激活Handle才工作
; SendMessage_(gad(0),#EM_SETSEL, 0, -1)
; SendMessage_(gad(0),#EM_REPLACESEL,0,s)
SendMessage_(gad(0),#WM_SETTEXT, 0, @s)
If s<>"":history(2):Else:Goto re:EndIf
;SendMessage_(gad(eg),#WM_LBUTTONDOWN,0,0):Delay(122)
;SendMessage_(gad(eg),#WM_LBUTTONUP,0,0)
SendMessage_(gad(eg),#BM_CLICK ,0,0)
Return