winforms - C# Global hotkeys won't work in first minimize to tray but after showing and minimize again it works -


sorry if miss fool, have send in project , got question

i have registered global hotkeys on handle created (edit!!)

    protected override void onhandlecreated(eventargs e)      {     base.onhandlecreated(e);         registerhotkey(this.handle, 1, 0x0000,0x70);         registerhotkey(this.handle, 2, 0x0000,0x71);         registerhotkey(this.handle, 3, 0x0000,0x72);         registerhotkey(this.handle, 4, 0x0000,0x73);         registerhotkey(this.handle, 5, 0x0000,0x74);         registerhotkey(this.handle, 6, 0x0000,0x75);         registerhotkey(this.handle, 7, 0x0000,0x76);         registerhotkey(this.handle, 8, 0x0000,0x77);         registerhotkey(this.handle, 9, 0x0000,0x78);         registerhotkey(this.handle, 10, 0x0000,0x79);         registerhotkey(this.handle, 11, 0x0000,0x7a);         registerhotkey(this.handle, 12, 0x0000,0x7b);         registerhotkey(this.handle, 13, 0x0002,0x45);     } 

and button1 hide form , make trayicon visible

    void button1click(object sender, eventargs e)     {         trayicon.visible=true;          showintaskbar=false;         this.hide();             trayicon.showballoontip(2000,"corrector minimized","right click @ check symbol exit or show , change hotkey",tooltipicon.info);     } 

i have function show form after double click on tray icon

    private void trayicon_doubleclick(object sender, eventargs e)      {         this.show();         visible=true;         showintaskbar=true;     } 

now problem, set global hotkey 13 exit program.

1.i opened program , pressed ctrl+e (the hotkey) >>> exit program

2.i opened program press button 1 ctrl+e>>> doesn't exit program

3.i opened program,press button 1 , doubleclick icon, form show ctrl+e>>>> exit program

4.i opened program,press button 1 , doubleclick icon, form show press button 1 again form dissappeared ctrl+e>>> exit program.

that's why confused, 2 , 4 should have same result on 4 work while on 2 doesn't work

someone please me

thanks

poom

edit:!!

my wndproc

     protected override void wndproc(ref message m)     {         if (m.msg == 0x0312)         {             int id = m.wparam.toint32();             if(id==14)             {                 application.exit();             }             if(id==13)             {                 application.exit();             }             if(check2==0)             {                 this.topmost=true;                 messagebox.show("กรุณาเลือกปุ่มที่จะใช้เเก้ก่อน,select hotkey first","ข้อผิดพลาด",messageboxbuttons.ok,messageboxicon.error);                 this.topmost=false;             }              if(id==check2)             {             translate();//you can replace statement desired response hotkey.             }          }         base.wndproc(ref m);     } 

pretty sure problem tied constant toggling of showintaskbar property. knowledge, doing destroys , recreates window, meaning handle registered hotkeys pointing wrong thing.

as code stands now, hotkeys getting assigned when form first created, since calling hide() doesn't dispose of window (for record, visible calls redundant; show()/hide() equivalent toggling visible true/false).

as far know, there 2 ways around this. either assign hotkeys after toggle on showintaskbar property, or override onhandlecreated method of form , assigning there.

i @ loss why steps 3 , 4 work way do; figure both shouldn't exit program. happen reliably? perhaps smarter venture guess why works. possible handle being recycled?


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -