Click here to Skip to main content
15,897,891 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using a #define from an unmanaged dll Pin
Jeremy Kimball25-Mar-04 7:49
Jeremy Kimball25-Mar-04 7:49 
GeneralRe: Using a #define from an unmanaged dll Pin
Andy Brummer25-Mar-04 9:28
sitebuilderAndy Brummer25-Mar-04 9:28 
GeneralStrongly typed hash-table Pin
peter271325-Mar-04 5:58
peter271325-Mar-04 5:58 
GeneralRe: Strongly typed hash-table Pin
Heath Stewart25-Mar-04 6:03
protectorHeath Stewart25-Mar-04 6:03 
GeneralRe: Strongly typed hash-table Pin
Andy Brummer25-Mar-04 9:31
sitebuilderAndy Brummer25-Mar-04 9:31 
GeneralCaption bar modifications Pin
Alex Korchemniy25-Mar-04 5:03
Alex Korchemniy25-Mar-04 5:03 
GeneralRe: Caption bar modifications Pin
Heath Stewart25-Mar-04 5:59
protectorHeath Stewart25-Mar-04 5:59 
GeneralRe: Caption bar modifications Pin
Dave Kreskowiak25-Mar-04 12:32
mveDave Kreskowiak25-Mar-04 12:32 
I've tried out the example given by Heath and found it to be a pain in the a** to work with. I think this is because in order to draw over the top of the caption bar, you have to call the base class WndProc() first, then draw on top of what it has done. But (always one these!) there are issues with with drawing the overlay when maximizing the window and returning from a minimized state. Try this out:
		[DllImport("user32.dll")] public static extern IntPtr GetWindowDC(IntPtr hWnd);<br />
		[DllImport("user32.dll")] public static extern IntPtr GetDC(IntPtr hWnd);<br />
		[DllImport("user32.dll")] public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);<br />
		[DllImport("user32.dll")] public static extern bool IsIconic(IntPtr hWnd);<br />
		[DllImport("user32.dll")] public static extern bool InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);<br />
<br />
		// Message constants<br />
		public const int WM_NCPAINT = 0x0085;<br />
		public const int WM_NCACTIVATE = 0x0086;<br />
		public const int WM_SIZE = 0x0005;<br />
		public const int WM_ACTIVATE = 0x0006;<br />
		public const int WM_PAINT = 0x000F;<br />
<br />
		private System.Windows.Forms.Button button1;<br />
		private bool skipNCPAINT = false;<br />
<br />
		// Override the Winproc function and PaintNC that paints the window on the screen... <br />
		[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]<br />
		protected override void WndProc(ref Message m)<br />
		{<br />
			switch (m.Msg)<br />
			{<br />
				case WM_NCPAINT:<br />
				{<br />
					Debug.WriteLine("Message: WM_NCPAINT     ; WPARM: " + m.WParam.ToInt32().ToString("X") + "; LPARM: " + m.LParam.ToInt32().ToString("X"));<br />
					if( skipNCPAINT )<br />
					{<br />
						Debug.WriteLine("Told to skip WM_NCPAINT!");<br />
						skipNCPAINT = false;<br />
						base.WndProc(ref m);<br />
						InvalidateRect( m.HWnd, IntPtr.Zero, true );<br />
						break;<br />
					}<br />
					else<br />
					{<br />
						base.WndProc(ref m);<br />
						PaintNC(m.HWnd);<br />
						m.Result = IntPtr.Zero;<br />
						break;<br />
					}<br />
				}<br />
<br />
				case WM_NCACTIVATE:<br />
				{<br />
					Debug.WriteLine("Message: WM_NCACTIVATE  ; WPARM: " + m.WParam.ToInt32().ToString("X") + "; LPARM: " + m.LParam.ToInt32().ToString("X"));<br />
					base.WndProc(ref m);<br />
					PaintNC(m.HWnd);<br />
					m.Result = IntPtr.Zero;<br />
					if( m.WParam.ToInt32() == 1 )<br />
						skipNCPAINT = true;<br />
					break;<br />
				}<br />
<br />
				case WM_SIZE:<br />
				{<br />
					Debug.WriteLine("Message: WM_SIZE        ; WPARM: " + m.WParam.ToInt32().ToString("X") + "; LPARM: " + m.LParam.ToInt32().ToString("X"));<br />
					base.WndProc(ref m);<br />
					PaintNC(m.HWnd);<br />
					m.Result = IntPtr.Zero;<br />
					break;<br />
				}<br />
				<br />
				default:<br />
					base.WndProc(ref m);<br />
					break;<br />
			}<br />
		}<br />
