Et bah mon OLLIVIER, j'ai démarré....
Code : Tout sélectionner
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