Click here to Skip to main content
15,896,348 members
Articles / Programming Languages / C#

Sending Input Messages to Other Windows or How To Win a Flash Game By Your Programming Skills

Rate me:
Please Sign up or sign in to vote.
3.12/5 (10 votes)
4 Jul 2006CPOL2 min read 61.3K   2.2K   47  
Library for sending input messages to other windows and links to libraries you need to take full control over any running window.
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;

	/// <summary>
	/// Summary description for WindowHighlighter.
	/// </summary>
	public class WindowHighlighter
	{				
		/// <summary>
		/// Highlights the specified window just like Spy++
		/// </summary>
		/// <param name="hWnd"></param>
		public static void Highlight(IntPtr hWnd)
		{
			const float penWidth = 3;
			Win32.Rect rc = new Win32.Rect();
			Win32.GetWindowRect(hWnd, ref rc);

			IntPtr hDC = Win32.GetWindowDC(hWnd);
			if (hDC != IntPtr.Zero)
			{
				using (Pen pen = new Pen(Color.Black, penWidth))
				{
					using (Graphics g = Graphics.FromHdc(hDC))
					{
						g.DrawRectangle(pen, 0, 0, rc.right - rc.left - (int)penWidth, rc.bottom - rc.top - (int)penWidth);
					}
				}
			}
			Win32.ReleaseDC(hWnd, hDC);
		}

		/// <summary>
		/// Forces a window to refresh, to eliminate our funky highlighted border
		/// </summary>
		/// <param name="hWnd"></param>
		public static void Refresh(IntPtr hWnd)
		{
			Win32.InvalidateRect(hWnd, IntPtr.Zero, 1 /* TRUE */);
			Win32.UpdateWindow(hWnd);
			Win32.RedrawWindow(hWnd, IntPtr.Zero, IntPtr.Zero, Win32.RDW_FRAME | Win32.RDW_INVALIDATE | Win32.RDW_UPDATENOW | Win32.RDW_ALLCHILDREN);		
		}
	}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Slovakia Slovakia
I am one step before graduating Faculty of Mathematics, Physics and Informatics, Commenius University Bratislava, specialization Computer Graphics. Working as C# programmer on large IS. Creator of Ubytovanie na Slovensku site.

Comments and Discussions