0

I am trying to get the HWND to the instance of Visual Studio that I am currently using to debug my programme but I am a little lost as to how exactly I go about doing that. Do I need to search all the Windows that currently open and then select the right one and get a handle to it. Also what if I have multiple instances of Visual Studio running, how would I get a handle to the correct one?

EDIT: It seemed sensible to add the actual problem here upon reflection and advice in the comments: I have a multiple monitor set up and different instances of visual running on each. I am trying to get the console produced when debugging to appear on the same monitor as the instance of visual studio that generated it so that both consoles do not overlap each other when they are generated.

Lsakurifaisu
  • 133
  • 1
  • 12
  • 8
    This smells like [XY problem](http://meta.stackexchange.com/q/66377/141290) from a thousand miles... What is the actual problem you are trying to solve? – Matteo Italia Nov 13 '13 at 14:59
  • I have a multiple monitor set up and different instances of visual running on each. I am trying to get the console produced when debugging to appear on the same monitor as the instance of visual studio that generated it so that both consoles do not overlap each other when they are generated. – Lsakurifaisu Nov 13 '13 at 15:02
  • This is the first time I have encountered the XY problem, should I delete this question and ask a more specific one? – Lsakurifaisu Nov 13 '13 at 15:03
  • That's not necessary, just edit the original question stating more clearly the general problem and the difficulties you are having with your current solution. – Matteo Italia Nov 13 '13 at 15:16
  • @Lsakurifaisu: No, it's fine. The "XY problem" doesn't always mean that you must have chosen the wrong solution direction. In hindsight it would have been better if you had started by saying what you wanted, instead of putting it in a comment, though. – MSalters Nov 13 '13 at 15:17
  • @MSalters: Thanks for the reply :) I can see why the XY problem is bad thing, I just thought that the solution to the question I asked could help others as well. But I understand by doing this I may not get an answer that is helpful to my problem hence why I should have been more specific with my question. Although I believe I have the knowledge to handle the rest of the problem once I get the correct HWND. – Lsakurifaisu Nov 13 '13 at 15:24
  • So regarding the console window - from within the process you can use [GetConsoleWindow](http://msdn.microsoft.com/en-us/library/windows/desktop/ms683175%28v=vs.85%29.aspx). May not be what you need in the end but this may help you get there. – NtscCobalt Nov 13 '13 at 15:30
  • @NtscCobalt: Thanks for the input but when the console is initially created it is on the primary monitor. So I'm not sure how I would use its HWND to position it relative to the instance of Visual Studio that generated it. – Lsakurifaisu Nov 13 '13 at 15:45
  • @Lsakurifaisu you can use the process parent id (see http://www.codeproject.com/Articles/9893/Get-Parent-Process-PID) to find the Visual Studio instance that launched it and then use [EnumWindows](http://msdn.microsoft.com/en-us/library/ms633497%28VS.85%29.aspx) to find a window belonging to Visual Studio for positioning. This is probably the most convoluted thing of all time so you may want to rethink why you are doing this. – NtscCobalt Nov 13 '13 at 16:27

0 Answers0