Windows CE restore other app window in C# - c#

How can I restore other application window from my application?
I know only process name for this application.
I search code for .Net 3.5
Thanks and hope for you reply

It depends on what you know about that other Window, but generally speaking you could P/Invoke to FindWindow and pass in the window's caption. That will get you the target Window's handle. With that you call BringWindowToTop, ShowWindow and/or SetWindowPos (again via P/Invoke) depending on the Window's state and your desires.

Related

Changing size and position of a window belonging to another process

I have a compiled c# console application and I would like to have an option to change a certain window (*.exe from, lets say, task manager) position and size.
Is it possible via the namespaces provided in VS2010?
The target window isn't connected in any way to the exe compiled by VS.
As said in the comments, you definitely have to use the SetWindowPos function.
You will need the window handle. For this you could call EnumWindows, checking the executable file name for each window using GetWindowModuleFileName.
Pseudo code:
foreach window in EnumWindows()
if GetWindowModuleFileName(window) == "program.exe"
SetWindowPos(window, ...)
These functions belong to the Windows API. To call them you will need to P/invoke (pinvoke.net might be of great help).
It's quite possible:
To change window position or/and size you may use SetWindowPos
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx
In order find out window's handle (hWnd argument) you may found useful
FindWindow
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633499(v=vs.85).aspx
EnumWindows
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633497(v=vs.85).aspx

Get window handle from window class name

I'm trying to get a window handle on a child window in my process and the only information I have is the window class name. Are there any win32 functions I can use for that? I'm doing this from C#.
A bit more detail: This is a Visual Studio plugin, written in C#. So my process is visual studio, which has lots of windows. One of them has a window class "VsTipWindow". I don't know the immediate parent window of that window, all I have is the class name. Is there any way for me to get the window handle from just that?
FindWindow is the Win32 call you want for this (or FindWindowEx if there's more than one window with that particular class name, and FindWindow isn't returning the one you're looking for).
just additional information..
maybe it's useful to know that you can get the handle of a window from a point
WindowFromPoint
http://msdn.microsoft.com/en-us/library/ms633558(VS.85).aspx
First off it should be noted that there is not a 1 to 1 relationship between windows and window classes, more than one window could use the same class.
I guess your only option is to call EnumChildWindows recursivly starting with the top level Visual Studio window (Or some other window higher in the window hierarchy if you know one that is a grandparent of the VsTipWindow window) In the callback function from EnumChildWindows you would call GetClassName and compare the string with VsTipWindow until you find the window.
Since you talked about unknown parent I'm assuming that you are after a child window, but if this window is a top level window, you need to use EnumWindows (And you should probably use GetWindowThreadProcessId to make sure you get the correct process also after you find a window with that classname)
(I'm sure .NET has functions that do the same thing as the native api, or you'd have to PInvoke)
A Win32 window class is the generic implementation of a control, the handle of the windows is the instance of the control. So you will have multiple window handles with the same window class (e.g.: EDIT). Strictly speaking, a window class is the pointer to the window procedure.
Frameworks like .net (and even MFC) tend to share few window class for all the windows controls, and then they will dispatch to the appropriate controls (i.e. they have a single generic window procedure). This is the same also for big applications like Visual Studio or Office.
So this renders very difficult to detect a specific windows just through its window class. However, you can enumerate all the windows that have a specific windows class with FindWindow, you will get also the window text that may help you. Using GetWindowThreadProcessId you can detect if the window is belonging to Visual Studio.

SetParent() on a VB6 application from a C# app

I am trying to use the win32 API to set the parent of an application to a panel in my C# application.
When I inspect it using Spy++ the application loads in 2 main forms ThunderRT6Main and ThunderRT6MDIForm both with the same title.
I have found the handle of both of these and tried to call SetParent on them both but the window does nothing and does not move anywhere...
Is there something funky I need to do when invoking SetParent() on a VB6 app?
ThunderRT6Main is the hidden owner of every top level form in VB6. It sets the application icon, the one you see in the Applications tab of Task Manager. You can read this interesting article
A window can have a parent or an owner but not both
Basicly you might need WS_CHILD set before calling SetParent.

WPF opening up exe program within WPF window

Not sure if this is possible but is there a way to open up another program like notepad within the container of a WPF window? similiar to that of being able to open a web page using the webbrowser control?
Basically I would like to open notepad or other exe but keep it constrained within the WPF window container using xaml/c# code? not sure if possible?
Yes it is possible.
All you have to do is:
Create a WindowsFormsHost and add it to a panel in your UI
Start the process (such as Notepad) using Process.Start
Call process.WaitForInputIdle
Use process.MainWindowHandle to get the window handle
Call SetWindowPos to set the process's window to the coordinates and Z Order of the HwndHost window
Hook both the HwndHost and the process.MainWindowHandle to detect size changes and repeat step 5.
It is quite straightforward to do all of this. The effect is the entire Notepad window (or whatever application you started) appears and behaves exactly as if it were part of your WPF application.
managed to do this using the SetParent method
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hwc, IntPtr hwp);
so by getting the handles for wpf window and then the exe window, I was able to set the wpf window as parent so it gave a simulation of being embedded (also closed the title bar etc)
got help from here: http://channel9.msdn.com/forums/TechOff/250417-Hide-window-caption-in-c/
You can't do that.
The reason you can view a web page is because IE was designed using an architecture that allows it - the rendering engine isn't actually part of the actual IE executable, but a DLL which exposes a component.
Generic EXEs do not work that way, and you cannot embed them inside your app.

Restore application from system tray

What is the best way to programmatically restore and give focus to a third-party application (say, GoogleTalk or Twhirl) running in the system tray? I am writing my utility in C#, but I obviously have no control over the third-party application.
Use something like FindWindow /FindWindowEx to find the hidden window and get its window handle and then call ShowWindow ( handle, SW_NORMAL) to unhide it.
Use a tool like Spy++ (can be found in the visual studio tools menu) to find the parameters which can be passed on to FindWindow to locate the desired window.
Use an API call to send mouse click events to the system tray? Google WM_SENDMSG SendMessage Win32 API for a starting point
There's also another API call for setting focus once the window's back up.

Categories