I remember in VB6
i was able to get the handle of a form of a software that's currently running, and change it from outside with some API functions.
Is it possible to do with c#? how? The problem is that this software is in a different language. I want to change some of it to English.
Asked
Active
Viewed 1,789 times
2
-
have you searched stackoverflow? simple search yielded lots of similar questions : for example http://stackoverflow.com/questions/5822026/get-wpf-window-by-hwnd – Michael Nov 07 '12 at 08:37
-
That's for WPF though, which doesn't appear very similar to the answers given here – Kestami Nov 07 '12 at 09:18
2 Answers
2
Try to use FindWindow
and SetWindowText
from Win32 API:
FindWindow
c# signature:
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
SetWindowText
c# signature:
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool SetWindowText(IntPtr hwnd, String lpString);
and a sample cod:
SetWindowText(Process.GetCurrentProcess().MainWindowHandle, "Hello W");

Ria
- 10,237
- 3
- 33
- 60
1
1) In WinForms there is an "Handle" property in Control class (all controls and Form class derive from it (MSDN article)
2) In WPF there is no HWND handle exposed, but you can get it by using WindowInteropHelper class.
you can get it like this:
WindowInteropHelper wih = new WindowInteropHelper(YourWindow);
IntPtr hwndHandle = wih.Handle;

Michael
- 860
- 7
- 19