Click here to Skip to main content
15,886,362 members
Home / Discussions / C#
   

C#

 
QuestionGradient arc Pin
FaraonKture31-Jul-13 21:30
FaraonKture31-Jul-13 21:30 
AnswerRe: Gradient arc Pin
Pete O'Hanlon31-Jul-13 22:22
mvePete O'Hanlon31-Jul-13 22:22 
AnswerRe: Gradient arc Pin
Abhinav S31-Jul-13 22:35
Abhinav S31-Jul-13 22:35 
QuestionWMI with service application Pin
Andre O Rahming31-Jul-13 12:37
Andre O Rahming31-Jul-13 12:37 
AnswerRe: WMI with service application Pin
Garth J Lancaster31-Jul-13 14:24
professionalGarth J Lancaster31-Jul-13 14:24 
AnswerRe: WMI with service application Pin
Abhinav S31-Jul-13 19:47
Abhinav S31-Jul-13 19:47 
AnswerRe: WMI with service application Pin
Bernhard Hiller31-Jul-13 21:05
Bernhard Hiller31-Jul-13 21:05 
QuestionHow to get window z order using GetTopMostWindow api Pin
bunge-bunge31-Jul-13 7:49
bunge-bunge31-Jul-13 7:49 
Hi,
I'm very new in c# code. I would like to have a list a windows that open in current desktop in window z order.I have go through the internet and found this code

C#
public partial class Form1 : Form
  {
      public const int GW_HWNDNEXT = 2; // The next window is below the specified window
      public const int GW_HWNDPREV = 3; // The previous window is above

      [DllImport("user32.dll")]
      static extern IntPtr GetTopWindow(IntPtr hWnd);

      [DllImport("user32.dll")]
      [return: MarshalAs(UnmanagedType.Bool)]
      static extern bool IsWindowVisible(IntPtr hWnd);

      [DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "GetWindow", SetLastError = true)]
      public static extern IntPtr GetNextWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.U4)] int wFlag);

      public Form1()
      {
          InitializeComponent();

          //how to get the return value from here???
      }

      public static Form GetTopMostWindow(IntPtr hWnd_mainFrm)
      {
          Form frm = null;

          IntPtr hwnd = GetTopWindow((IntPtr)null);
          if (hwnd != IntPtr.Zero)
          {
              while ((!IsWindowVisible(hwnd) || frm == null) && hwnd != hWnd_mainFrm)
              {
                  // Get next window under the current handler
                  hwnd = GetNextWindow(hwnd, GW_HWNDNEXT);

                  try
                  {
                      frm = (Form)Form.FromHandle(hwnd);
                  }
                  catch
                  {
                      // Weird behaviour: In some cases, trying to cast to a Form a handle of an object
                      // that isn't a form will just return null. In other cases, will throw an exception.
                  }
              }
          }

          return frm;
      }



  }


My question how to get the GetTopMostWindow() return value from form1() class?

Thank you Smile | :)
AnswerRe: How to get window z order using GetTopMostWindow api Pin
Eddy Vluggen31-Jul-13 8:49
professionalEddy Vluggen31-Jul-13 8:49 
QuestionWhat do you think this is about? Pin
Jasmine250131-Jul-13 7:22
Jasmine250131-Jul-13 7:22 
AnswerRe: What do you think this is about? Pin
Eddy Vluggen31-Jul-13 8:46
professionalEddy Vluggen31-Jul-13 8:46 
GeneralRe: What do you think this is about? Pin
Jasmine250131-Jul-13 9:06
Jasmine250131-Jul-13 9:06 
GeneralRe: What do you think this is about? Pin
Eddy Vluggen31-Jul-13 10:42
professionalEddy Vluggen31-Jul-13 10:42 
GeneralRe: What do you think this is about? Pin
Jasmine250131-Jul-13 11:13
Jasmine250131-Jul-13 11:13 
AnswerRe: What do you think this is about? Pin
Ravi Bhavnani31-Jul-13 10:46
professionalRavi Bhavnani31-Jul-13 10:46 
GeneralRe: What do you think this is about? Pin
Jasmine250131-Jul-13 11:18
Jasmine250131-Jul-13 11:18 
GeneralRe: What do you think this is about? Pin
Ravi Bhavnani31-Jul-13 12:02
professionalRavi Bhavnani31-Jul-13 12:02 
GeneralRe: What do you think this is about? Pin
Jasmine250131-Jul-13 12:23
Jasmine250131-Jul-13 12:23 
GeneralRe: What do you think this is about? Pin
Ravi Bhavnani31-Jul-13 12:39
professionalRavi Bhavnani31-Jul-13 12:39 
AnswerRe: What do you think this is about? Pin
Bernhard Hiller31-Jul-13 21:16
Bernhard Hiller31-Jul-13 21:16 
AnswerRe: What do you think this is about? Pin
BillWoodruff1-Aug-13 2:09
professionalBillWoodruff1-Aug-13 2:09 
GeneralRe: What do you think this is about? Pin
Jasmine25012-Aug-13 5:56
Jasmine25012-Aug-13 5:56 
QuestionManaging List<Bitmap> Pin
BBatts31-Jul-13 4:34
BBatts31-Jul-13 4:34 
AnswerRe: Managing List<Bitmap> Pin
OriginalGriff31-Jul-13 8:28
mveOriginalGriff31-Jul-13 8:28 
GeneralRe: Managing List<Bitmap> Pin
BillWoodruff1-Aug-13 2:35
professionalBillWoodruff1-Aug-13 2:35 

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.