窗体透明度设置

来源:互联网 发布:网络信息安全事件案列 编辑:程序博客网 时间:2024/06/06 16:48

效果

  


新建对话框程序


修改对话框



WindowAlphaSettingDlg.h : 头文件

public:CSliderCtrl m_sld;afx_msg void OnNMReleasedcaptureSlider1(NMHDR *pNMHDR, LRESULT *pResult);


WindowAlphaSettingDlg.cpp : 实现文件

BOOL CWindowAlphaSettingDlg::OnInitDialog()

//窗口置顶::SetWindowPos(m_hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);//控件范围m_sld.SetRange(10,255);m_sld.SetPos(128);//窗口样式SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);HINSTANCE hInst = LoadLibrary("User32.DLL");if (hInst){typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);MYFUNC fun = NULL;//取得SetLayeredWindowAttributes函数指针fun = (MYFUNC)GetProcAddress(hInst,"SetLayeredWindowAttributes");if(fun) fun(this->GetSafeHwnd(),0,128,2);FreeLibrary(hInst);}

void CWindowAlphaSettingDlg::OnNMReleasedcaptureSlider1(NMHDR *pNMHDR, LRESULT *pResult){// TODO: 在此添加控件通知处理程序代码BYTE eff = (BYTE)m_sld.GetPos();HINSTANCE hInst = LoadLibrary("User32.DLL");if (hInst){typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);MYFUNC fun = NULL;//取得SetLayeredWindowAttributes函数指针fun = (MYFUNC)GetProcAddress(hInst,"SetLayeredWindowAttributes");if(fun) fun(this->GetSafeHwnd(),0,eff,2);FreeLibrary(hInst);}CString str;str.Format("%d%%",100*eff/255);GetDlgItem(IDC_STATIC1)->SetWindowText(str);*pResult = 0;}


0 0