Click here to Skip to main content
15,927,344 members
Home / Discussions / C#
   

C#

 
GeneralRe: Inverse colour in GDI+ Pin
Heath Stewart29-Sep-04 5:39
protectorHeath Stewart29-Sep-04 5:39 
GeneralRe: Inverse colour in GDI+ Pin
benjymous28-Sep-04 21:37
benjymous28-Sep-04 21:37 
GeneralCommunication between C++ program and a GUI in C# Pin
Luís Brás28-Sep-04 3:30
Luís Brás28-Sep-04 3:30 
GeneralRe: Communication between C++ program and a GUI in C# Pin
Heath Stewart28-Sep-04 6:34
protectorHeath Stewart28-Sep-04 6:34 
GeneralRe: Communication between C++ program and a GUI in C# Pin
Christian Graus28-Sep-04 11:53
protectorChristian Graus28-Sep-04 11:53 
GeneralRe: Communication between C++ program and a GUI in C# Pin
Heath Stewart28-Sep-04 13:06
protectorHeath Stewart28-Sep-04 13:06 
GeneralDelegates, thread pool, asynchronous invocation Pin
Serge Lobko-Lobanovsky28-Sep-04 2:10
Serge Lobko-Lobanovsky28-Sep-04 2:10 
Generalwindow flickers Pin
Ajmoda28-Sep-04 1:04
Ajmoda28-Sep-04 1:04 
hello guys
i have a problems with the following code but i can't identify any on having idea please help me
the problems are:
1 when activate and deactivate it doesn't paint NCArea
2 it flickers
3 it doesn't give the feel like windows default title


//NCButton class

using System;

namespace WindowsApplication1
{
///
/// Summary description for NCButton.
///

public class NCButton
{
System.Drawing.Image nBitmap,fBitmap,pBitmap;
System.Drawing.Rectangle buttonRectangle;

public NCButton()
{
//
// TODO: Add constructor logic here
//
nBitmap = null;
fBitmap = null;
pBitmap = null;
}
public System.Drawing.Image NormalButtonImage
{
get
{
return nBitmap;
}
set
{
nBitmap = value;
}
}
public System.Drawing.Image FocusedButtonImage
{
get
{
return fBitmap;
}
set
{
fBitmap = value;
}
}
public System.Drawing.Image PressedButtonImage
{
get
{
return pBitmap;
}
set
{
pBitmap = value;
}
}
public System.Drawing.Rectangle ButtonRectangle
{
get
{
return buttonRectangle;
}
set
{
buttonRectangle = value;
}
}
}
}


//form1 class
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
///
/// Summary description for Form1.
///

///


public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
///
/// Required designer variable.
///

///

private ArrayList ncButtons;

[Category("Custom Mouse Events")]

private event System.Windows.Forms.MouseEventHandler NonClientMouseMove;
private event System.Windows.Forms.MouseEventHandler NonClientMouseDown;
private event System.Windows.Forms.MouseEventHandler NonClientMouseUp;

System.Drawing.Bitmap imgTitle,imgLRBorder,imgBBorder,imgButtons;

Rectangle bt1,bt2,bt3;

private System.Windows.Forms.ImageList imageList1;

private System.Drawing.Graphics graphics;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

ncButtons = new ArrayList();

NCButton bt = new NCButton();
bt.FocusedButtonImage = new Bitmap(@"C:\btimages\fmin.bmp");
bt.NormalButtonImage = new Bitmap(@"C:\btimages\nmin.bmp");
bt.PressedButtonImage = new Bitmap(@"C:\btimages\pmin.bmp");
Rectangle rect = new Rectangle(0,0,bt.NormalButtonImage.Width,bt.NormalButtonImage.Height);
bt.ButtonRectangle = rect;
ncButtons.Add(bt);

bt = new NCButton();
bt.FocusedButtonImage = new Bitmap(@"C:\btimages\fmax.bmp");
bt.NormalButtonImage = new Bitmap(@"C:\btimages\nmax.bmp");
bt.PressedButtonImage = new Bitmap(@"C:\btimages\pmax.bmp");
rect = new Rectangle(0,0,bt.NormalButtonImage.Width,bt.NormalButtonImage.Height);
bt.ButtonRectangle = rect;
ncButtons.Add(bt);

