---
title: "How to get handle to the window in wpf?"  
description: "How to get handle to the window in wpf?"  
author: "Anonymous User"  
published: 2013-09-23  
updated: 2013-09-23  
canonical: https://www.mindstick.com/forum/1487/how-to-get-handle-to-the-window-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# How to get handle to the window in wpf?

I got a WPF [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects), which is compiled into a dll and will be called from another [application](https://www.mindstick.com/articles/12824/calculator-application-in-android). That's how it is set up. In this WPF project I need to [pop up](https://answers.mindstick.com/qa/50233/what-to-do-with-the-issues-that-may-pop-up-at-the-time-of-usb-device-installation) a customized [message](https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net) box from the [view model](https://www.mindstick.com/forum/160237/explain-razor-view-model-binding-how-does-it-work-and-why-is-it-important) of the main [window](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript) to show [messages](https://www.mindstick.com/news/4166/google-rolling-out-gemini-extensions-for-messages-whatsapp-and-spotify) to the user. This customized message box requires a Window parameter. That's how it is.

For a WPF application, Application.Current.MainWindow will get me what I need. But here it is a dll, so Application.Current is null, and [leads](https://www.mindstick.com/articles/12410/how-can-online-leads-lift-your-roi) to run time exception. I also tried something like Window.GetWindow(this). Here it is not working, because 'this' is the view model, so it won't give me the [handle](https://www.mindstick.com/articles/311004/suede-skillet-handle-cover) of the main window.

What else can I try to get the handle of the main window here?

Thanks.

## Replies

### Reply by Sumit Kesarwani

Hi Pravesh,

Once you get the application dll, and assuming you know the window's name, you can get and instaniate it through reflection

string myWpfAssemblyPath = ""; // Enter the path to your application here

Assembly wpfAppAssembly = Assembly.Load(myWpfAssemblyPath);

var MainWindow = (Window)wpfAppAssembly.CreateInstance("myMainWindow");

Note that this will create a new instance of the window, and not get you a handle of a window that is already running. to get a window handle that is already instansiated, you could use WIN32 API.


---

Original Source: https://www.mindstick.com/forum/1487/how-to-get-handle-to-the-window-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
