Click here to Skip to main content
15,884,472 members
Home / Discussions / C#
   

C#

 
QuestionMerging Of Multiple Activex Wrapper Dll Into Single Assembly Pin
vighnesha17-Apr-06 19:31
vighnesha17-Apr-06 19:31 
AnswerRe: Merging Of Multiple Activex Wrapper Dll Into Single Assembly Pin
Jakob Farian Krarup17-Apr-06 19:38
Jakob Farian Krarup17-Apr-06 19:38 
GeneralRe: Merging Of Multiple Activex Wrapper Dll Into Single Assembly Pin
vighnesha17-Apr-06 20:42
vighnesha17-Apr-06 20:42 
QuestionSuggest me for Data Migration tools Pin
mahesh_magham17-Apr-06 18:22
mahesh_magham17-Apr-06 18:22 
Questionhow to get all windows that are programs Pin
g00fyman17-Apr-06 18:18
g00fyman17-Apr-06 18:18 
AnswerRe: how to get all windows that are programs Pin
alexey N17-Apr-06 18:58
alexey N17-Apr-06 18:58 
GeneralRe: how to get all windows that are programs Pin
g00fyman17-Apr-06 19:19
g00fyman17-Apr-06 19:19 
GeneralRe: how to get all windows that are programs Pin
g00fyman17-Apr-06 19:42
g00fyman17-Apr-06 19:42 
ok as promised and after trawling the windows api, always an excellent read.

i have this, which works nicely for my own screenshot app that is loaded with useful things.

i plan to add this to the explorer context menu so u can choose which window to capture or you can capture a region using a selection rectangle on the screen.

enough of that here is the code

of course, anyone using this will need to dllimport the requried functions

btw the reason it was failing was because i was using GeWindowText() instead of sending WM_GETTEXT.

public static Window[] EnumerateTopWindows()
    {
      ArrayList windowList = new ArrayList();
      IntPtr hWnd = IntPtr.Zero;
      Window window = null;

      // Get first window
      hWnd = GetActiveWindow();
      hWnd = GetWindow(hWnd, GW_HWNDFIRST);

      while (hWnd != IntPtr.Zero)
      {
        if (IsWindow(hWnd) && IsWindowVisible(hWnd))
        {
          IntPtr parentWin = GetParent(hWnd);
          if ((parentWin == IntPtr.Zero))
          {
            string text = GetText(hWnd);
            int length = text.Length;
            if (length > 0)
            {
              if (text != "Tray" && text != "Start" && text != "Task Manager" && text != "Program Manager")
              {
                window = new Window();
                window.Handle = hWnd;
                window.Text = text;
                windowList.Add(window);
              }
            }
          }
        }
        hWnd = GetWindow(hWnd, GW_HWNDNEXT);
      }
      return (Window[])windowList.ToArray(typeof(Window));
    }

private static string GetText(IntPtr hWnd)
    {
      int cap = 1048576;

      StringBuilder buffer = new StringBuilder(cap);
      SendMessage(hWnd.ToInt32(), WM_GETTEXT, cap, buffer);

      return Convert.ToString(buffer);
    }


kind regards,
g00fy
Questionstatic question Pin
Old Gun17-Apr-06 18:04
Old Gun17-Apr-06 18:04 
AnswerRe: static question Pin
alexey N17-Apr-06 18:10
alexey N17-Apr-06 18:10 
GeneralRe: static question Pin
Old Gun17-Apr-06 19:01
Old Gun17-Apr-06 19:01 
GeneralRe: static question Pin
alexey N17-Apr-06 19:49
alexey N17-Apr-06 19:49 
AnswerRe: static question Pin
Guffa17-Apr-06 20:51
Guffa17-Apr-06 20:51 
GeneralRe: static question Pin
Old Gun17-Apr-06 21:35
Old Gun17-Apr-06 21:35 
GeneralRe: static question Pin
Old Gun18-Apr-06 1:39
Old Gun18-Apr-06 1:39 
QuestionDetect when windows added Pin
Hossein Margani17-Apr-06 16:26
Hossein Margani17-Apr-06 16:26 
Questionsetting new interval value and turning on timer in Parent Form Pin
emran83417-Apr-06 16:00
emran83417-Apr-06 16:00 
AnswerRe: setting new interval value and turning on timer in Parent Form Pin
Robin Panther17-Apr-06 17:02
Robin Panther17-Apr-06 17:02 
QuestionProgress Pin
Sean8917-Apr-06 15:23
Sean8917-Apr-06 15:23 
AnswerRe: Progress Pin
enjoycrack17-Apr-06 16:58
enjoycrack17-Apr-06 16:58 
QuestionHandling Data Error Event Pin
emran83417-Apr-06 15:21
emran83417-Apr-06 15:21 
QuestionGraphics and pixel manipulation Pin
Maksymus00717-Apr-06 13:41
Maksymus00717-Apr-06 13:41 
AnswerRe: Graphics and pixel manipulation Pin
Office Lineman17-Apr-06 13:51
Office Lineman17-Apr-06 13:51 
GeneralRe: Graphics and pixel manipulation Pin
Maksymus00717-Apr-06 22:44
Maksymus00717-Apr-06 22:44 
QuestionDatagridview Pin
thepersonof17-Apr-06 13:03
thepersonof17-Apr-06 13:03 

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.