Click here to Skip to main content
12,451,446 members (56,226 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads

Stats

43.3K views
1.9K downloads
46 bookmarked
Posted

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

, 4 Jul 2006 CPOL
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)

Share

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.

You may also be interested in...

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