hwnd

How do I GetModuleFileName() if I only have a window handle (hWnd)?

走远了吗. 提交于 2019-11-27 16:24:13
问题 I'm trying to get the name of the executable of a window that is outside my C# 2.0 application. My app currently gets a window handle (hWnd) using the GetForegroundWindow() call from "user32.dll". From the digging that I've been able to do, I think I want to use the GetModuleFileNameEx() function (from PSAPI) to obtain the name, but GetModuleFileNameEx() requires a handle to a Process, not a Window. Is it possible to get a process handle from a window handle? (Do I need to get the thread

How can I tell if a Window has focus? (Win32 API)

a 夏天 提交于 2019-11-27 13:33:37
Using the Win32 API (in C, but that's inconsequential) how can I tell if a given window (identified by HWND) has focus? I'm hooking an application watching for an event, and when that event occurs I want to check if the application already has focus. If it doesn't, I want to flash the window until they give focus to it. Alternately, does the FlashWindowEx struct flag FLASHW_TIMERNOFG that flashes until the window has focus just not flash if the window already has focus? I cannot test this now since I am not in my development environment, but I was under the impression that it would flash

WPF Memory Leak on XP (CMilChannel, HWND)

这一生的挚爱 提交于 2019-11-27 13:22:29
问题 My WPF application leaks memory at about 4kb/s. The memory usage in Task Manager climbs constantly until the application crashes with an "Out of Memory" exception. By doing my own research I have found that the problem is discussed here: Track down memory leak in WPF and #8 here: http://blogs.msdn.com/jgoldb/archive/2008/02/04/finding-memory-leaks-in-wpf-based-applications.aspx The problem described is: This is a leak in WPF present in versions of the framework up to and including .NET 3.5

Insert text into the textbox of another application

和自甴很熟 提交于 2019-11-27 04:33:22
How do I, using C# or C++, insert text into the textbox of another application? I did this a long time ago and seemed to remember something about using the applications HWND. But since that change for every instance of the application I feel that I fon't remember the complete story. Do I somehow get a list of running apps, extract the one I want, get the HWND from that and then... hmm.... then what? :) Use FindWindowEx() to find the handle (HWND) and then send the WM_SETTEXT message using SendMessage() When using FindWindowEx you will need to first find the main window handle by using its

How do I get the handle of a console application's window

元气小坏坏 提交于 2019-11-26 22:43:00
Can someone tell me how to get the handle of a Windows console application in C#? In a Windows Forms application, I would normally try this.Handle . Not sure it works, but you can try that : IntPtr handle = Process.GetCurrentProcess().MainWindowHandle; ivan_pozdeev The aforementioned Process.MainWindowHandle method only works for the process that started the console The FindWindowByCaption method is inherently unreliable Here's a robust way to do this: The related functions from the Console Win32 API are: [DllImport("kernel32.dll", SetLastError = true)] static extern bool AttachConsole(uint

In Java Swing how do you get a Win32 window handle (hwnd) reference to a window?

本秂侑毒 提交于 2019-11-26 22:14:04
In Java 1.4 you could use ((SunToolkit) Toolkit.getDefaultToolkit()).getNativeWindowHandleFromComponent() but that was removed. It looks like you have to use JNI to do this now. Do you have the JNI code and sample Java code to do this? I need this to call the Win32 GetWindowLong and SetWindowLong API calls, which can be done via the Jawin library. I would like something very precise so I can pass a reference to the JDialog or JFrame and get the window handle. Swing transparency using JNI may be related. Jared MacD. You don't have write any C/JNI code. From Java: import sun.awt.windows

How to get tooltip text for a given HWND?

假如想象 提交于 2019-11-26 22:05:38
问题 I'm looking for a way to get the tooltip control (if any) which is associated with a given HWND. The text of the tooltip control would be sufficient, too. The closest thing I found is the TTM_GETTEXT message, but it's meant to be sent to the tooltip control itself instead of the tool it's associated with. I don't have a handle to the tooltip control though. Does anybody know how to do this? All this is done using plain Windows API in C++. 回答1: There doesn't seem to be a specific message to

Get hwnd by process id c++

我的未来我决定 提交于 2019-11-26 21:38:51
问题 How can I get the HWND of application, if I know the process ID? Anyone could post a sample please? I'm using MSV C++ 2010. I found Process::MainWindowHandle but I don't know how to use it. 回答1: HWND g_HWND=NULL; BOOL CALLBACK EnumWindowsProcMy(HWND hwnd,LPARAM lParam) { DWORD lpdwProcessId; GetWindowThreadProcessId(hwnd,&lpdwProcessId); if(lpdwProcessId==lParam) { g_HWND=hwnd; return FALSE; } return TRUE; } EnumWindows(EnumWindowsProcMy,m_ProcessId); 回答2: You can use EnumWindows and

Getting HWND off of CoreWindow object in UWP

人走茶凉 提交于 2019-11-26 21:23:53
问题 This short MSDN documentation says CoreWindow has ICoreWindowInterop that obtains the handle HWND to the CoreWindow. But I cannot find references on how to get it (C#). Help, please. https://msdn.microsoft.com/en-us/library/dn302119(v=vs.85).aspx 回答1: This COM interface is only directly accessible to C++ code. In C# you have to declare it yourself and make it match the interface declaration in C:\Program Files (x86)\Windows Kits\10\Include\10.0.10586.0\winrt\CoreWindow.idl. Like this: using

How can I tell if a Window has focus? (Win32 API)

梦想的初衷 提交于 2019-11-26 16:07:04
问题 Using the Win32 API (in C, but that's inconsequential) how can I tell if a given window (identified by HWND) has focus? I'm hooking an application watching for an event, and when that event occurs I want to check if the application already has focus. If it doesn't, I want to flash the window until they give focus to it. Alternately, does the FlashWindowEx struct flag FLASHW_TIMERNOFG that flashes until the window has focus just not flash if the window already has focus? I cannot test this now