Click here to Skip to main content
15,892,746 members
Home / Discussions / C#
   

C#

 
AnswerRe: How can I dictate the position of the run prompt? Pin
Dave Kreskowiak28-Apr-14 9:28
mveDave Kreskowiak28-Apr-14 9:28 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk328-Apr-14 9:44
turbosupramk328-Apr-14 9:44 
GeneralRe: How can I dictate the position of the run prompt? Pin
Dave Kreskowiak28-Apr-14 10:26
mveDave Kreskowiak28-Apr-14 10:26 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk328-Apr-14 11:02
turbosupramk328-Apr-14 11:02 
GeneralRe: How can I dictate the position of the run prompt? Pin
Dave Kreskowiak28-Apr-14 13:43
mveDave Kreskowiak28-Apr-14 13:43 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk328-Apr-14 15:26
turbosupramk328-Apr-14 15:26 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk329-Apr-14 2:35
turbosupramk329-Apr-14 2:35 
GeneralRe: How can I dictate the position of the run prompt? Pin
Alan N29-Apr-14 6:14
Alan N29-Apr-14 6:14 
You haven't said how you are trying to get the handle of the Run window but it is possible with the native function EnumWindows.

C#
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

public class ProcessWindowFinder {
  [DllImport("user32.dll", SetLastError = true)]
  [return: MarshalAs(UnmanagedType.Bool)]
  static extern bool EnumWindows(EnumWindowsProc callbackMethod, IntPtr state);

  [DllImport("user32.dll")]
  static extern UInt32 GetWindowThreadProcessId(
    [In] IntPtr hwnd,
    out UInt32 processId);

  delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr state);

  public void FindWindows(Process selectedProcess) {
    EnumWindows(SelectWindowsByPID, (IntPtr)selectedProcess.Id);
  }

  private bool SelectWindowsByPID(IntPtr hwnd, IntPtr state) {
    Int32 pid = state.ToInt32();
    Int32 windowPid = GetWindowPID(hwnd);
    if (pid == windowPid) {
      // Do something here,
      // e.g. raise an event to pass hwnd to subscribers
    }
    return true;
  }

  private Int32 GetWindowPID(IntPtr hwnd) {
    UInt32 PID;
    GetWindowThreadProcessId(hwnd, out PID);
    return unchecked((Int32)PID);
  }
}



The callback function SelectWindowsByPID filters the handles down to those belonging to the selected process, in your case rundll32. You could filter further by window text (native GetWindowText) and visibility (native IsWindowVisible) but I think that final application specific filtering should really be done outside the ProcessWindowFinder class which is why I suggest raising an event.

Alan.
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk329-Apr-14 9:14
turbosupramk329-Apr-14 9:14 
GeneralRe: How can I dictate the position of the run prompt? Pin
Dave Kreskowiak29-Apr-14 10:36
mveDave Kreskowiak29-Apr-14 10:36 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk330-Apr-14 6:02
turbosupramk330-Apr-14 6:02 
GeneralRe: How can I dictate the position of the run prompt? Pin
Dave Kreskowiak30-Apr-14 8:16
mveDave Kreskowiak30-Apr-14 8:16 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk330-Apr-14 8:49
turbosupramk330-Apr-14 8:49 
GeneralRe: How can I dictate the position of the run prompt? Pin
Alan N29-Apr-14 11:25
Alan N29-Apr-14 11:25 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk330-Apr-14 6:11
turbosupramk330-Apr-14 6:11 
GeneralRe: How can I dictate the position of the run prompt? Pin
Alan N1-May-14 3:12
Alan N1-May-14 3:12 
GeneralRe: How can I dictate the position of the run prompt? Pin
turbosupramk32-May-14 1:46
turbosupramk32-May-14 1:46 
QuestionImplementing transaction in MVC as Attribute Pin
nitin_ion28-Apr-14 0:12
nitin_ion28-Apr-14 0:12 
AnswerRe: Implementing transaction in MVC as Attribute Pin
Dave Kreskowiak28-Apr-14 3:18
mveDave Kreskowiak28-Apr-14 3:18 
GeneralRe: Implementing transaction in MVC as Attribute Pin
nitin_ion28-Apr-14 17:19
nitin_ion28-Apr-14 17:19 
GeneralRe: Implementing transaction in MVC as Attribute Pin
Dave Kreskowiak28-Apr-14 17:55
mveDave Kreskowiak28-Apr-14 17:55 
QuestionHow to use Multithreading in Async Socket Http request Pin
sbmzhcn27-Apr-14 15:22
sbmzhcn27-Apr-14 15:22 
Questionlooking for a decent book on c# for advanced programmers Pin
Nico Haegens27-Apr-14 1:10
professionalNico Haegens27-Apr-14 1:10 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
Pete O'Hanlon27-Apr-14 1:59
mvePete O'Hanlon27-Apr-14 1:59 
AnswerRe: looking for a decent book on c# for advanced programmers Pin
BillWoodruff27-Apr-14 7:08
professionalBillWoodruff27-Apr-14 7:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.