Click here to Skip to main content
15,445,560 members
Home / Discussions / C#
   

C#

 
QuestionMerging Of Multiple Activex Wrapper Dll Into Single Assembly Pin
vighnesha17-Apr-06 19:31
Membervighnesha17-Apr-06 19:31 
AnswerRe: Merging Of Multiple Activex Wrapper Dll Into Single Assembly Pin
Jakob Farian Krarup17-Apr-06 19:38
MemberJakob Farian Krarup17-Apr-06 19:38 
GeneralRe: Merging Of Multiple Activex Wrapper Dll Into Single Assembly Pin
vighnesha17-Apr-06 20:42
Membervighnesha17-Apr-06 20:42 
QuestionSuggest me for Data Migration tools Pin
mahesh_magham17-Apr-06 18:22
Membermahesh_magham17-Apr-06 18:22 
Questionhow to get all windows that are programs Pin
g00fyman17-Apr-06 18:18
Memberg00fyman17-Apr-06 18:18 
AnswerRe: how to get all windows that are programs Pin
alexey N17-Apr-06 18:58
Memberalexey N17-Apr-06 18:58 
GeneralRe: how to get all windows that are programs Pin
g00fyman17-Apr-06 19:19
Memberg00fyman17-Apr-06 19:19 
GeneralRe: how to get all windows that are programs Pin
g00fyman17-Apr-06 19:42
Memberg00fyman17-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
MemberOld Gun17-Apr-06 18:04 
AnswerRe: static question Pin
alexey N17-Apr-06 18:10
Memberalexey N17-Apr-06 18:10 
GeneralRe: static question Pin
Old Gun17-Apr-06 19:01
MemberOld Gun17-Apr-06 19:01 
GeneralRe: static question Pin
alexey N17-Apr-06 19:49
Memberalexey N17-Apr-06 19:49 
AnswerRe: static question Pin
Guffa17-Apr-06 20:51
MemberGuffa17-Apr-06 20:51 
GeneralRe: static question Pin
Old Gun17-Apr-06 21:35
MemberOld Gun17-Apr-06 21:35 
GeneralRe: static question Pin
Old Gun18-Apr-06 1:39
MemberOld Gun18-Apr-06 1:39 
QuestionDetect when windows added Pin
Hossein Margani17-Apr-06 16:26
MemberHossein Margani17-Apr-06 16:26 
Questionsetting new interval value and turning on timer in Parent Form Pin
emran83417-Apr-06 16:00
Memberemran83417-Apr-06 16:00 
AnswerRe: setting new interval value and turning on timer in Parent Form Pin
Robin Panther17-Apr-06 17:02
MemberRobin Panther17-Apr-06 17:02 
QuestionProgress Pin
Sean8917-Apr-06 15:23
MemberSean8917-Apr-06 15:23 
AnswerRe: Progress Pin
enjoycrack17-Apr-06 16:58
Memberenjoycrack17-Apr-06 16:58 
QuestionHandling Data Error Event Pin
emran83417-Apr-06 15:21
Memberemran83417-Apr-06 15:21 
QuestionGraphics and pixel manipulation Pin
Maksymus00717-Apr-06 13:41
MemberMaksymus00717-Apr-06 13:41 
AnswerRe: Graphics and pixel manipulation Pin
Office Lineman17-Apr-06 13:51
MemberOffice Lineman17-Apr-06 13:51 
GeneralRe: Graphics and pixel manipulation Pin
Maksymus00717-Apr-06 22:44
MemberMaksymus00717-Apr-06 22:44 
QuestionDatagridview Pin
thepersonof17-Apr-06 13:03
Memberthepersonof17-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.