4

i got some trick to capture mouse touch title bar but the routine fire repeatedly when i place mouse on title bar. here is the routine

protected override void WndProc(ref Message m)
{
            if (m.Msg == 0xA0) // WM_NCMOUSEMOVE
            {
        listBox1.Items.Add("mouse move on title bar");
            }
            else if (m.Msg == 0x2A2) // WM_NCMOUSELEAVE
            {
        listBox1.Items.Add("mouse leave from title bar");            
            }

            base.WndProc(ref m);
}

can any one tell me any trick as a result WndProc fire only once when mouse touch the title bar instead of repeatedly firing. thanks

nsconnector
  • 838
  • 6
  • 12
Thomas
  • 33,544
  • 126
  • 357
  • 626
  • 1
    I don't know about Firing event only once but you could use flag to make sure the desired task is carried out only once when mouse touch the title bar – nsconnector Mar 10 '13 at 16:24
  • isn't there a WM_MOUSEENTER event? (only solution I see so that it fires only once, except using a flag as @nsconnector said)) – ppetrov Mar 10 '13 at 16:28

1 Answers1

3

Are you looking for this?I am controlling addition of items to listbox using flag.

private bool insideTitleBar = false;
private bool outsideTitleBar = false;

protected override void WndProc(ref Message m)
{
    if (m.Msg == 0xA0) // WM_NCMOUSEMOVE
    {        
           if(!insideTitleBar)
           {
            listBox1.Items.Add("mouse move on title bar");
            insideTitleBar = true;
            outsideTitleBar = false;
           }
    } 
    else if (m.Msg == 0x2A2) // WM_NCMOUSELEAVE
    {
           if(!outsideTitleBar)
           {      
            listBox1.Items.Add("mouse leave from title bar");            
            outsideTitleBar = true;
            insideTitleBar = false;
           }
    }
    base.WndProc(ref m);
}
nsconnector
  • 838
  • 6
  • 12