I have the following class declared:
public partial class MainWindow : Window
And I need to get the actual handle of the window once the wi
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern int FindWindowEx(int hwndParent, int hwndEnfant, int lpClasse, string lpTitre);
int hwnd = FindWindowEx(0, 0, 0, title);//where title is the windowtitle
//verification of the window
if (hwnd == 0)
{
throw new Exception("Window not found");
}
The earliest place you can get the handle is OnSourceInitialized
In the OnInitialized
method the handle has not yet been created. But you are on the right track. If you put your call in the Loaded
event the handle will have been created and it should return the correct handle.