[Closed] Hiding Notepad
Hello!
So I’m simply trying to hide a a window with setWindowPos such as Notepad, for example. This is what I got so far:
theHWND = for n in (windows.getChildrenHWND 0) where n[4] == "Notepad" do exit with n[1]
HWND_NOTOPMOST = -2
SWP_HIDEWINDOW = 0x0080
setwindowpos theHWND HWND_NOTOPMOST 0 0 0 0 SWP_HIDEWINDOW
So my question is why isn’t it working? And why does this work?
Does setwindowpos only work with 3dsmax children? :shrug:
Here’s some code I’ve used before to restore/maximize a custom app
fn maximizeUI =
(
SC_CLOSE = 0xF060
C_MAXIMIZE = 0xF030
SC_MINIMIZE = 0xF020
SC_RESTORE = 0xF120
SC_HOTKEY = 0xF150
WM_SYSCOMMAND = 0x112
-- Run windows Notepad here...
-- get nodepad's window hwnd:
hwnd = windows.getchildhwnd 0 "Obj_toApp"
-- restore
windows.SendMessage hwnd[1] WM_SYSCOMMAND SC_MINIMIZE 0
windows.SendMessage hwnd[1] WM_SYSCOMMAND SC_RESTORE 0
)
Hmmm thanks! It’s not exactly what I was looking for. I want to hide and show the window.
As a matter of fact I just found the solution, thanks to DenisT of course! I changed it a bit so it does what I want it to do.
fn CreateUser32Assembly forceRecompile:on =
(
if (forceRecompile or
(classof ::User32Assembly) != dotNetObject or
((::User32Assembly.GetType()).ToString()) != "System.Reflection.Assembly") do
(
source = "using System;
"
source += "using System.Runtime.InteropServices;
"
source += "class User32
"
source += "{
"
source += " [DllImport(\"User32.DLL\", EntryPoint=\"GetWindowLong\")]
"
source += " public static extern Int32 GetWindowLong(IntPtr hWnd, Int32 index);
"
source += " [DllImport(\"User32.DLL\", EntryPoint=\"SetWindowLong\")]
"
source += " public static extern Int32 SetWindowLong(IntPtr hWnd, Int32 index, Int32 newVal);
"
source += " [DllImport(\"User32.DLL\", EntryPoint=\"SetWindowLong\")]
"
source += " public static extern Int32 SetWindowLongPtr(IntPtr hWnd, Int32 index, IntPtr dwNewLong);
"
source += " [DllImport(\"user32.dll\")]
"
source += " public static extern bool SetWindowPos(IntPtr hWnd, int hWndArg, int Left, int Top, int Width, int Height, int hWndFlags);
"
source += "}
"
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.GenerateInMemory = true
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
::User32Assembly = compilerResults.CompiledAssembly
)
::User32Assembly.CreateInstance "User32"
)
global User32 = CreateUser32Assembly()
fn setOwnerWindow hwnd =
(
hwnd = dotnetobject "IntPtr" hwnd
::User32.SetWindowPos hwnd -2 0 0 0 0 0x0080 -- hide window
hwnd
)
theHWND = for n in (windows.getChildrenHWND 0) where n[4] == "Notepad" do exit with n[1]
setOwnerWindow theHWND
I found the snippet of code here.
But I still have the same question, why does this work and this doesn’t?
edit: stripped a couple more things from the code snippet.
That’s the first thing I tried! And it did not work. (Of course I might have screwed up). I googled a bit and I found a couple of threads of people saying that in order to hide a window properly it must be done with SetWindowPos instead of SW_HIDE.
Edit: Sorry… I might have tried to send SW_HIDE through SendMessage… let me try again
Sorry can’t test it Denis, it’s still too advanced for me.
This is what I got:
theHWND = for n in (windows.getChildrenHWND 0) where n[4] == "Notepad" do exit with n[1]
SW_HIDE = 0
ShowWindow theHWND SW_HIDE
ShowWindow is not doing nothing obviously, I need to create a proper User32 assembly, am I right? That’s the part I still don’t know how to do.
does it mean that you want to hide the window without disposing the window hwnd? which means you want to hide the window and not close it. is it correct?
i will take a look at it tomorrow… but… why do you open the Notepad to close it later? i smell that you are making something cool which you don’t want to tell us …
haha you got me! I used Notepad just for the example.
I’m actually working on my little experiment. I’m trying to bring 3dsMax and Unreal closer together.
To be even more precise, I need to show and hide a certain dialog within the Unreal 3 Editor and manually send clicks to a listview in order to select objects in the Unreal 3 scene. So, if everything works as it should… I should be able to select objects in Unreal from 3dsMax (and then do stuff to them, hehe)
Check it out if you want:
http://www.youtube.com/watch?v=LDgwbrhOVSY
I actually used a few snippets from another thread over here about the extended viewports. It’s actually what got me thinking! Before I had to have Unreal3 and 3dsmax open side by side if I wanted to see the changes in real time. This way it’s much more convenient!
So anyway, long story short, want to thank you and this subforum again. If it wasn’t for you guys I wouldn’t be learning so much these past 2 years.
here is a list of user32 functions to do want you need:
global _user32 =
(
source = "using System;
"
source += "using System.Runtime.InteropServices;
"
source += "class User32
"
source += "{
"
source += " [DllImport(\"user32.dll\")]
"
source += " public static extern bool ShowWindow(Int64 hWnd, int nCmdShow);
"
source += " static int SW_HIDE = 0x0;
"
source += " static int SW_SHOWNORMAL = 0x1;
"
source += " static int SW_SHOWMINIMIZED = 0x2;
"
source += " static int SW_SHOWMAXIMIZED = 0x3;
"
source += " static int SW_SHOWNOACTIVATE = 0x4;
"
source += " static int SW_SHOW = 0x5;
"
source += " static int SW_MINIMIZE = 0x6;
"
source += " static int SW_SHOWMINNOACTIVE= 0x7;
"
source += " static int SW_SHOWNA = 0x8;
"
source += " static int SW_RESTORE = 0x9;
"
source += " static int SW_SHOWDEFAULT = 0x10;
"
source += " static int SW_FORCEMINIMIZE = 0x11;
"
source += " public bool ShowWindowHide(Int64 hWnd) { return ShowWindow(hWnd, SW_HIDE); }
"
source += " public bool ShowWindowShow(Int64 hWnd) { return ShowWindow(hWnd, SW_SHOW); }
"
source += " public bool ShowWindowMinimize(Int64 hWnd) { return ShowWindow(hWnd, SW_MINIMIZE); }
"
source += " public bool ShowWindowRestore(Int64 hWnd) { return ShowWindow(hWnd, SW_RESTORE); }
"
source += " [DllImport(\"user32.dll\")]
"
source += " public static extern bool CloseWindow(Int64 hWnd);
"
source += " [DllImport(\"user32.dll\")]
"
source += " public static extern bool DestroyWindow(Int64 hWnd);
"
source += " [DllImport(\"user32.dll\")]
"
source += " public static extern int SendMessage(Int64 hWnd, int wMsg, int wParam, int lParam);
"
source += " static int WM_CLOSE = 0x0010;
"
source += " public bool DestroyWindow(Int64 hWnd, bool complete)
"
source += " {
"
source += " return ((complete) ? Convert.ToBoolean(SendMessage(hWnd, WM_CLOSE, 0, 0)) : DestroyWindow(hWnd));
"
source += " }
"
source += "}
"
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add "System.dll"
compilerParams.ReferencedAssemblies.Add "System.Drawing.dll"
compilerParams.GenerateInMemory = on
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
compilerResults.CompiledAssembly.CreateInstance "User32"
)
/*
(
-- #1 ************************************ --
HiddenDOSCommand "notepad" startpath:@"c:\" donotwait:on
-- #2 ********************************* --
notepad_hwnd = for w in (windows.getchildrenhwnd 0) where w[4] == "Notepad" do exit with w[1]
-- #3 ********************************* --
_user32.ShowWindowHide notepad_hwnd
-- #5 ********************************* --
_user32.ShowWindowShow notepad_hwnd
-- #6 ********************************* --
_user32.CloseWindow notepad_hwnd
-- #7 ********************************* -- show no activate
_user32.ShowWindow notepad_hwnd 0x4
-- #8 ********************************* -- can't because created in other thread
_user32.DestroyWindow notepad_hwnd
-- #9 ************************************ -- destroy complete!
_user32.DestroyWindow notepad_hwnd on
)
*/