目录:
0.消息汇总.
1.常用方法总结.
2.示例效果源码
0.消息汇总:
ON_WM_HSCROLL() void CBmpDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) nSBCode区域,
ON_WM_VSCROLL() void CBmpDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
ON_WM_MOUSEWHEEL() BOOL CBmpDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
配合:GetScrollInfo GetScrollPos ScrollWindow SetScrollPos
1.常用方法总结:
2.示例效果源码
窗口淡入淡出显示
OnInitDialog中:
CenterWindow();//创建窗体
DWORD dwStyle = AW_BLEND;//淡入淡出样式
HINSTANCE hInst = LoadLibrary("User32.DLL");//载入动态库
typedef BOOL(WINAPI MYFUNC(HWND,DWORD,DWORD));//定义函数类型
MYFUNC* AnimateWindow;//定义函数指针
AnimateWindow = (MYFUNC *)::GetProcAddress(hInst,"AnimateWindow");//获取函数地址
AnimateWindow(this->m_hWnd,1000,dwStyle);//设置动画窗体
FreeLibrary(hInst);//释放动态库
OnClose() 中
DWORD dwStyle = AW_BLEND;
HINSTANCE hInst=LoadLibrary("User32.DLL");
typedef BOOL(WINAPI MYFUNC(HWND,DWORD,DWORD));
MYFUNC* AnimateWindow;
AnimateWindow=(MYFUNC *)::GetProcAddress(hInst,"AnimateWindow");
AnimateWindow(this->GetSafeHwnd(),1000,AW_HIDE | dwStyle);
FreeLibrary(hInst);
CDialog::OnClose();
设置窗体背景透明,与桌面融为一体:
SetWindowLong(GetSageWnd(),GWL_EXSTY,GetWindowLong(GetSageWnd(),GWL_EXSTY|0x80000));
typedef BOOL (WINAPI *FSetLayeredWindowAttrbitues)(HWND,COLORREF,BYTE,DwoRD);
FSetLayeredWindowAttrbitues SetLayeredWindowAttrbitues ;
HINSTANCE hInst = LoadLibrary("User32.DLL");
SetLayeredWindowAttrbitues = (SetLayeredWindowAttrbitues)GetProcAddress(hInst,"SetLayeredWindowAttrbitues");
if(SetLayeredWindowAttrbitues)
{
SetLayeredWindowAttrbitues(GetSafeHwnd(),GetSysColor(COLOR_3DFACE),255,true);
}
FreeLibrary(hInst);
改变窗体为圆角窗体:
OnInitDialog中:
CRect rect;
GetClientRect(&rect);
HRGN rgn;
rgn = CreateRoundRectRgn(0,0,rect.Width()+5,rect.Height(),30,30);
SetWindowRgn(rgn,TRUE);
return TRUE; // return TRUE unless you set the focus to a control
设置始终顶置的窗口:
::SetWindowPos(AfxGetMainWnd()->m_hWnd,HWND_TOPMOST,10,10,450,300,SWP_NOMOVE);
QQ窗口自动隐藏:<定时器技术>
void CQQHideDlg::OnTimer(UINT nIDEvent)
{
CRect rc;
CRect rect;
GetWindowRect(&rect);//窗体大小
rc.CopyRect(&rect);//复制矩形区
CPoint pOint;
GetCursorPos(&pOint);//获取鼠标位置
if(rect.top < 0 && PtInRect(rect,pOint))//显示窗体
{
rect.top = 0;
MoveWindow(rect.left,rect.top,rc.Width(),rc.Height());//移动窗体
}
else if(rect.top > -3 && rect.top < 3 && !PtInRect(rect,pOint))//隐藏窗体
{
rect.top = 3-rect.Height();
MoveWindow(rect.left,rect.top,rc.Width(),rc.Height());
}
CDialog::OnTimer(nIDEvent);
}
窗体晃动效果:
void CRockDialogDlg::OnRoct()
{
CRect rect;
this->GetWindowRect(&rect);//获取窗口大小
int off = 10;
for (int i = 0 ;i < 6 ; i++)
{
rect.OffsetRect(off,0);//窗体区域偏移
this->MoveWindow(&rect,true);//窗体移动
if (off == -10)
off = 10;
else
off = -10;
::Sleep(100);
}
}
动态更换窗体图标:
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);//获取图标资源
SetIcon(m_hIcon, TRUE);//设置大图标
SetIcon(m_hIcon, FALSE);//设置小图标
无标题栏拖动:<这个重要>
void CMoveCaptionDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
::SendMessage(GetSafeHwnd(),WM_SYSCOMMAND,SC_MOVE + HTCAPTION,0);
CDialog::OnLButtonDown(nFlags, point);
}