Click here to Skip to main content
15,906,574 members
Home / Discussions / C#
   

C#

 
AnswerRe: OODBMS are the best solution for Today applications Pin
johhnny8-Oct-05 12:20
johhnny8-Oct-05 12:20 
AnswerRe: OODBMS are the best solution for Today applications Pin
Colin Angus Mackay8-Oct-05 22:26
Colin Angus Mackay8-Oct-05 22:26 
GeneralRe: OODBMS are the best solution for Today applications Pin
tolgayikilmaz9-Oct-05 1:45
tolgayikilmaz9-Oct-05 1:45 
GeneralRe: OODBMS are the best solution for Today applications Pin
Colin Angus Mackay9-Oct-05 1:48
Colin Angus Mackay9-Oct-05 1:48 
AnswerRe: OODBMS are the best solution for Today applications Pin
Kevin McFarlane9-Oct-05 8:29
Kevin McFarlane9-Oct-05 8:29 
QuestionOpening the Form in maximized mode? Pin
E6AD8-Oct-05 12:09
E6AD8-Oct-05 12:09 
AnswerRe: Opening the Form in maximized mode? Pin
S. Senthil Kumar8-Oct-05 20:03
S. Senthil Kumar8-Oct-05 20:03 
QuestionWindowScraping Pin
budidharma8-Oct-05 11:17
budidharma8-Oct-05 11:17 
I've been trying to figure out how to extract information from all the windows presently on the desktop for about a week now. I've made it a ways, but now I am most thoroughly stuck. The following code I've gathered from various places. It compiles fine in VS 2005 RC1 against the .NET 2.0 framework.

However, at runtime it gets hung up when trying to return the windowlist. It gives a generic error and stops execution when it attemps to run the following line:

foreach (Window x in Windows)<br />
{<br />
     Windows.Add(x.Title + ": " + x.hWnd.ToString());<br />
}


Here is the entire rest of the code. It should compile for you fine, with a simple cut and paste job.
I really need to get this code working. If you have the time, and want to chat: my AIM is navinineteen.

The following is two separate files:


<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace WindowScraper<br />
{<br />
	/// <summary><br />
	/// Summary description for Form1.<br />
	/// </summary><br />
	public class FormWindowList : System.Windows.Forms.Form<br />
	{<br />
<br />
		private System.Windows.Forms.ListBox listBoxWindowList;<br />
		private System.Windows.Forms.Button buttonUpdateWindowsList;<br />
		private System.Windows.Forms.Button buttonSaveImage;<br />
		/// <summary><br />
		/// Required designer variable.<br />
		/// </summary><br />
		private System.ComponentModel.Container components = null;<br />
<br />
		public FormWindowList()<br />
		{<br />
			//<br />
			// Required for Windows Form Designer support<br />
			//<br />
			InitializeComponent();<br />
<br />
			//<br />
			// TODO: Add any constructor code after InitializeComponent call<br />
			//<br />
		}<br />
<br />
		/// <summary><br />
		/// Clean up any resources being used.<br />
		/// </summary><br />
		protected override void Dispose( bool disposing )<br />
		{<br />
			if( disposing )<br />
			{<br />
				if (components != null) <br />
				{<br />
					components.Dispose();<br />
				}<br />
			}<br />
			base.Dispose( disposing );<br />
		}<br />
<br />
		#region Windows Form Designer generated code<br />
		/// <summary><br />
		/// Required method for Designer support - do not modify<br />
		/// the contents of this method with the code editor.<br />
		/// </summary><br />
		private void InitializeComponent()<br />
		{<br />
			this.listBoxWindowList = new System.Windows.Forms.ListBox();<br />
			this.buttonUpdateWindowsList = new System.Windows.Forms.Button();<br />
			this.buttonSaveImage = new System.Windows.Forms.Button();<br />
			this.SuspendLayout();<br />
			// <br />
			// listBoxWindowList<br />
			// <br />
			this.listBoxWindowList.Location = new System.Drawing.Point(16, 16);<br />
			this.listBoxWindowList.Name = "listBoxWindowList";<br />
			this.listBoxWindowList.Size = new System.Drawing.Size(256, 173);<br />
			this.listBoxWindowList.TabIndex = 0;<br />
			// <br />
			// buttonUpdateWindowsList<br />
			// <br />
			this.buttonUpdateWindowsList.Location = new System.Drawing.Point(64, 200);<br />
			this.buttonUpdateWindowsList.Name = "buttonUpdateWindowsList";<br />
			this.buttonUpdateWindowsList.Size = new System.Drawing.Size(160, 23);<br />
			this.buttonUpdateWindowsList.TabIndex = 1;<br />
			this.buttonUpdateWindowsList.Text = "Update Windows List";<br />
			this.buttonUpdateWindowsList.Click += new System.EventHandler(this.UpdateWindowList);<br />
			// <br />
			// buttonSaveImage<br />
			// <br />
			this.buttonSaveImage.Location = new System.Drawing.Point(64, 232);<br />
			this.buttonSaveImage.Name = "buttonSaveImage";<br />
			this.buttonSaveImage.Size = new System.Drawing.Size(160, 23);<br />
			this.buttonSaveImage.TabIndex = 2;<br />
			this.buttonSaveImage.Text = "Save Image";<br />
			this.buttonSaveImage.Click += new System.EventHandler(this.SaveImage);<br />
			// <br />
			// FormWindowList<br />
			// <br />
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
			this.ClientSize = new System.Drawing.Size(292, 273);<br />
			this.Controls.Add(this.buttonSaveImage);<br />
			this.Controls.Add(this.buttonUpdateWindowsList);<br />
			this.Controls.Add(this.listBoxWindowList);<br />
			this.Name = "FormWindowList";<br />
			this.Text = "Window List";<br />
			this.ResumeLayout(false);<br />
<br />
		}<br />
		#endregion<br />
<br />
		/// <summary><br />
		/// The main entry point for the application.<br />
		/// </summary><br />
		[STAThread]<br />
		static void Main() <br />
		{<br />
			Application.Run(new FormWindowList());<br />
		}<br />
<br />
		private void UpdateWindowList(object sender, System.EventArgs e)<br />
		{<br />
			listBoxWindowList.Controls.Clear();<br />
<br />
            ArrayList windows = WindowScraper.GetWindowList();<br />
            foreach (string window in windows)<br />
                listBoxWindowList.Items.Add(window);<br />
		}<br />
<br />
		private void SaveImage(object sender, System.EventArgs e)<br />
		{<br />
		<br />
		}<br />
		<br />
	}<br />
}<br />


... and the second file.

<br />
<br />
using System;<br />
using System.Collections;<br />
using System.Text;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace WindowScraper<br />
{<br />
    /// <summary><br />
    /// Summary description for WindowScraper.<br />
    /// </summary><br />
    public class WindowScraper<br />
    {<br />
        public static ArrayList Windows;<br />
<br />
        public struct Window<br />
        {<br />
            public string Title;<br />
            public int hWnd;<br />
            public Window(string Title, int hWnd)<br />
            {<br />
                this.Title = Title;<br />
                this.hWnd = hWnd;<br />
            }<br />
        }<br />
<br />
<br />
        /// <summary><br />
        /// Imported user32 functions.<br />
        /// </summary><br />
<br />
        private const int GWL_EXSTYLE = (-20);<br />
        private const int WS_EX_TOOLWINDOW = 0x80;<br />
        private const int WS_EX_APPWINDOW = 0x40000;<br />
        private const int GW_OWNER = 4;<br />
<br />
        public delegate int EnumWindowsProcDelegate(int hWnd, int lParam);<br />
<br />
        [DllImport("user32")]<br />
        private static extern int EnumWindows(EnumWindowsProcDelegate lpEnumFunc, int lParam);<br />
<br />
        [DllImport("User32.Dll")]<br />
        public static extern void GetWindowText(int h, StringBuilder s, int nMaxCount);<br />
<br />
        [DllImport("user32", EntryPoint = "GetWindowLongA")]<br />
        private static extern int GetWindowLongPtr(int hwnd, int nIndex);<br />
<br />
        [DllImport("user32")]<br />
        private static extern int GetParent(int hwnd);<br />
<br />
        [DllImport("user32")]<br />
        private static extern int GetWindow(int hwnd, int wCmd);<br />
<br />
        [DllImport("user32")]<br />
        private static extern int IsWindowVisible(int hwnd);<br />
<br />
        [DllImport("user32")]<br />
        private static extern int GetDesktopWindow();<br />
<br />
<br />
        /// <summary><br />
        /// Checks to see if its a valid window.<br />
        /// </summary><br />
        /// <param name="hWnd">hWnd to check</param><br />
        /// <returns>If it was successful or not</returns><br />
        private static bool IsTaskbarWindow(int hWnd)<br />
        {<br />
            int lExStyle;<br />
            int hParent;<br />
            lExStyle = GetWindowLongPtr(hWnd, GWL_EXSTYLE);<br />
            hParent = GetParent(hWnd);<br />
            bool fTaskbarWindow = ((IsWindowVisible(hWnd) != 0) & (GetWindow(hWnd, GW_OWNER) == 0) & (hParent == 0 | hParent == GetDesktopWindow()));<br />
            if ((lExStyle & WS_EX_TOOLWINDOW) == WS_EX_TOOLWINDOW)<br />
            {<br />
                fTaskbarWindow = false;<br />
            }<br />
            if ((lExStyle & WS_EX_APPWINDOW) == WS_EX_APPWINDOW)<br />
            {<br />
                fTaskbarWindow = true;<br />
            }<br />
            return fTaskbarWindow;<br />
        }<br />
<br />
        /// <summary><br />
        ///<br />
        /// </summary><br />
        /// <param name="hWnd"></param><br />
        /// <param name="lParam"></param><br />
        /// <returns></returns><br />
<br />
        public static int EnumWindowsProc(int hWnd, int lParam)<br />
        {<br />
            if (IsTaskbarWindow(hWnd))<br />
            {<br />
                StringBuilder sb = new StringBuilder(1024);<br />
                GetWindowText(hWnd, sb, sb.Capacity);<br />
                String xMsg = sb.ToString();<br />
                {<br />
                    if (xMsg.Length > 0)<br />
                    {<br />
                        Windows.Add(new Window(xMsg, hWnd));<br />
                    }<br />
                }<br />
            }<br />
            return 1;<br />
        }<br />
<br />
        public static ArrayList GetWindowList()<br />
        {<br />
            Windows = new ArrayList();<br />
            EnumWindows(EnumWindowsProc, 0);<br />
            foreach (Window x in Windows)<br />
            {<br />
                Windows.Add(x.Title + ": " + x.hWnd.ToString());<br />
            }<br />
			return Windows;<br />
        }<br />
<br />
    }<br />
}<br />
<br />

