Click here to Skip to main content
15,914,795 members
Home / Discussions / C#
   

C#

 
AnswerRe: Windows Form icon Pin
vatzcar17-Apr-06 21:48
vatzcar17-Apr-06 21:48 
GeneralRe: Windows Form icon Pin
TheEagle19-Apr-06 7:02
TheEagle19-Apr-06 7:02 
QuestionFilling datatable with recordset data using OleDBDataAdapter's fill method Pin
Maau2117-Apr-06 20:55
Maau2117-Apr-06 20:55 
QuestionHow I get Microsoft excel range object which contain merged cells with c# Pin
Old Gun17-Apr-06 20:51
Old Gun17-Apr-06 20:51 
Questionhow can i create document for my dll Pin
iman_kh17-Apr-06 20:34
iman_kh17-Apr-06 20:34 
AnswerRe: how can i create document for my dll Pin
alexey N17-Apr-06 20:41
alexey N17-Apr-06 20:41 
Questionwithevents in c# Pin
abhinish17-Apr-06 20:22
abhinish17-Apr-06 20:22 
AnswerRe: withevents in c# Pin
Christian Graus17-Apr-06 20:40
protectorChristian Graus17-Apr-06 20:40 
AnswerRe: withevents in c# Pin
HimaBindu Vejella17-Apr-06 23:32
HimaBindu Vejella17-Apr-06 23:32 
Questionimporting excel data to sql server Pin
genx_code17-Apr-06 20:20
genx_code17-Apr-06 20:20 
AnswerRe: importing excel data to sql server Pin
Monin D.17-Apr-06 21:13
Monin D.17-Apr-06 21:13 
GeneralRe: importing excel data to sql server Pin
genx_code18-Apr-06 16:34
genx_code18-Apr-06 16:34 
AnswerRe: importing excel data to sql server Pin
HimaBindu Vejella17-Apr-06 23:55
HimaBindu Vejella17-Apr-06 23:55 
Questiondynamic html page creation using javascript Pin
umaheshchandra17-Apr-06 20:17
umaheshchandra17-Apr-06 20:17 
AnswerRe: dynamic html page creation using javascript Pin
alexey N17-Apr-06 20:28
alexey N17-Apr-06 20:28 
QuestionHTML To PDF File Pin
bging17-Apr-06 19:58
bging17-Apr-06 19:58 
Questionto get the font style of a character Pin
janarthanreddy17-Apr-06 19:44
janarthanreddy17-Apr-06 19:44 
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

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.