It is currently Tue Feb 25, 2020 12:23 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Handle of a windows explorer window [Resolved]
PostPosted: Fri Apr 05, 2019 9:46 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4631
Location: Lyon - France
Hello at all :D

I want to retrieve the Hwnd of a windows explorer window from runprogram
I don't want use FindWindow_(#Null, "TitleExplorerWindow") because sometime two windows can have the same title

But why the NETMAESTRO code not works with "Explorer.exe" :|
viewtopic.php?p=222224#p222224

Code:
Procedure EnumProc(hwnd, param)
  *handle.LONG = param
  *handle\l = hwnd
  ProcedureReturn 0
EndProcedure

Procedure RunProgramEx(file$,param$,dir$,showflag)
  If Left(param$,1)<>" " : param$=" "+param$ : EndIf
  Info.STARTUPINFO : Info\cb=SizeOf(STARTUPINFO) : Info\dwFlags=1
  Info\wShowWindow=showflag : ProcessInfo.PROCESS_INFORMATION
  If CreateProcess_(@file$,@param$,0,0,0,#NORMAL_PRIORITY_CLASS,0,@dir$,@Info,@ProcessInfo)
    ThreadID=ProcessInfo\dwThreadID
  EndIf
  ProcedureReturn ThreadID
EndProcedure


ThreadID=RunProgramEx("c:\windows\explorer.exe", "/n, c:\", "c:\windows\",#SW_SHOW)
Sleep_(2000)
EnumThreadWindows_(ThreadId, @EnumProc(), @hWnd.l)
PostMessage_(hWnd,#WM_CLOSE,0,0) ; Now close it.

and nothing better with the BBANELLI code :|
viewtopic.php?p=459955#p459955

Code:
EnableExplicit

Define.MODULEENTRY32 Entry
Define.i handle, res, PID, hWnd
Define *Buffer
Define rect.RECT
Define.i w, h

*Buffer = AllocateMemory(256)
Entry\dwSize = SizeOf(MODULEENTRY32)

RunProgram("c:\windows\explorer.exe", "\n, c:\", "c:\windows\")
Repeat
  hWnd = GetForegroundWindow_()
  If hWnd
    GetWindowThreadProcessId_(hWnd, @PID)
    GetWindowText_(hWnd, *Buffer, 255)
    handle = CreateToolhelp32Snapshot_(#TH32CS_SNAPMODULE, PID)
    If handle
      res = Module32First_(handle, Entry)
      If res
      EndIf
      CloseHandle_(handle)
    EndIf
  EndIf

Until LCase(PeekS(@Entry\szModule,-1)) = "explorer.exe"
If GetWindowRect_(hWnd, @rect)
  w = rect\right - rect\left
  h = rect\bottom - rect\top
EndIf
SetWindowPos_(hWnd, #Null, 0, 0, w, h, #Null)
End

Have a good day

_________________
ImageThe happiness is a road...
Not a destination


Last edited by Kwai chang caine on Wed Apr 17, 2019 12:21 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Handle of a windows explorer window
PostPosted: Sat Apr 06, 2019 7:19 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4631
Location: Lyon - France
Nobody know how have this HWND :cry:

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Handle of a windows explorer window
PostPosted: Sun Apr 07, 2019 12:55 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1905
Kwai chang caine wrote:
I want to retrieve the Hwnd of a windows explorer window from runprogram

Try this -> viewtopic.php?p=222199#p222199


Top
 Profile  
Reply with quote  
 Post subject: Re: Handle of a windows explorer window
PostPosted: Sun Apr 07, 2019 8:58 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4631
Location: Lyon - France
Hello DUDE :D
Thanks to your answer 8)

I have try the PB code and one more time, like NETMAESTRO and BBANELLI codes, that not works here with W10 v5.70 x86 :|

Code:
Procedure RunProgramEx(file$,param$,dir$,showflag)
  If Left(param$,1)<>" " : param$=" "+param$ : EndIf
  Info.STARTUPINFO : Info\cb=SizeOf(STARTUPINFO) : Info\dwFlags=1
  Info\wShowWindow=showflag : ProcessInfo.PROCESS_INFORMATION
  If CreateProcess_(@file$,@param$,0,0,0,#NORMAL_PRIORITY_CLASS,0,@dir$,@Info,@ProcessInfo)
    ProcessID=ProcessInfo\dwProcessId
    Repeat
      win=FindWindow_(0,0)
      While win<>0
        GetWindowThreadProcessId_(win,@pid)
        If pid=ProcessID : WinHandle=win : Break : EndIf
        win=GetWindow_(win,#GW_HWNDNEXT)
      Wend
    Until WinHandle
  EndIf
  ProcedureReturn WinHandle
EndProcedure

app$="c:\windows\explorer.exe" ; Full path needed!
hWnd=RunProgramEx(app$,"\n, c:\",GetPathPart(app$),#SW_SHOW)
Debug hWnd
Sleep_(2000) ; Give it a couple of seconds to open.
PostMessage_(hWnd,#WM_CLOSE,0,0) ; Now close it.

It's an history of mad, :shock:
The code is locked in the loop
Code:
While win<>0
 GetWindowThreadProcessId_(win,@pid)
 If pid=ProcessID : WinHandle=win : Break : EndIf
   win=GetWindow_(win,#GW_HWNDNEXT)
 Wend
And i don't understand why :|

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Handle of a windows explorer window
PostPosted: Sun Apr 07, 2019 1:16 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3514
Hi KCC
Code:
Global fhWnd

RunProgram("c:\windows\explorer.exe", " /n, c:\", "c:\windows\")
Delay(3000)

Procedure EnumRunningWindows()
  Protected hWnd
  hWnd = FindWindow_(0, 0)
  Repeat
    hWnd = GetWindow_(hWnd, #GW_HWNDNEXT)
    If hWnd And IsWindowVisible_(hWnd) And GetWindowLongPtr_(hWnd, #GWL_HWNDPARENT) = 0
      Protected txt${#MAX_PATH}
      GetWindowText_(hWnd, @txt$, #MAX_PATH)
      If txt$ <> "" And txt$ <> "Start" And txt$ <> "Program Manager"
        fhwnd = hwnd
        Break
      EndIf
    EndIf
  Until hWnd = 0
  ProcedureReturn #True
EndProcedure

EnumRunningWindows()

SendMessage_(fhwnd,#WM_CLOSE,0,0)


_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Handle of a windows explorer window
PostPosted: Sun Apr 07, 2019 1:41 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2232
Location: Germany
Only the last active explorer...
Code:
*title = AllocateMemory(#MAX_PATH)

RunProgram("c:\windows\explorer.exe", " /n, c:\", "c:\windows\")
RunProgram("c:\windows\explorer.exe", " /n, d:\", "c:\windows\")
Delay(3000)

Repeat
  hWnd = FindWindow_("CabinetWClass", 0)
  If Not hWnd
    Break
  EndIf
  GetWindowText_(hWnd, *title, #MAX_PATH)
  Debug PeekS(*title)
  Delay(2000)
ForEver

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Handle of a windows explorer window
PostPosted: Sun Apr 07, 2019 5:19 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4631
Location: Lyon - France
Thanks at you two my friends 8)
Your two codes works
Two differents handles detected for the two explorer windows of the same path :D

RASHAD
Code:
Global fhWnd

Procedure EnumRunningWindows()
  Protected hWnd
  hWnd = FindWindow_(0, 0)
  Repeat
    hWnd = GetWindow_(hWnd, #GW_HWNDNEXT)
    If hWnd And IsWindowVisible_(hWnd) And GetWindowLongPtr_(hWnd, #GWL_HWNDPARENT) = 0
      Protected txt${#MAX_PATH}
      GetWindowText_(hWnd, @txt$, #MAX_PATH)
      If txt$ <> "" And txt$ <> "Start" And txt$ <> "Program Manager"
        fhwnd = hwnd
        Break
      EndIf
    EndIf
  Until hWnd = 0
  ProcedureReturn #True
EndProcedure

RunProgram("c:\windows\explorer.exe", " /n, c:\", "c:\windows\")
Delay(3000)
EnumRunningWindows()
Debug fhwnd
RunProgram("c:\windows\explorer.exe", " /n, c:\", "c:\windows\")
Delay(3000)
EnumRunningWindows()
Debug fhwnd


MKSOFT
Code:
RunProgram("c:\windows\explorer.exe", " /n, c:\", "c:\windows\")
Delay(2000)
hWnd = FindWindow_("CabinetWClass", 0)
Debug hWnd
RunProgram("c:\windows\explorer.exe", " /n, c:\", "c:\windows\")
Delay(2000)
hWnd = FindWindow_("CabinetWClass", 0)
Debug hWnd

I wish, at you three, a very good end of week

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye