Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
Add your own
alternative version
Go to top

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

, 4 Jul 2006
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 - - (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.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.


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


About the Author

Michal Remi
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.

| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 4 Jul 2006
Article Copyright 2006 by Michal Remi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid