Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "AfxPath.inc"
Global hDlg, PID, hBrowser As Dword, BrowserEXE$$
%IDC_Open = 500
%IDC_GetBrowserHandle = 501
%IDC_MoveBrowser = 502
%IDC_ListView = 503
Function PBMain() As Long
Dialog Default Font "Tahoma", 12, 1
Dialog New Pixels, 0, "",200,200,650,300, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Open,"Open Browser", 10,10,130,25
Control Add Button, hDlg, %IDC_GetBrowserHandle,"Get Handles", 10,50,130,25
Control Add Button, hDlg, %IDC_MoveBrowser, "Move Browser", 10,90,130,25
Control Add ListView, hDlg, %IDC_ListView,"" , 150,10,490,400
ListView Insert Column hDlg, %IDC_ListView, 1, "hWnd", 150, 0
ListView Insert Column hDlg, %IDC_ListView, 2, "EXE", 320, 0
Dialog Set Text hDlg, Str$(hDlg)
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local iReturn,w,h As Long, hKey As Dword
Select Case Cb.Msg
Case %WM_InitDialog
BrowserEXE$$ = AfxGetDefaultBrowserpath
Dialog Set Text hDlg, "Default Browser: " + BrowserEXE$$
Case %WM_Size
Dialog Get Client hDlg To w,h
Control Set Size hDlg, %IDC_ListView, 490, h-20
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Open
iReturn = ShellExecute(hDlg, "Open", "http://www.garybeene.com/", $Nul, $Nul, %SW_ShowNormal)
Case %IDC_MoveBrowser
SetWindowPos hBrowser, %Hwnd_NoTopMost, 0,0,0,0, %SWP_NoSize
Case %IDC_GetBrowserHandle
EnumWindows CodePtr(EnumCallBack), 0&
ListView Sort hDlg, %IDC_ListView, 2, Descend
End Select
End Select
End Function
Function EnumCallback (ByVal hWnd As Long, lParam As Long) As Long
Local PID,hProcess As Dword, EXEName As WStringZ*%Max_Path
ListView Insert Item hDlg, %IDC_ListView, 1, 0, Hex$(hWnd)
GetWindowThreadProcessID(hWnd,PID)
hProcess = OpenProcess(%Process_Query_Information Or %Process_VM_Read, %False, PID)
GetModuleBaseName(hProcess, %Null, EXEName, %Max_Path)
CloseHandle(hProcess)
ListView Set Text hDlg, %IDC_ListView, 1,2, ExeName
Function = 1
End Function
http://www.garybeene.com/sw/gbsnippets.htm