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.
Related
I am working on a simple active desktop replacement for a school that is migrating to Windows 7. The idea is to create a window with a few large buttons with pictures on so that young children who have trouble reading can use them.
I am using SetParent() to set my window's parent to 'Progman' so that it is always at the back and is not minimised when a user chooses to 'Show Desktop'. Everything works fine on Windows XP but on Windows 7 when users click 'Show Desktop' the window remains but the contents are replaced with the users Windows background. The buttons still work (you just can't see them) and if you resize or otherwise update the window they appear again. A picture of the problem:
Any ideas why this is happening? Does anyone know a way I could force a refresh of the window when 'Show Desktop' is pressed?
I suspect in your case your app is throwing an exception but not crashing. WPF apps have a tendency to do this if the exception is thrown during the ctor of some UI element. It can disrupt the rendering stack.
I tried to reproduce the problem but was unsuccessful. From my tests I was able to get the handle to 'Progman' and set the main window as the parent when using the Windows 7 basic theme (no Arrow glass).
When I used the Arrow theme, calling SetParent would cause the window to vanish. A little research turned up a possible fix. Instead of setting the parent as the 'Progman' window, you can try using the 'SysListView32' child (the child window used to hold the desktop icons).
The problem is obtaining 'SysListView32' isn't easy. It used to be a matter of traversing through 'Progman' to 'SHELLDLL_DefView' and then 'SysListView32', however, Windows 7 has changed that. 'SHELLDLL_DefView' is now a child of WorkerW.... some of the time.
Here is the best article I could find explaining this:
http://fernandomachadopirizen.wordpress.com/2010/08/09/give-me-a-handle-and-i-will-move-the-earth/
I'm new to windows programming (any win 32 API).
I want to create a windows application that listens to the clipborad all the time and reacts to keyboard shortcuts (for example you copy text from the ClipBoard and press Ctrl-F and something is done on the text in the clipboard).
I know how to make a window app in win32 and in C# (.NET) but it's a windowed application which has a window and appears in the window panel.
I want an pplication that will only be visible in the taskbar right part so you can close it (like most antivirus do) and keeps on running from start will it's closed.
Anyone got some code template, or can reffer me to a tutorial ? i don't mind if it's C\C+ or C#.
10x.
It can be another windows application in which the form's ShowInTaskbar property is set to false and you add a NotifyIcon component to put it into tray. Here is an article from CodeProject. You can find many more on codeproject or on other programming related sites.
You may find this useful, although it's in C.
Or this in C#.
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.
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.
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.