Hello at all
I want to know, si you have a tips for listing all the handle of windows and a handle daughter.
Because, i want to catch the handle of by example the openfilerequester of the IDE of purebasic.
When i press the ley "Ctrl+o" in the native IDE
Thanks for your answer
Good day
Listing all the handles
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Listing all the handles

Not a destination
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
I have found this great code of FREAK i believe
Is it the good, the fasted and the most simple way for found the handle of a messagerequester or a filerequester ??
http://www.purebasic.fr/english/viewtop ... te+process
Is it the good, the fasted and the most simple way for found the handle of a messagerequester or a filerequester ??
http://www.purebasic.fr/english/viewtop ... te+process
Code: Select all
Declare.s ProcessNameFromHwnd(hwnd)
Declare CheckWindowsProcess(WndHwnd, p)
Global USB_ROOT.s = "e:\" ; the root of your USB stick
; assuming that all applications started on your USB stick have a window, we could enumerate all windows
; and send a #wm_close message to the ones that have started on your USB stick.
Procedure CheckWindowsProcess(WndHwnd, p)
; check if the first third caracters of the process path are the USB_ROOT.s
Protected ProcessPath.s = ProcessNameFromHwnd(WndHwnd)
Protected Caption.s = Space(255)
If UCase(Mid(ProcessPath, 1, 3)) = UCase(USB_ROOT)
GetWindowText_(WndHwnd, @Caption, 255)
Debug "Title: " + Caption
Debug "Path: " + ProcessPath
Debug "Hwnd: " + Str(WndHwnd)
Debug "---------------------------"
; here, as you already have the Window Handle, you could send the #wm_close message
EndIf
ProcedureReturn #True ; return 1 to continue the enumeration
EndProcedure
Procedure.s ProcessNameFromHwnd(hwnd)
Protected ProcessID
Protected hProcess
Protected hModule
Protected ProcessName.s = Space(#MAX_PATH)
Protected EnumProcessModules
Protected GetModuleFileNameEx
If OpenLibrary(0, "psapi.dll")
EnumProcessModules = GetFunction(0, "EnumProcessModules")
GetModuleFileNameEx = GetFunction(0, "GetModuleFileNameExA")
GetWindowThreadProcessId_(hwnd, @ProcessID)
hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION|#PROCESS_VM_READ, 0, ProcessID)
CallFunctionFast(EnumProcessModules, hProcess, @hModule, 1, 0)
CallFunctionFast(GetModuleFileNameEx, hProcess, hModule, @ProcessName, #MAX_PATH)
CloseHandle_(hProcess)
CloseLibrary(0)
EndIf
ProcedureReturn ProcessName
EndProcedure
Debug "applications started on " + USB_ROOT
Debug "------------------------------------"
EnumWindows_(@CheckWindowsProcess(), 1)
Debug "------------------------------------"
Debug "end"

Not a destination
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Well...., with the code of a little bit everybody, (that i thanks
), i have create this code.
I'm go to an idea of TSSOFT, i believe.
When i launch this exe, he read the file selected ".PB" and when he find an include instruction, he open the Filerequester with sendkey "Ctrl+o" and write the path of the file, make the return key, and resume ....while there are not PBI file.
Like this, we are a little project management
I need this code because i have a big DLL with ten ".pbi" and to open all each time is too hard
But i have a problem (Like usually
)
When the Messagerequester is open, he is modal, and lock the writing of the file in the openfilerequester
Somebody can help me ??

I'm go to an idea of TSSOFT, i believe.
When i launch this exe, he read the file selected ".PB" and when he find an include instruction, he open the Filerequester with sendkey "Ctrl+o" and write the path of the file, make the return key, and resume ....while there are not PBI file.
Like this, we are a little project management

I need this code because i have a big DLL with ten ".pbi" and to open all each time is too hard

But i have a problem (Like usually

When the Messagerequester is open, he is modal, and lock the writing of the file in the openfilerequester

Somebody can help me ??
Code: Select all
Global Passage
Global AppPath.s
Global FichierACharger$
AppPath = Space(200)
GetCurrentDirectory_(200, @AppPath)
AppPath = Trim(AppPath)
PathAddBackslash_(@AppPath)
Enumeration
#FormProjet
#ListViewPb
#TextPb
EndEnumeration
Declare.s ProcessNameFromHwnd(hwnd)
Declare CheckWindowsProcess(WndHwnd, p)
Procedure SendKey(Key.s)
; get virtual key code and shift state
VK.w = VkKeyScan_(Asc(Key))
If VK = -1
ProcedureReturn
EndIf
; get scan code if an extended key
If MapVirtualKey_(VK, 2) = 0
Extended.l = #KEYEVENTF_EXTENDEDKEY
; get scan code
Scan.l = MapVirtualKey_(VK, 0)
Else
Extended = 0
Scan = 0
EndIf
; press shift/ctrl/alt if needed
Shift.l = VK & $100
Ctrl.l = VK & $200
Alt.l = VK & $400
If Shift
keybd_event_(#VK_SHIFT, 0, 0, 0)
EndIf
If Ctrl
keybd_event_(#VK_CONTROL, 0, 0, 0)
EndIf
If Alt
keybd_event_(#VK_MENU, 0, 0, 0)
EndIf
; press and release key
VK & $ff
keybd_event_(VK, Scan, Extended, 0)
keybd_event_(VK, Scan, #KEYEVENTF_KEYUP | Extended, 0)
; release shift/ctrl/alt if pressed
If Shift
keybd_event_(#VK_SHIFT, 0, #KEYEVENTF_KEYUP, 0)
EndIf
If Ctrl
keybd_event_(#VK_CONTROL, 0, #KEYEVENTF_KEYUP, 0)
EndIf
If Alt
keybd_event_(#VK_MENU, 0, #KEYEVENTF_KEYUP, 0)
EndIf
EndProcedure
Procedure SendKeys(String.s)
For Letter.l = 1 To Len(String)
SendKey(Mid(String, Letter, 1))
Next
EndProcedure
ProcedureDLL FindHwndWindowByPartName(Part$)
r = GetWindow_(GetDesktopWindow_(),#GW_CHILD)
Repeat
t$ = Space(999)
GetWindowText_(r,t$,999)
If FindString(LCase(t$), LCase(part$),1) <> 0 And IsWindowVisible_(r) = #True
w = r
Else
r = GetWindow_(r, #GW_HWNDNEXT)
EndIf
Until r = 0 Or w <> 0
ProcedureReturn w
EndProcedure
Procedure CheckWindowsProcess(WndHwnd, p)
; check if the first third caracters of the process path are the USB_ROOT.s
Protected ProcessPath.s = ProcessNameFromHwnd(WndHwnd)
Protected Caption.s = Space(255)
GetWindowText_(WndHwnd, @Caption, 255)
If FindString(UCase(Caption), "OUVRIR UN FICHIER...", 1)
Delay(10)
SendKeys(AppPath + Trim(FichierACharger$))
Delay(10)
keybd_event_(#VK_RETURN,0,0,0)
Delay(10)
EndIf
ProcedureReturn #True ; return 1 to continue the enumeration
EndProcedure
Procedure.s ProcessNameFromHwnd(hwnd)
Protected ProcessID
Protected hProcess
Protected hModule
Protected ProcessName.s = Space(#MAX_PATH)
Protected EnumProcessModules
Protected GetModuleFileNameEx
If OpenLibrary(0, "psapi.dll")
EnumProcessModules = GetFunction(0, "EnumProcessModules")
GetModuleFileNameEx = GetFunction(0, "GetModuleFileNameExA")
GetWindowThreadProcessId_(hwnd, @ProcessID)
hProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION|#PROCESS_VM_READ, 0, ProcessID)
CallFunctionFast(EnumProcessModules, hProcess, @hModule, 1, 0)
CallFunctionFast(GetModuleFileNameEx, hProcess, hModule, @ProcessName, #MAX_PATH)
CloseHandle_(hProcess)
CloseLibrary(0)
EndIf
ProcedureReturn ProcessName
EndProcedure
OpenWindow(#FormProjet, 380, 113, 189, 261, "Charge projet", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
CreateGadgetList(WindowID(#FormProjet))
TextGadget(#TextPb, 13, 11, 165, 22, "Choisissez votre projet",#PB_Text_Center)
ListViewGadget(#ListViewPb, 13, 41, 165, 206)
UsedDirectory = ExamineDirectory(#PB_Any, AppPath, "*.*")
While NextDirectoryEntry(UsedDirectory)
NomElement.s = DirectoryEntryName(UsedDirectory)
If DirectoryEntryType(UsedDirectory) = #PB_DirectoryEntry_File
If Not FindString(NomElement,".pbi", 1) And FindString(UCase(NomElement), ".PB", 1)
AddGadgetItem(#ListViewPb, - 1, NomElement)
EndIf
EndIf
Wend
FinishDirectory(UsedDirectory)
Repeat
Evenement = WaitWindowEvent ()
Select Evenement
Case #PB_Event_Gadget
ProjetChoisi.s = GetGadgetItemText(#ListViewPb, GetGadgetState(#ListViewPb), 0)
Delay(1000)
If Not Passage
Passage = #True
RunProgram(#PB_Compiler_Home + "Purebasic.exe")
Delay(2000)
EndIf
ReadFile(1, AppPath + ProjetChoisi)
hand = FindHwndWindowByPartName("PureBasic - ")
Repeat
LigneCode$ = ReadString(1)
If FindString(LigneCode$, "IncludeFile", 1)
res = SetForegroundWindow_(hand)
FichierACharger$ = ReplaceString(LigneCode$, "IncludeFile", "")
FichierACharger$ = ReplaceString(FichierACharger$, Chr(34), "")
; Ouverture du selecteur de fichier par la methode sendkey
keybd_event_(#VK_CONTROL,0,0,0)
keybd_event_($4F,0,0,0)
keybd_event_(#VK_CONTROL,0,#KEYEVENTF_KEYUP,0)
EnumWindows_(@CheckWindowsProcess(), 1)
EndIf
Until Eof(1) <> 0
CloseFile(1)
EndSelect
Until Evenement = #PB_Event_CloseWindow

Not a destination