bt = new NCButton();
bt.FocusedButtonImage = new Bitmap(@"C:\btimages\fclose.bmp");
bt.NormalButtonImage = new Bitmap(@"C:\btimages\nclose.bmp");
bt.PressedButtonImage = new Bitmap(@"C:\btimages\pclose.bmp");
rect = new Rectangle(0,0,bt.NormalButtonImage.Width,bt.NormalButtonImage.Height);
bt.ButtonRectangle = rect;
ncButtons.Add(bt);


imgTitle = new Bitmap(@"C:\Skin Images\title.bmp");
imgLRBorder = new System.Drawing.Bitmap(@"C:\Skin Images\LRF.bmp");
imgBBorder = new System.Drawing.Bitmap(@"C:\Skin Images\BottomF.bmp");
imgButtons = new System.Drawing.Bitmap(@"C:\Skin Images\Button.bmp");
//graphics = new System.Drawing.Graphics();
//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{

if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

protected override void WndProc(ref Message m)
{

if(m.Msg == 0x1)//once when application starts
{

}
else if(m.Msg == 0x85 || m.Msg == 0x86)//nc_paint //nc_activate
{
IntPtr regn = m.WParam;
IntPtr hdc = Form1.GetDCEx(m.HWnd,regn,0x1 | 0x30);
if(hdc != IntPtr.Zero)
{
graphics = Graphics.FromHdc(hdc);

}
RepaintTheNCArea();
}

else if(m.Msg == 0xA0 )//nc mouse move
{
if( MouseMoveHandling(FindMousePosition()))
return;
}
else if(m.Msg == 0xA1 )//nc mouse button down
{
if( MouseDownHandling(FindMousePosition()) )
return;
}
else if(m.Msg == 0xA2 )//nc mouse button up
{
if (MouseUpHandling(FindMousePosition()))
return;
}
label1.Text = m.Msg.ToString();
base.WndProc (ref m);
}

[DllImport("User32.DLL", EntryPoint="GetDCEx", SetLastError=true,
CharSet=CharSet.Ansi, ExactSpelling=true,
CallingConvention=CallingConvention.Winapi)]
public static extern IntPtr GetDCEx(
IntPtr hWnd, // handle to window
IntPtr hrgnClip, // handle to clipping region
int flags // creation options
);

[DllImport("User32.DLL", EntryPoint="GetWindowDC", SetLastError=true,
CharSet=CharSet.Ansi, ExactSpelling=true,
CallingConvention=CallingConvention.Winapi)]
public static extern IntPtr GetWindowDC(
IntPtr hWnd // handle to window
);

private bool MouseMoveHandling(Point mousePosition)
{
Rectangle rect = ((NCButton)this.ncButtons[0]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[0]).FocusedButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[1]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[1]).FocusedButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[2]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[2]).FocusedButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
return true;
}
RepaintTheNCArea();
return false;
}
private bool MouseDownHandling(Point mousePosition)
{
Rectangle rect = ((NCButton)this.ncButtons[0]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[0]).PressedButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[1]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[1]).PressedButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[2]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[2]).PressedButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
return true;
}
RepaintTheNCArea();
return false;
}
private bool MouseUpHandling(Point mousePosition)
{
Rectangle rect = ((NCButton)this.ncButtons[0]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[0]).NormalButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[1]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[1]).NormalButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[2]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[2]).NormalButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
return true;
}
RepaintTheNCArea();
return false;
}
private Point FindMousePosition()
{
/*int l = (int)m.LParam;
int x = l & 0xffff;
int y = (int)((l & 0xffff0000) >> 16);
label1.Text = x.ToString();
label2.Text = y.ToString();*/

Point pt = System.Windows.Forms.Cursor.Position;
Point ptScreen = Cursor.Position;
Point ptClient = PointToClient(ptScreen);
ptClient.Y += 30;

//label1.Text = ptClient.X.ToString();
//label2.Text = ptClient.Y.ToString();

return ptClient;
}
private void RepaintTheNCArea()
{
if(graphics != null)
{
graphics.DrawImage(imgTitle,0,0,this.Width,30);

graphics.DrawImage( ((NCButton)ncButtons[0]).NormalButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
graphics.DrawImage( ((NCButton)ncButtons[1]).NormalButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
graphics.DrawImage( ((NCButton)ncButtons[2]).NormalButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
}
}

private void Form1_Resize(object sender, System.EventArgs e)
{

int totalButtonsWidth = 0;

int x = 0, y = 0 , w = 0, h = 0;
int space = 5;//space b/w the buttons;

for(int i = 0 ; i < ncButtons.Count ; i++)
{
totalButtonsWidth += ((NCButton)ncButtons[i]).NormalButtonImage.Width;
}

x = this.Width - ( (space * 2) + totalButtonsWidth) ;
y = 0;
w = ((NCButton)ncButtons[0]).NormalButtonImage.Width;
h = ((NCButton)ncButtons[0]).NormalButtonImage.Height;
Rectangle rect = new Rectangle(x,y,w,h);
((NCButton)ncButtons[0]).ButtonRectangle = rect;

x += (space + w) ;
y = 0;
w = ((NCButton)ncButtons[1]).NormalButtonImage.Width;
h = ((NCButton)ncButtons[1]).NormalButtonImage.Height;
rect = new Rectangle(x,y,w,h);
((NCButton)ncButtons[1]).ButtonRectangle = rect;

x += (space + w) ;
y = 0;
w = ((NCButton)ncButtons[2]).NormalButtonImage.Width;
h = ((NCButton)ncButtons[2]).NormalButtonImage.Height;
rect = new Rectangle(x,y,w,h);
((NCButton)ncButtons[2]).ButtonRectangle = rect;
}
}
}
GeneralRe: window flickers Pin
sreejith ss nair28-Sep-04 1:29
sreejith ss nair28-Sep-04 1:29 
GeneralRe: window flickers Pin
Ajmoda28-Sep-04 1:58
Ajmoda28-Sep-04 1:58 
GeneralRe: window flickers Pin
sreejith ss nair28-Sep-04 2:18
sreejith ss nair28-Sep-04 2:18 
GeneralRe: window flickers Pin
Ajmoda28-Sep-04 2:36
Ajmoda28-Sep-04 2:36 
GeneralRe: window flickers Pin
sreejith ss nair28-Sep-04 2:46
sreejith ss nair28-Sep-04 2:46 
GeneralRe: window flickers Pin
Jay Shankar28-Sep-04 21:44
Jay Shankar28-Sep-04 21:44 
GeneralRe: window flickers Pin
Ajmoda28-Sep-04 21:53
Ajmoda28-Sep-04 21:53 
GeneralRe: window flickers Pin
Jay Shankar28-Sep-04 22:16
Jay Shankar28-Sep-04 22:16 
GeneralRe: window flickers Pin
Ajmoda28-Sep-04 22:23
Ajmoda28-Sep-04 22:23 
GeneralRe: window flickers Pin
Andrzej Markowski28-Sep-04 22:45
Andrzej Markowski28-Sep-04 22:45 
GeneralRe: System.UInt32 -&gt; Integer Pin
El'Cachubrey28-Sep-04 0:35
El'Cachubrey28-Sep-04 0:35 
GeneralAddTabType for PropertyGrid Pin
Claudia Peschke27-Sep-04 23:38
Claudia Peschke27-Sep-04 23:38 
GeneralRe: AddTabType for PropertyGrid Pin
leppie28-Sep-04 0:37
leppie28-Sep-04 0:37 
QuestionHow to program outlook express in C# ? Pin
ppp00127-Sep-04 22:44
ppp00127-Sep-04 22:44 
GeneralSystem.UInt32 -> Integer Pin
El'Cachubrey27-Sep-04 22:40
El'Cachubrey27-Sep-04 22:40 
GeneralRe: System.UInt32 -&gt; Integer Pin
exhaulted27-Sep-04 23:04
exhaulted27-Sep-04 23:04 
GeneralRe: System.UInt32 -&gt; Integer Pin
Colin Angus Mackay27-Sep-04 23:51
Colin Angus Mackay27-Sep-04 23:51 

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.