• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            歲月流冰的技術(shù)博客--笨瑜

            No prepare is prepare to lose~~~~~~

              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
              15 隨筆 :: 0 文章 :: 8 評論 :: 0 Trackbacks
            最近遇到一個(gè)問題,在一個(gè)WinForm窗口中,按ALT+Z能夠?qū)崿F(xiàn)最小化到托盤及從托盤回復(fù)正常窗口。
            剛開始,試著在窗口的KeyPress事件中添加,但是當(dāng)窗口最小化到托盤后,焦點(diǎn)已經(jīng)不在窗口上了,因此將不能捕捉鍵盤按鍵按下的事件,因此不能從托盤彈出。經(jīng)測試,這種方法是錯(cuò)誤的。
            既然KeyPress事件不能解決問題,那么為什么不能添加熱鍵呢?
            添加熱鍵的方法是
            BOOL RegisterHotKey( 
              HWND hWnd, 
              
            int id, 
              UINT fsModifiers, 
              UINT vk 
            );
            其中參數(shù)hWnd是注冊熱鍵的窗口句柄,id是熱鍵的標(biāo)識符,fsModifiers是在創(chuàng)建WM_HOTKEY消息時(shí)必須跟用戶定義的按鍵一同按下的特殊組合鍵,他的值為:
            Value Description
            MOD_ALT Either ALT key must be held down.
            MOD_CONTROL Either CTRL key must be held down.
            MOD_KEYUP Both key up events and key down events generate a WM_HOTKEY message.
            MOD_SHIFT Either SHIFT key must be held down.
            MOD_WIN Either WINDOWS key was held down. These keys are labeled with the Microsoft Windows logo.
            我們可以使用這個(gè)函數(shù)注冊我們的熱鍵。
            在C#中使用這個(gè)函數(shù),我們必須從user32.dll中將此函數(shù)導(dǎo)入,而且必須重寫WndProc函數(shù)來捕捉熱鍵消息。
            以下為示例代碼:
            [DllImport("user32.dll")]
                    
            public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, Keys vk);
                    [DllImport(
            "user32.dll")]
                    
            public static extern bool UnregisterHotKey(IntPtr hWnd, int id); 

                    
            private void Form1_Load(object sender, EventArgs e)
                    
            {
                        RegisterHotKey(
            this.Handle, 8881, Keys.Z);
                        
            this.Hide();
                        
            this.ShowInTaskbar = true;
                        
            this.comboBox1.SelectedIndex = 0;
                    }


                    
            protected override void WndProc(ref Message m)
                    
            {
                        
            switch (m.Msg)
                        

                            
            case 0x0312:
                                
            if (m.WParam.ToString().CompareTo("888"== 0)
                                
            {
                                    
            if (bIsShowed)
                                    
            {
                                        
            this.Hide();
                                        
            this.ShowInTaskbar = true;
                                        
            this.WindowState = FormWindowState.Minimized;
                                        
            this.notifyIcon1.Visible = true;
                                        
            this.bIsShowed = false;
                                    }

                                    
            else
                                    
            {
                                        
            this.Visible = true;
                                        
            this.ShowInTaskbar = false;
                                        
            this.WindowState = FormWindowState.Normal;
                                        
            this.Activate();
                                        
            this.notifyIcon1.Visible = false;
                                        bIsShowed 
            = true;
                                    }

                                    UnregisterHotKey(
            this.Handle, 888);
                                    RegisterHotKey(
            this.Handle, 8881, Keys.Z);
                                }

                                
            break;
                            
            default:
                                
            break;
                        }


                        
            base.WndProc(ref m);
                    }
            posted on 2007-12-10 09:37 歲月流冰 閱讀(1226) 評論(2)  編輯 收藏 引用 所屬分類: C#

            評論

            # re: C#中添加熱鍵的方法 2007-12-10 11:38 <a href=http://minidx.com>minidxer</a>
            不符合法在首頁標(biāo)準(zhǔn)哈  回復(fù)  更多評論
              

            # re: C#中添加熱鍵的方法 2008-09-11 18:20 包你滿意
            不錯(cuò),向樓主學(xué)習(xí)了  回復(fù)  更多評論
              

            国产精品成人99久久久久 | 精品久久久久久中文字幕人妻最新| 伊人精品久久久久7777| 久久久久亚洲AV成人片| 国产精品99久久久久久www| 久久福利资源国产精品999| 久久综合国产乱子伦精品免费| 91性高湖久久久久| 国产A三级久久精品| 久久久久99精品成人片三人毛片| 性做久久久久久免费观看| 久久亚洲综合色一区二区三区| 久久人人爽人人爽人人片AV高清| 91亚洲国产成人久久精品| 人妻精品久久久久中文字幕69| 国产一区二区三精品久久久无广告 | 日本欧美久久久久免费播放网| 伊人色综合久久天天| 亚洲精品乱码久久久久久按摩| 久久久久久久综合日本| 久久香蕉国产线看观看乱码| 亚洲国产美女精品久久久久∴| 久久人人爽人人爽人人片AV麻豆 | 无码国内精品久久综合88| 93精91精品国产综合久久香蕉 | 久久精品国产清自在天天线| 久久精品www人人爽人人| 亚洲中文久久精品无码| 亚洲精品午夜国产va久久| 久久伊人五月天论坛| 亚洲精品NV久久久久久久久久| 久久精品国产一区二区三区| 国产精品VIDEOSSEX久久发布| 久久99毛片免费观看不卡| 久久国产欧美日韩精品| 伊人久久大香线蕉av一区| 亚洲AV无码久久寂寞少妇| 亚洲AV无码1区2区久久| 久久不见久久见免费视频7| 久久婷婷国产麻豆91天堂| 精品综合久久久久久97超人 |