<br />
		protected void PaintNC(System.IntPtr hWnd)<br />
		{<br />
			if( !IsIconic( hWnd ) )<br />
			{			<br />
				int ourButtonWidth = 60;<br />
				IntPtr hDC = GetWindowDC(hWnd);<br />
				Graphics g = Graphics.FromHdc(hDC);<br />
<br />
				int CaptionHeight = Bounds.Height - ClientRectangle.Height; //Titlebar<br />
<br />
				Size CloseButtonSize = SystemInformation.CaptionButtonSize;<br />
<br />
				int X = Bounds.Width / 2 - (ourButtonWidth / 2);<br />
				int Y = 6;<br />
				Debug.WriteLine("Size: " + X.ToString());<br />
				ControlPaint.DrawButton(g, X, Y, ourButtonWidth, CaptionHeight - 12, ButtonState.Normal);<br />
			<br />
				g.Dispose();<br />
				ReleaseDC(hWnd, hDC);<br />
			}<br />
		}<br />
<br />
		private void button1_Click(object sender, System.EventArgs e)<br />
		{<br />
			Debug.WriteLine("----------------------------------------------------------------------");<br />
		}<br />
<br />
	}



RageInTheMachine9532
GeneralListbox in C# with XML Pin
bertcox25-Mar-04 2:32
bertcox25-Mar-04 2:32 
GeneralRe: Listbox in C# with XML Pin
Heath Stewart25-Mar-04 4:49
protectorHeath Stewart25-Mar-04 4:49 
GeneralProcess.GetProcesses(string computerName) Pin
nilhz25-Mar-04 2:16
nilhz25-Mar-04 2:16 
GeneralRe: Process.GetProcesses(string computerName) Pin
Heath Stewart25-Mar-04 4:43
protectorHeath Stewart25-Mar-04 4:43 
GeneralError message that doesn't go away Pin
profoundwhispers24-Mar-04 23:38
profoundwhispers24-Mar-04 23:38 
GeneralRe: Error message that doesn't go away Pin
Dave Kreskowiak25-Mar-04 1:15
mveDave Kreskowiak25-Mar-04 1:15 
GeneralRe: Error message that doesn't go away Pin
Heath Stewart25-Mar-04 4:38
protectorHeath Stewart25-Mar-04 4:38 
GeneralUrgent :remoting callbacks Pin
rana7424-Mar-04 22:06
rana7424-Mar-04 22:06 
GeneralRe: Urgent :remoting callbacks Pin
Heath Stewart25-Mar-04 4:21
protectorHeath Stewart25-Mar-04 4:21 
GeneralAsynchronous Network Transfer Pin
sibish n b24-Mar-04 22:04
sibish n b24-Mar-04 22:04 
GeneralGenerate a Diagram from a Database, algorithms, approaches, tips... Pin
Braulio Dez24-Mar-04 21:12
Braulio Dez24-Mar-04 21:12 
Generalc# forms Pin
DougW4824-Mar-04 18:56
DougW4824-Mar-04 18:56 
GeneralRe: c# forms Pin
Heath Stewart24-Mar-04 20:16
protectorHeath Stewart24-Mar-04 20:16 
GeneralRe: c# forms Pin
DougW4825-Mar-04 0:02
DougW4825-Mar-04 0:02 
GeneralRe: c# forms Pin
Heath Stewart25-Mar-04 3:56
protectorHeath Stewart25-Mar-04 3:56 
GeneralRich Text Box (Visual c#.net) Pin
naresh_pandey1324-Mar-04 18:53
naresh_pandey1324-Mar-04 18:53 
GeneralRe: Rich Text Box (Visual c#.net) Pin
OmegaSupreme25-Mar-04 5:24
OmegaSupreme25-Mar-04 5:24 

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.