類似qq等重抽屜菜單的實現。

來源:互聯網
上載者:User

    為了實現像qq,最佳化大師中菜單。在網上找了好久,終於在vckbase中找到了。主要的原理就是通過移動視窗來實現的。

    我實現的工具中用了2個按鈕和兩個listctrl,不過listctrl可以用其他控制項來代替,這樣就更加多樣化了。

     首先是為這2個按鈕添加事件,這兩個按鈕的事件響應函數分別是

afx_msg void  OnBnClicke1(NMHDR * pNMHDR,LRESULT *pResult);

afx_msg void  OnBnClicke2(NMHDR * pNMHDR,LRESULT *pResult);

還需要一個用於切換的函數。

void OnChange();

 

 

這3個函數實現代碼如下:

OnBnClicke1(NMHDR * pNMHDR,LRESULT *pResult)</p><p>{<br />m_clicknum=1;<br />if(m_TopButtonNum==1)<br />{<br />OnBnClickedBtnDevDetect();<br />return ;// TOOL1按鈕已在上層, 再次點擊沒反應;<br />} </p><p>OnChange();<br />m_TopButtonNum=1;</p><p>}<br />

 

 

OnBnClickedBtnDevDetect()<br />{<br />// TODO: 在此添加控制項通知處理常式代碼<br />m_clicknum=2;<br />if(m_TopButtonNum==2)<br />{<br />return; // TOOL3按鈕已在上層, 再次點擊沒反應;<br />}<br />OnChange();</p><p>m_TopButtonNum=2;</p><p>}

 

OnChange()<br />{</p><p>if(m_TopButtonNum!=1&&m_clicknum==1)<br />{<br />int nWidth;<br />int nHeight;</p><p>// 第一個按鈕已經置於最上層,所以無需移動,其餘全置於下面<br />m_Btn1t.MoveWindow(m_point0.x + 10 ,<br />m_point1.y - 20 - m_Rect1.Height(),<br />m_Rect1.Width(),<br />m_Rect1.Height());</p><p>// 顯示該button按鈕下內容<br /> nWidth = m_Rect0.Width();<br /> nHeight = (m_point1.y - 20 - m_Rect1.Height()) - (m_point0.y + 10 + m_Rect0.Height() + m_RectLogo.Height()) ;</p><p>m_List1.MoveWindow(m_point0.x + 10,<br />m_point0.y + 10 + m_Rect0.Height() + m_RectLogo.Height(),<br />nWidth,nHeight);</p><p>m_List1.ShowWindow(SW_SHOW);<br />m_List2.ShowWindow(SW_HIDE);</p><p>//m_pCurrentDlg->ShowWindow(true);<br />return;<br />}</p><p>if(m_TopButtonNum!=2&&m_clicknum==2)<br />{</p><p>int nWidth;<br />int nHeight;</p><p>// 先將排在它上面的按鈕置上不聞;<br />m_Btn2.MoveWindow(m_point0.x + 10 ,<br />m_point0.y + 10 + m_Rect0.Height() + m_RectLogo.Height(),<br />m_Rect1.Width(),<br />m_Rect1.Height());</p><p>nWidth = m_Rect0.Width();<br />nHeight = (m_point1.y - 20) - (m_point0.y + 10 + m_Rect0.Height() + m_Rect1.Height() + m_RectLogo.Height());<br />m_List2.MoveWindow(m_point0.x + 10 ,<br />m_point0.y + 10 + m_Rect0.Height() + m_Rect1.Height() + m_RectLogo.Height(),<br />nWidth,nHeight);</p><p>// 顯示該按鈕下內容<br />m_List1.ShowWindow(SW_HIDE);<br />m_List2.ShowWindow(SW_SHOW);</p><p>//m_pCurrentDlg->ShowWindow(true);<br />return;<br />}<br />}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.