西西軟件下載最安全的下載網(wǎng)站、值得信賴的軟件下載站!

首頁編程開發(fā)其它知識(shí) → MFC 單文檔創(chuàng)建一個(gè)新半透明窗口實(shí)例代碼

MFC 單文檔創(chuàng)建一個(gè)新半透明窗口實(shí)例代碼

相關(guān)軟件相關(guān)文章發(fā)表評(píng)論 來源:西西整理時(shí)間:2013/1/4 0:27:40字體大。A-A+

作者:西西點(diǎn)擊:3次評(píng)論:0次標(biāo)簽: MFC

  • 類型:電子教程大。2.5M語言:中文 評(píng)分:8.8
  • 標(biāo)簽:
立即下載

在工程中新建一個(gè)類 CChildFrame

class CChildFrame : public CFrameWnd

在構(gòu)造函數(shù)中:

1 CChildFrame::CChildFrame()
2 {
3     Create(NULL,"MFC Tutorial Part 1 CoderSource Window");
4 }

可選:添加WM_PAINT消息:

 1 void CChildFrame::OnPaint() 
 2 {
 3     CPaintDC dc(this); // device context for painting
 4     
 5     // TODO: Add your message handler code here
 6     CDC *pDC = GetDC();
 7 
 8     CBrush brush(RGB(0, 0, 0));
 9     CBrush *pOldBrush = pDC->SelectObject(&brush);
10     pDC->Rectangle(0, 0, 500, 500);
11     pDC->SelectObject(pOldBrush);
12     // Do not call CFrameWnd::OnPaint() for painting messages
13 }

在CXXApp類中,添加 CChildFrame 指針變量

1 class CXXApp : public CWinApp
2 {
3 public:
4     CChildFrame *m_pChildWnd;
5 
6         ...
7 }

在CXXApp類的 InitInstance 方法中添加

 1 BOOL CMultilayerDisplayApp::InitInstance()
 2 {
 3     ...
 4     
 5     m_pChildWnd = new CChildFrame(); // 創(chuàng)建新窗口類對(duì)象
 6         //////// 這部分用于透明此窗口對(duì)象關(guān)聯(lián)的窗口///////////
 7     //加入WS_EX_LAYERED擴(kuò)展屬性
 8     SetWindowLong(m_pChildWnd->m_hWnd, GWL_EXSTYLE, GetWindowLong(m_pChildWnd->m_hWnd, GWL_EXSTYLE)^0x80000);
 9     HINSTANCE hInst = LoadLibrary("User32.DLL");
10     if (hInst)
11     {
12         typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
13         MYFUNC fun = NULL;
14         //取得SetLayeredWindowAttributes函數(shù)指針
15         fun = (MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
16         if (fun)
17         {
18             fun(m_pChildWnd->m_hWnd, 0, 128, 2);
19         }
20         FreeLibrary(hInst);
21     }
22         //////// 這部分用于透明此窗口對(duì)象關(guān)聯(lián)的窗口///////////
23 
24     // The one and only window has been initialized, so show and update it.
25     m_pMainWnd->ShowWindow(SW_SHOW);
26     m_pMainWnd->UpdateWindow();
27 
28     m_pChildWnd->ShowWindow(SW_SHOW);
29     m_pChildWnd->UpdateWindow();
30 
31     return TRUE;
32 }
33                 

效果如下:

    相關(guān)評(píng)論

    閱讀本文后您有什么感想? 已有人給出評(píng)價(jià)!

    • 8 喜歡喜歡
    • 3 頂
    • 1 難過難過
    • 5 囧
    • 3 圍觀圍觀
    • 2 無聊無聊

    熱門評(píng)論

    最新評(píng)論

    發(fā)表評(píng)論 查看所有評(píng)論(0)

    昵稱:
    表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
    字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過審核才能顯示)
    推薦文章

    沒有數(shù)據(jù)