Hide external window
Hide external window
hi...
how to hide a window from a external program like notepad for example?
how to hide a window from a external program like notepad for example?
Re: Hide external window
mx101 Hi
1- Run Notepad.exe first
2- Run the next prog. and play with show or hide
Thanks to SFSxOI
Edit: I editted the code I posted it wrong ,Sorry
1- Run Notepad.exe first
2- Run the next prog. and play with show or hide
Thanks to SFSxOI
Code: Select all
#PROCESS_ALL_ACCESS_VISTA_WIN7 = $1FFFFF
Prototype.i PFNCreateToolhelp32Snapshot(dwFlags.i, th32ProcessID.i) ;
Prototype.b PFNProcess32First(hSnapshot.i, *lppe.PROCESSENTRY32) ;
Prototype.b PFNProcess32Next(hSnapshot.i, *lppe.PROCESSENTRY32) ;
Procedure GetPidByName(p_name$)
Protected hDLL.i, process_name$
Protected PEntry.PROCESSENTRY32, hTool32.i
Protected pCreateToolhelp32Snapshot.PFNCreateToolhelp32Snapshot
Protected pProcess32First.PFNProcess32First
Protected pProcess32Next.PFNProcess32Next
Protected pid.i
hDLL = OpenLibrary(#PB_Any,"kernel32.dll")
If hDLL
pCreateToolhelp32Snapshot = GetFunction(hDLL,"CreateToolhelp32Snapshot")
pProcess32First = GetFunction(hDLL,"Process32First")
pProcess32Next = GetFunction(hDLL,"Process32Next")
Else
ProcedureReturn 0
EndIf
PEntry\dwSize = SizeOf(PROCESSENTRY32)
hTool32 = pCreateToolhelp32Snapshot(#TH32CS_SNAPPROCESS, 0)
pProcess32First(hTool32, @PEntry)
process_name$ = Space(#MAX_PATH)
CopyMemory(@PEntry\szExeFile,@process_name$,#MAX_PATH)
If UCase(process_name$) = UCase(p_name$)
ProcedureReturn PEntry\th32ProcessID
EndIf
While pProcess32Next(hTool32, @PEntry) > 0
process_name$ = Space(#MAX_PATH)
CopyMemory(@PEntry\szExeFile,@process_name$,#MAX_PATH)
If UCase(process_name$) = UCase(p_name$)
ProcedureReturn PEntry\th32ProcessID
EndIf
Wend
CloseLibrary(hDLL)
ProcedureReturn 0
EndProcedure
Procedure EnumWindowsProc(hWnd,lParam)
GetWindowThreadProcessId_(hWnd,@lpProc)
If lpProc=PeekL(lParam) ; process passed to EnumWindows is process found at this hwnd
PokeL(lParam,hWnd) ; set ptr to hwnd
ProcedureReturn 0
EndIf
ProcedureReturn 1
EndProcedure
Procedure GetProcessId_(hProcess) ; for windows Vista, Windows XP SP1, Windows 7
Protected hThread
Protected Pid
Protected GCPI
GCPI = GetProcAddress_(GetModuleHandle_("Kernel32"),"GetCurrentProcessId");
hThread = CreateRemoteThread_(hProcess,0,0,GCPI,0,0,0)
If Not hThread
ProcedureReturn 0
EndIf
WaitForSingleObject_(hThread,#INFINITE)
GetExitCodeThread_(hThread,@Pid)
CloseHandle_(hThread)
ProcedureReturn Pid
EndProcedure
Procedure GetProcHwnd(lpProc)
Protected pid = GetProcessId_(lpProc)
ptr=pid
Repeat : Until EnumWindows_(@EnumWindowsProc(),@ptr)
If ptr=pid ; if no handle is returned no matching process was found
ProcedureReturn 0
EndIf
; some form of GetWindow_() here for top-level window..
ProcedureReturn ptr
EndProcedure
#WindowWidth = 310
#WindowHeight = 200
hwnd = OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "PureBasic - Gadget Demonstration", #PB_Window_MinimizeGadget)
Top = 10
GadgetHeight = 24
ButtonGadget(1, 223,#WindowHeight-36, 80, 24, "Hide")
ButtonGadget(2, 120,#WindowHeight-36, 80, 24, "Show")
ButtonGadget(8, 10, #WindowHeight-36, 80, 24, "Quit")
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_Event_Gadget
Select EventGadget()
Case 1
Pid.i = GetPidByName("notepad.exe")
hproc.i = OpenProcess_(#PROCESS_ALL_ACCESS,0,Pid)
hwnd = GetProcHwnd(hproc)
ShowWindow_(hwnd,#SW_HIDE)
Case 2
ShowWindow_(hwnd,#SW_SHOW)
Case 8 ; Quit...
EventID = #PB_Event_CloseWindow
EndSelect
EndIf
Until EventID = #PB_Event_CloseWindow
End
Edit: I editted the code I posted it wrong ,Sorry
Last edited by RASHAD on Thu Jan 07, 2010 5:21 pm, edited 2 times in total.
Egypt my love
Re: Hide external window
thanks but i have compiler error "GetPidByName is not a function, array, macro or link list"RASHAD wrote:mx101 Hi
1- Run Notepad.exe first
2- Run the next prog. and play with show or hide
Thanks to SFSxOI
Code: Select all
#WindowWidth = 310 #WindowHeight = 200 hwnd = OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, "PureBasic - Gadget Demonstration", #PB_Window_MinimizeGadget) Top = 10 GadgetHeight = 24 ButtonGadget(1, 223,#WindowHeight-36, 80, 24, "Hide") ButtonGadget(2, 120,#WindowHeight-36, 80, 24, "Show") ButtonGadget(8, 10, #WindowHeight-36, 80, 24, "Quit") Repeat EventID = WaitWindowEvent() If EventID = #PB_Event_Gadget Select EventGadget() Case 1 Pid.i = GetPidByName("notepad.exe") hproc.i = OpenProcess_(#PROCESS_ALL_ACCESS,0,Pid) hwnd = GetProcHwnd(hproc) ShowWindow_(hwnd,#SW_HIDE) Case 2 ShowWindow_(hwnd,#SW_SHOW) Case 8 ; Quit... EventID = #PB_Event_CloseWindow EndSelect EndIf Until EventID = #PB_Event_CloseWindow End
Re: Hide external window
Sorry mx101
I posted the wrong code ,I allready updated it in the first post
This code is for 64 bit application
If you are running 32 bit OS and application just change all .i to .l
That is all
You can after successful attempt enhance the code to check for the application ( if it is 32 or 64 bit ) first
I posted the wrong code ,I allready updated it in the first post
This code is for 64 bit application
If you are running 32 bit OS and application just change all .i to .l
That is all
You can after successful attempt enhance the code to check for the application ( if it is 32 or 64 bit ) first
Last edited by RASHAD on Thu Jan 07, 2010 5:15 pm, edited 1 time in total.
Egypt my love
Re: Hide external window
nothing to change. Changing is badRASHAD wrote:If you are running 32 bit OS and application just change all .i to .l
The code missing the "GetPidByName()" Function
Re: Hide external window
RASHAD wrote:Sorry mx101
I posted the wrong code ,I allready updated it in the first post
This code is for 64 bit application
If you are running 32 bit OS and application just change all .i to .l
That is all
You can after successful attempt enhance the code to check for the application ( if it is 32 or 64 bit ) first
but i have have same error on 64 bit application.
Re: Hide external window
Sorry Thomas
You are very fast (give me some time man well you?)
Check it now Thomas
You are very fast (give me some time man well you?)
Check it now Thomas
Last edited by RASHAD on Thu Jan 07, 2010 5:22 pm, edited 1 time in total.
Egypt my love
Re: Hide external window
ok work on x64RASHAD wrote:Sorry Thomas
You are very fast (give me some time man well you?)
i had not read that you made the update to the code
thanks for help if can give work code to x86 i appreciate
Re: Hide external window
work on x64 not work on x86RASHAD wrote:Sorry Thomas
You are very fast (give me some time man well you?)
Check it now Thomas
big thanks
- Fluid Byte
- Addict

- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Re: Hide external window
Uhmm, lol?
Code: Select all
hwndNotepad = FindWindow_("Notepad",0)
Delay(100)
ShowWindow_(hwndNotepad,#SW_HIDE)Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
- Rook Zimbabwe
- Addict

- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Re: Hide external window
Why would you need to hide your program from "notepad"???
- Fluid Byte
- Addict

- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Re: Hide external window
Be happy it's just Notepad and not some system critical application 
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Re: Hide external window
@FB Hi
Unfortunately it will not always work
Try it with the Calculator prog for test
Unfortunately it will not always work
Try it with the Calculator prog for test
Egypt my love
-
UserOfPure
- Enthusiast

- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Re: Hide external window
It will work with Calculator, all you need to do is get the exact window title with FindWindow, then use the result of that with ShowWindow and #SW_HIDE.
Re: Hide external window
OK I am using Windows 7 x64
Please put some code using FindWindow_() to hide Calculator prog
mx101 did not say Notepad he said like NotePad so the choices are open
Please check
Please put some code using FindWindow_() to hide Calculator prog
mx101 did not say Notepad he said like NotePad so the choices are open
Please check
Egypt my love