AnswerRe: WindowScraping Pin
XRaheemX10-Oct-05 5:06
XRaheemX10-Oct-05 5:06 
QuestionTaskbar Applications Pin
jgallen238-Oct-05 11:13
jgallen238-Oct-05 11:13 
QuestionRichTextBox Qeustion Pin
Mohammad A Gdeisat8-Oct-05 10:45
Mohammad A Gdeisat8-Oct-05 10:45 
AnswerRe: RichTextBox Qeustion Pin
mav.northwind9-Oct-05 0:31
mav.northwind9-Oct-05 0:31 
QuestionThreads Pin
ShimiG8-Oct-05 8:32
ShimiG8-Oct-05 8:32 
AnswerRe: Threads Pin
S. Senthil Kumar8-Oct-05 20:07
S. Senthil Kumar8-Oct-05 20:07 
GeneralRe: Threads Pin
ShimiG9-Oct-05 4:27
ShimiG9-Oct-05 4:27 
GeneralRe: Threads Pin
S. Senthil Kumar9-Oct-05 5:01
S. Senthil Kumar9-Oct-05 5:01 
GeneralRe: Threads Pin
ShimiG9-Oct-05 5:16
ShimiG9-Oct-05 5:16 
GeneralRe: Threads Pin
S. Senthil Kumar9-Oct-05 19:10
S. Senthil Kumar9-Oct-05 19:10 
AnswerRe: Threads Pin
Member 17998439-Oct-05 5:56
Member 17998439-Oct-05 5:56 
QuestionFile turns into Form?? Generates Form for Generic Class?? Why?? Pin
Anonymous8-Oct-05 6:56
Anonymous8-Oct-05 6:56 
AnswerRe: File turns into Form?? Generates Form for Generic Class?? Why?? Pin
Dave Kreskowiak8-Oct-05 19:23
mveDave Kreskowiak8-Oct-05 19:23 
QuestionMaking animtion in picture box Pin
Member 20302058-Oct-05 5:57
Member 20302058-Oct-05 5:57 
AnswerRe: Making animtion in picture box Pin
Libor Tinka9-Oct-05 0:46
Libor Tinka9-Oct-05 0:46 
QuestionDisplaying the Window Title when doing Alt-Tab Pin
BlueWavz8-Oct-05 5:02
BlueWavz8-Oct-05 5:02 
AnswerRe: Displaying the Window Title when doing Alt-Tab Pin
XRaheemX10-Oct-05 5:10
XRaheemX10-Oct-05 5:10 

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.