/************************************************************************ * 程序名: 精仿QQ主界面 * 制作人: 李克平, 2011年04月11日 * 版本号: 1.0 ************************************************************************/ // QQDlg.cpp : 实现文件 // #include "stdafx.h" #include "QQ.h" #include "QQDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif //收缩模式 #define HM_NONE 0 //不收缩 #define HM_TOP 1 //向上收缩 #define HM_BOTTOM 2 //向下收缩 #define HM_LEFT 3 //向左收缩 #define HM_RIGHT 4 //向右收缩 #define CM_ELAPSE 200 //检测鼠标是否离开窗口的时间间隔 #define HS_ELAPSE 5 //隐藏或显示过程每步的时间间隔 #define HS_STEPS 5 //隐藏或显示过程分成多少步 #define INTERVAL 10 //触发粘附时鼠标与屏幕边界的最小间隔,单位为象素 #define INFALTE 20 //触发收缩时鼠标与窗口边界的最小间隔,单位为象素 #define MINCX 200 //窗口最小宽度 #define MINCY 400 //窗口最小高度 // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 class CAboutDlg : public CDialog { public: CAboutDlg(); // 对话框数据 enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CQQDlg 对话框 CQQDlg::CQQDlg(CWnd* pParent /*=NULL*/) : CDialog(CQQDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); m_hrgn = NULL; bScreenMax = FALSE; m_isSizeChanged = FALSE; m_isSetTimer = FALSE; m_hsFinished = TRUE; m_hiding = FALSE; m_oldWndHeight = MINCY; m_taskBarHeight = 30; m_edgeHeight = 0; m_edgeWidth =0; m_hideMode = HM_NONE; } void CQQDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_BTN_CLOSE, m_btnClose); DDX_Control(pDX, IDC_BTN_MAX, m_btnMax); DDX_Control(pDX, IDC_BTN_MIN, m_btnMin); DDX_Control(pDX, IDC_BTN_WEALTH, m_btnWealth); DDX_Control(pDX, IDC_BTN_TOOL, m_btnTool); DDX_Control(pDX, IDC_BTN_SMS, m_btnSMS); DDX_Control(pDX, IDC_BTN_SELL, m_btnSell); DDX_Control(pDX, IDC_BTN_PET, m_btnPet); DDX_Control(pDX, IDC_BTN_MUSIC, m_btnMusic); DDX_Control(pDX, IDC_BTN_MSG, m_btnMSG); DDX_Control(pDX, IDC_BTN_MAIL, m_btnMail); DDX_Control(pDX, IDC_BTN_LIVE, m_btnLive); DDX_Control(pDX, IDC_BTN_LIST, m_btnList); DDX_Control(pDX, IDC_BTN_GAME, m_btnGame); DDX_Control(pDX, IDC_BTN_FIND, m_btnSearch); DDX_Control(pDX, IDC_BTN_COLOR, m_btnColor); DDX_Control(pDX, IDC_BTN_CHAT, m_btnChat); DDX_Control(pDX, IDC_BTN_BRW, m_btnBRW); DDX_Control(pDX, IDC_BTN_APP, m_btnApp); DDX_Control(pDX, IDC_BTN_ONLINE, m_btnOnline); DDX_Control(pDX, IDC_BTN_MAINMENU, m_btnMainMenu); DDX_Control(pDX, IDC_BTN_MAINFIGURE, m_btnMainFigure); DDX_Control(pDX, IDC_BTN_CLOSE, m_btnClose); DDX_Control(pDX, IDC_BTN_MAX, m_btnMax); DDX_Control(pDX, IDC_BTN_MIN, m_btnMin); DDX_Control(pDX, IDC_EDIT_SEARCH, m_editSearch); DDX_Control(pDX, IDC_STATIC_USERSTATUS, m_staUserStatus); DDX_Control(pDX, IDC_STATIC_SYSTIME, m_staSysTime); DDX_Control(pDX, IDC_STATIC_TAB, m_skinTab); DDX_Control(pDX, IDC_STATIC_USERHEAD, m_staUserHead); } BEGIN_MESSAGE_MAP(CQQDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_SIZE() ON_WM_ERASEBKGND() ON_WM_GETMINMAXINFO() ON_WM_CTLCOLOR() ON_WM_SIZING() ON_WM_MOVING() ON_WM_TIMER() ON_WM_CREATE() ON_WM_NCHITTEST() ON_WM_LBUTTONDOWN() ON_BN_CLICKED(IDC_BTN_CLOSE, OnClose) ON_BN_CLICKED(IDC_BTN_MIN, OnMin) ON_BN_CLICKED(IDC_BTN_MAX, OnMax) ON_BN_CLICKED(IDC_BTN_MAINMENU, OnBnClickedBtnMainmenu) ON_BN_CLICKED(IDC_BTN_COLOR, OnBnClickedBtnColor) END_MESSAGE_MAP() // CQQDlg 消息处理程序 BOOL CQQDlg::OnInitDialog() { CDialog::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 //修改窗体扩展风格 //ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW); // TODO: 在此添加额外的初始化代码 SetWindowText("QQ2009"); // TODO: Add extra initialization here m_bFirst = TRUE; if ( m_bFirst ) { m_skinWin.InstallSkin( this ); m_bFirst = FALSE; } CRect rcClient; GetClientRect(&rcClient); int cx = rcClient.Width(); int cy = rcClient.Height(); GetAppDir(strThemePath); strThemePath += _T("Skin\\DefaultTheme\\"); m_mainPanle.LoadImage(strThemePath + _T("MainPanle.bmp")); CString strMouseOut,strMouseIn; m_btnClose.LoadImage(strThemePath+"Close.bmp"); m_btnMax.LoadImage(strThemePath+"Max.bmp"); m_btnMin.LoadImage(strThemePath+"Min.bmp"); m_btnMainFigure.LoadImage(strThemePath+"MainFigure.bmp"); m_staUserHead.SetParent(&m_btnMainFigure); m_staUserHead.LoadBitmap(strThemePath+"figure.bmp"); //设置字体 m_font.CreateFont(15, //字体高度 0, //系统选取字体最佳宽度 0, //倾斜度为0,表示水平 0, //字体倾斜度为0 FW_BOLD, //字体粗度,400为正常 0, //无斜体字 0, //无下划线 0, //无删除线 ANSI_CHARSET, //所用的字符集 OUT_DEFAULT_PRECIS, //输出粗度为默认值 OUT_DEFAULT_PRECIS, //裁减粗度为默认值 DEFAULT_QUALITY, //输出质量为默认值 DEFAULT_PITCH|FF_DONTCARE, //字间距和字体系列 _T("Arial")); m_staUserStatus.SetText("8968737[在线]",0,RGB(7,30,129)); m_staUserStatus.SetFont(&m_font); m_staSysTime.SetText(GetStrCurrentTime(),0,RGB(27,79,116)); m_editSearch.LoadBitmap(strThemePath+"EditBox.bmp"); m_editSearch.SetText("搜索我的好友...",20,RGB(176,176,176)); m_editSearch.SetExtendPoint(12,5); m_btnOnline.LoadImage(strThemePath+"imonline.bmp",RGB(255,255,255)); strMouseIn = strThemePath+"icon\\mail.ico"; m_btnMail.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\sell.ico"; m_btnSell.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\wealth.ico"; m_btnWealth.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\list.ico"; m_btnList.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\color.ico"; m_btnColor.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\sms.ico"; m_btnSMS.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\game.ico"; m_btnGame.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\brw.ico"; m_btnBRW.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\chat.ico"; m_btnChat.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\pet.ico"; m_btnPet.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\music.ico"; m_btnMusic.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\live.ico"; m_btnLive.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\app.ico"; m_btnApp.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\tool.ico"; m_btnTool.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\msg.ico"; m_btnMSG.SetIcon(strMouseIn,strMouseIn); strMouseIn = strThemePath+"icon\\search.ico"; m_btnSearch.SetIcon(strMouseIn,strMouseIn); m_btnSearch.SetWindowText(_T("查找")); m_btnSearch.SetColor(RGB(11,77,124),RGB(11,77,124)); m_leftPanle.LoadImage(strThemePath+"leftBar.bmp"); m_outBarCtrl.Create(WS_VISIBLE|WS_CHILD,CRect(0,0,0,0),this,IDC_GFXOUTBAR); m_outBarCtrl.SetFolderImage(strThemePath+"Bar.bmp"); m_outBarCtrl.SetSelIcon(strThemePath+"icon\\Find.ico"); wndTree.Create(WS_CHILD|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS|TVS_SHOWSELALWAYS, CRect(0,0,0,0), &m_outBarCtrl, 1010); //wndTree.SetImageList(&imaSmall, TVSIL_NORMAL); HTREEITEM htm = wndTree.InsertItem("tree 1", 0,0); HTREEITEM htm1 = wndTree.InsertItem("tree 2", 1,1, htm); wndTree.InsertItem("tree 3", 1,1, htm); for (int xx = 0; xx < 15; xx ++) { htm = wndTree.InsertItem("tree 1", 0,0); htm1 = wndTree.InsertItem("tree 2", 1,1, htm); wndTree.InsertItem("tree 3", 1,1, htm); htm = wndTree.InsertItem("tree 1", 0,0); htm1 = wndTree.InsertItem("tree asda2", 1,1, htm); wndTree.InsertItem("tree 3", 1,1, htm); } m_imHead.Create(40, 40, ILC_MASK|ILC_COLOR32, 1, 1); //添加ID 为IDI_ICON的图标 //m_imHead.Add( AfxGetApp()->LoadIcon(IDI_ICON)); //从图标文件中加载并添加 // HICON hIcon = (HICON)LoadImage(NULL, ".\\image\\SQQun.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE) // m_imHead.Add(hIcon); //从位图文件中加载并添加 CBitmap *pBitmap=new CBitmap; CString strHead,strApp; GetAppDir(strApp); for(int i = 1;i<=134;i++) { strHead.Format("NEWFACE\\%d.bmp",i); strHead = strApp + strHead; pBitmap->m_hObject = (HBITMAP) LoadImage(NULL, strHead, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); m_imHead.Add(pBitmap, RGB(255,255, 255)/*mask color*/); } delete pBitmap; //先创建ListCtrl (m_MyFriendListCtrl) if(m_MyFriendListCtrl.Create(LVS_REPORT |LVS_NOCOLUMNHEADER|LVS_OWNERDRAWFIXED|LVS_SHOWSELALWAYS|WS_CHILD, CRect(0,0,0,0), &m_outBarCtrl, IDD_TALKER_LIST/*ID*/)) { m_MyFriendListCtrl.SetExtendedStyle( m_MyFriendListCtrl.GetExtendedStyle()| LVS_EX_FULLROWSELECT); m_MyFriendListCtrl.SetImageList(&m_imHead,LVSIL_SMALL); m_MyFriendListCtrl.InsertColumn(0,"名字",LVCFMT_LEFT); //m_MyFriendListCtrl.SetColumnWidth(0 ,100); //往ListCtrl 中添加好友 for(int i=0; i<134; i++) { CString strTemp = _T(""); LUSERITEM userInfo = {0}; //CString strTemp; strTemp.Format("我的好友%d",i); userInfo.szUserID = strTemp.GetBuffer(strTemp.GetLength()); strTemp.ReleaseBuffer(); userInfo.szNoticeMsg = _T("没有你,世界寸步难行!"); m_MyFriendListCtrl.InsertItem(i,strTemp, i,&userInfo);//第三个参数 Index of the ImageList m_MyFriendListCtrl.SetItemData(i,(i%2)? i|CMyListCtrl::TVS_EMAIL:i); } } m_outBarCtrl.AddFolderBar("QQ好友",&m_MyFriendListCtrl,0); m_outBarCtrl.AddFolderBar("通讯录", &wndTree,1); m_outBarCtrl.AddFolder("QQ群",2); m_outBarCtrl.AddFolder("最近联系人",3); m_outBarCtrl.SetSelFolder(0); m_skinTab.SetSkin(strThemePath+"TabBG.bmp"); //m_skinTab.SetSkinBG(strThemePath+"leftBar.bmp"); m_skinTab.SetIcon(0,strThemePath+"icon\\FriendButton.ico",&m_outBarCtrl); m_skinTab.SetIcon(1,strThemePath+"icon\\NetDiskButton.ico",NULL); m_skinTab.SetIcon(2,strThemePath+"icon\\QZONE_Bar.ico",NULL); m_skinTab.SetIcon(3,strThemePath+"icon\\papa.ico",NULL); m_skinTab.SetIcon(4,strThemePath+"icon\\ContentsButton.ico",NULL); m_skinTab.SetIcon(5,strThemePath+"icon\\BlankPanel.ico",NULL); m_skinTab.m_iCurrentSelect=0; m_btnMainMenu.LoadImage(strThemePath+"MainMenu.bmp"); SetTimer(3,1000,NULL); //开启系统时间显示 return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } void CQQDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // 如果向对话框添加最小化按钮,则需要下面的代码 // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序, // 这将由框架自动完成。 void CQQDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // 使图标在工作区矩形中居中 int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { ChangeWindowRgn(); AdjustControl(); CPaintDC dc(this); // 用于绘制的设备上下文 CRect rcClient; GetClientRect(&rcClient); //调整控件位置//////////////////////////// //内存画图////////////////////////// CDC m_MemDC; m_MemDC.CreateCompatibleDC(&dc); CBitmap btScreen; btScreen.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height()); m_MemDC.SelectObject(&btScreen); btScreen.DeleteObject(); //画背景 //MemDC.Rectangle(rcClient); //m_MemDC.FillSolidRect(rcClient,RGB(91,195,252));//draw the backGround if (m_mainPanle.m_hObject !=0) m_mainPanle.ExtendDraw(&m_MemDC,rcClient,100,125); if(m_leftPanle.m_hObject != 0) { m_leftPanle.ExtendDraw(&m_MemDC, CRect(2,115,m_leftPanle.Width()+1,rcClient.bottom-50),2,10); } //创建不规则窗体 //ChangeWindowRgn(&m_MemDC); //ChangeWindowRgn(); //重画控件///////////////////////// ReDrawCrl(&m_MemDC); //画到显示器上//////////////////////////// dc.BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), &m_MemDC, 0, 0, SRCCOPY); m_MemDC.DeleteDC(); } } //当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSOR CQQDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } BOOL CQQDlg::PreTranslateMessage(MSG* pMsg) { // TODO: 在此添加专用代码和/或调用基类 // 单击除了窗口标题栏以外的区域使窗口移动 if (pMsg->message == WM_LBUTTONDOWN && pMsg->hwnd == m_hWnd) { pMsg->message = WM_NCLBUTTONDOWN; pMsg->wParam = HTCAPTION; } if (pMsg->message == WM_LBUTTONDBLCLK && pMsg->hwnd == m_hWnd) { OnMax(); } return CDialog::PreTranslateMessage(pMsg); } void CQQDlg::OnMax() { // TODO: Add your control notification handler code here if(bScreenMax) { m_btnMax.LoadImage(strThemePath+"max.bmp"); ::MoveWindow( m_hWnd, m_rectRestoreWin.left, m_rectRestoreWin.top, m_rectRestoreWin.Width(), m_rectRestoreWin.Height(), TRUE ); bScreenMax = FALSE; UpdateWindow(); } else { CRect rc; SystemParametersInfo(SPI_GETWORKAREA, 0, rc, 0); GetWindowRect(m_rectRestoreWin ); m_btnMax.LoadImage(strThemePath+"restore.bmp"); //ShowWindow(SW_SHOWMAXIMIZED); ::MoveWindow( m_hWnd, rc.left, rc.top, rc.Width(), rc.Height(), TRUE); bScreenMax = TRUE; UpdateWindow(); } } void CQQDlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); Invalidate(); // TODO: 在此处添加消息处理程序代码 } BOOL CQQDlg::OnEraseBkgnd(CDC* pDC) { // TODO: 在此添加消息处理程序代码和/或调用默认值 return TRUE; //return CDialog::OnEraseBkgnd(pDC); } //创建不规则窗体 void CQQDlg::ChangeWindowRgn() { CRect rc; GetClientRect(&rc); CEnBitmap bmpMain; if (m_mainPanle.m_hObject !=NULL) m_mainPanle.ExtendDrawImage(bmpMain,rc,100,125); if(m_hrgn) DeleteObject(m_hrgn); m_hrgn = bmpMain.BitmapToRegion(RGB(255,0,255)); SetWindowRgn(m_hrgn,TRUE); bmpMain.DeleteObject(); } void CQQDlg::ReDrawCrl(CDC* m_MemDC) { CRect rcClient; GetClientRect(&rcClient); static bool firstGetClientRect = true; static int preClientHeight = rcClient.Height(); static int preClientWidth = rcClient.Width(); if(firstGetClientRect) { firstGetClientRect = false; } if(firstGetClientRect||preClientHeight!=rcClient.Height()||preClientWidth!=rcClient.Width()) { preClientHeight = rcClient.Height(); preClientWidth = rcClient.Width(); CEnBitmap *bmpPaint = NULL; CImage *image=NULL; CRect rect; CRect rcIcon; CPoint ptText; CString strText; //CFont font; //font.CreatePointFont(90,_T("Arial")); //m_MemDC->SelectObject(&font); GetClientRect(&rect); int cx=rect.Width(); int cy=rect.Height(); m_staUserStatus.Redraw(m_MemDC); m_staSysTime.Redraw(m_MemDC); m_MemDC->BitBlt(5,90,cx-10,m_editSearch.Height(),m_editSearch.GetWindowDC(),0,0,SRCCOPY); m_MemDC->BitBlt(1,115,m_skinTab.Width(),m_skinTab.Heighth(),m_skinTab.GetWindowDC(),0,0,SRCCOPY); if(m_skinTab.m_iCurrentSelect == 0) m_MemDC->BitBlt(37,117,cx-43,cy-173,m_outBarCtrl.GetWindowDC(),0,0,SRCCOPY); bmpPaint = m_btnMainFigure.GetPaintBmp(); rect = m_btnMainFigure.GetRectInParent(); if(bmpPaint->m_hObject != 0) bmpPaint->TransparentBlt(*m_MemDC, rect, RGB(255,0,255)); bmpPaint = m_btnMin.GetPaintBmp(); rect = m_btnMin.GetRectInParent(); if(bmpPaint->m_hObject != 0) bmpPaint->TransparentBlt(*m_MemDC, rect, RGB(255,0,255)); bmpPaint = m_btnMax.GetPaintBmp(); rect = m_btnMax.GetRectInParent(); if(bmpPaint->m_hObject != 0) bmpPaint->TransparentBlt(*m_MemDC, rect, RGB(255,0,255)); bmpPaint = m_btnClose.GetPaintBmp(); rect = m_btnClose.GetRectInParent(); if(bmpPaint->m_hObject != 0) bmpPaint->TransparentBlt(*m_MemDC, rect, RGB(255,0,255)); bmpPaint = m_btnMainMenu.GetPaintBmp(); rect = m_btnMainMenu.GetRectInParent(); if(bmpPaint->m_hObject != 0) bmpPaint->TransparentBlt(*m_MemDC, rect, RGB(255,0,255)); bmpPaint = m_btnOnline.GetPaintBmp(); rect = m_btnOnline.GetRectInParent(); if(bmpPaint->m_hObject != 0) bmpPaint->TransparentBlt(*m_MemDC, rect, RGB(255,255,255)); image=m_btnMail.GetPaintIcon(); rect = m_btnMail.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnSell.GetPaintIcon(); rect = m_btnSell.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnWealth.GetPaintIcon(); rect = m_btnWealth.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnList.GetPaintIcon(); rect = m_btnList.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnColor.GetPaintIcon(); rect = m_btnColor.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnSMS.GetPaintIcon(); rect = m_btnSMS.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnGame.GetPaintIcon(); rect = m_btnGame.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnBRW.GetPaintIcon(); rect = m_btnBRW.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnChat.GetPaintIcon(); rect = m_btnChat.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnPet.GetPaintIcon(); rect = m_btnPet.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnMusic.GetPaintIcon(); rect = m_btnMusic.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnLive.GetPaintIcon(); rect = m_btnLive.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnApp.GetPaintIcon(); rect = m_btnApp.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnTool.GetPaintIcon(); rect = m_btnTool.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnMSG.GetPaintIcon(); rect = m_btnMSG.GetRectInParent(); if(!image->IsNull()) image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); image=m_btnSearch.GetPaintIcon(); rect = m_btnSearch.GetRectInParent(); if(!image->IsNull()) { image->TransparentBlt(m_MemDC->m_hDC, rect.left+2,rect.top+2,16,16, RGB(0,0,0)); ptText = m_btnSearch.GetTextPos(); m_btnSearch.GetWindowText(strText); m_MemDC->TextOut(rect.left+ptText.x+2,rect.top+ptText.y+2,strText); } } } void CQQDlg::AdjustControl() { CRect rc; GetClientRect(&rc); int cx=rc.Width(); int cy=rc.Height(); m_btnClose.SetWindowPos(NULL,cx-m_btnClose.Width()-10 ,0 ,0,0, SWP_NOSIZE); m_btnMax.SetWindowPos(NULL,cx-m_btnClose.Width()-m_btnMax.Width()-10 ,0 ,0,0, SWP_NOSIZE); m_btnMin.SetWindowPos(NULL,cx-m_btnClose.Width()-m_btnMax.Width()-m_btnMin.Width()-10 ,0 ,0,0, SWP_NOSIZE); m_btnMainFigure.SetWindowPos(NULL,5,30,0,0,SWP_NOSIZE); m_staUserHead.SetWindowPos(NULL,9,9,40,40,NULL); m_btnMail.SetWindowPos(NULL,70 ,66,0,0, SWP_NOSIZE); m_btnSell.SetWindowPos(NULL,70 +25,66,0,0, SWP_NOSIZE); m_btnWealth.SetWindowPos(NULL,70 +25*2,66,0,0, SWP_NOSIZE); m_btnList.SetWindowPos(NULL,70 +25*3,66,0,0, SWP_NOSIZE); m_btnColor.SetWindowPos(NULL,cx-30,66,0,0, SWP_NOSIZE); m_staUserStatus.SetWindowPos(NULL,85,30,0,0,SWP_NOSIZE); m_staSysTime.SetWindowPos(NULL,70,50,0,0,SWP_NOSIZE); m_editSearch.SetWindowPos(NULL,5,90,cx-10,m_editSearch.Height(),NULL); m_btnOnline.SetWindowPos(NULL,70,35,0,0,SWP_NOSIZE); m_btnSMS.SetWindowPos(NULL,50,cy-50,0,0, SWP_NOSIZE); m_btnGame.SetWindowPos(NULL,50 +25,cy-50,0,0, SWP_NOSIZE); m_btnBRW.SetWindowPos(NULL,50 +25*2,cy-50,0,0, SWP_NOSIZE); m_btnChat.SetWindowPos(NULL,50 +25*3,cy-50,0,0, SWP_NOSIZE); m_btnPet.SetWindowPos(NULL,50 +25*4,cy-50,0,0, SWP_NOSIZE); m_btnMusic.SetWindowPos(NULL,50 +25*5,cy-50,0,0, SWP_NOSIZE); m_btnLive.SetWindowPos(NULL,50 +25*6,cy-50,0,0, SWP_NOSIZE); m_btnApp.SetWindowPos(NULL,50 ,cy-25,0,0, SWP_NOSIZE); m_btnTool.SetWindowPos(NULL,50+25,cy-25,0,0, SWP_NOSIZE); m_btnMSG.SetWindowPos(NULL,50 +25*2 ,cy-25,0,0, SWP_NOSIZE); m_btnSearch.SetWindowPos(NULL,50 +25*3 ,cy-25,50,20, NULL); m_skinTab.SetWindowPos(NULL,1,115,m_skinTab.Width(),m_skinTab.Heighth(),NULL); m_outBarCtrl.SetWindowPos(NULL,37,117,cx-43,cy-173,NULL); m_btnMainMenu.SetWindowPos(NULL,0 ,cy-m_btnMainMenu.Heighth(),0,0, SWP_NOSIZE); } void CQQDlg::OnClose() { // TODO: 在此添加控件通知处理程序代码 PostQuitMessage(0); } void CQQDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI) { // TODO: 在此添加消息处理程序代码和/或调用默认值 lpMMI->ptMinTrackSize = CPoint( m_mainPanle.Width()+10, m_mainPanle.Height()+300 ); CDialog::OnGetMinMaxInfo(lpMMI); } HBRUSH CQQDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: 在此更改 DC 的任何属性 switch (nCtlColor) { case CTLCOLOR_STATIC: { //判断背景画刷和位图背景是否有效,当二者之一有效时 //类名字符串最大长度 #define MAX_CLASS_NAME 255 //对于静态控件 if (nCtlColor == CTLCOLOR_STATIC) { TCHAR lpszClassName [MAX_CLASS_NAME + 1]; //获取控件的类名信息 ::GetClassName (pWnd->GetSafeHwnd (), lpszClassName, MAX_CLASS_NAME); CString strClass = lpszClassName; //一般静态文本 if (strClass == _T("Static")) { pDC->SetBkMode(TRANSPARENT); return (HBRUSH) ::GetStockObject (HOLLOW_BRUSH); } //分组框左上角静态文本 if (strClass == _T("Button")) { //pDC->SetBkMode(TRANSPARENT); pDC->SetBkColor(GetSysColor(COLOR_3DFACE)); return (HBRUSH) ::GetStockObject (NULL_BRUSH); //return (HBRUSH)m_brBkgr.GetSafeHandle(); } } } break; } // TODO: 如果默认的不是所需画笔,则返回另一个画笔 return hbr; } void CQQDlg::OnMin() { ShowWindow(SW_SHOWMINIMIZED); } void CQQDlg::OnSizing(UINT fwSide, LPRECT pRect) { FixSizing(fwSide,pRect); //修正pRect CDialog::OnSizing(fwSide, pRect); } void CQQDlg::FixSizing(UINT fwSide, LPRECT pRect) { CRect curRect(pRect); if(curRect.Width() < MINCX || curRect.Height() < MINCY) { //小于指定的最小宽度或高度 switch(fwSide) { case WMSZ_BOTTOM: pRect->bottom = pRect->top + MINCY; break; case WMSZ_BOTTOMLEFT: if(curRect.Width() <= MINCX) pRect->left = pRect->right - MINCX; if(curRect.Height() <= MINCY) pRect->bottom = pRect->top + MINCY; break; case WMSZ_BOTTOMRIGHT: if(curRect.Width() < MINCX) pRect->right = pRect->left + MINCX; if(curRect.Height() < MINCY) pRect->bottom = pRect->top + MINCY; break; case WMSZ_LEFT: pRect->left = pRect->right - MINCX; break; case WMSZ_RIGHT: pRect->right = pRect->left + MINCX; break; case WMSZ_TOP: pRect->top = pRect->bottom - MINCY; break; case WMSZ_TOPLEFT: if(curRect.Width() <= MINCX) pRect->left = pRect->right - MINCX; if(curRect.Height() <= MINCY) pRect->top = pRect->bottom - MINCY; break; case WMSZ_TOPRIGHT: if(curRect.Width() < MINCX) pRect->right = pRect->left + MINCX; if(curRect.Height() < MINCY) pRect->top = pRect->bottom - MINCY; break; } } } void CQQDlg::OnMoving(UINT fwSide, LPRECT pRect) { FixMoving(fwSide,pRect); //修正pRect CDialog::OnMoving(fwSide, pRect); } void CQQDlg::FixMoving(UINT fwSide, LPRECT pRect) { POINT curPos; GetCursorPos(&curPos); INT screenHeight = GetSystemMetrics(SM_CYSCREEN); INT screenWidth = GetSystemMetrics(SM_CXSCREEN); INT height = pRect->bottom - pRect->top; INT width = pRect->right - pRect->left; if (curPos.y <= INTERVAL) { //粘附在上边 pRect->bottom = height - m_edgeHeight; pRect->top = -m_edgeHeight; m_hideMode = HM_TOP; } else if(curPos.y >= (screenHeight - INTERVAL - m_taskBarHeight)) { //粘附在下边 pRect->top = screenHeight - m_taskBarHeight - height; pRect->bottom = screenHeight - m_taskBarHeight; m_hideMode = HM_BOTTOM; } else if (curPos.x < INTERVAL) { //粘附在左边 if(!m_isSizeChanged) { CRect tRect; GetWindowRect(tRect); m_oldWndHeight = tRect.Height(); } pRect->right = width; pRect->left = 0; pRect->top = -m_edgeHeight; pRect->bottom = screenHeight - m_taskBarHeight; m_isSizeChanged = TRUE; m_hideMode = HM_LEFT; } else if(curPos.x >= (screenWidth - INTERVAL)) { //粘附在右边 if(!m_isSizeChanged) { CRect tRect; GetWindowRect(tRect); m_oldWndHeight = tRect.Height(); } pRect->left = screenWidth - width; pRect->right = screenWidth; pRect->top = -m_edgeHeight; pRect->bottom = screenHeight - m_taskBarHeight; m_isSizeChanged = TRUE; m_hideMode = HM_RIGHT; } else { //不粘附 if(m_isSizeChanged) { //如果收缩到两边,则拖出来后会变回原来大小 //在"拖动不显示窗口内容下"只有光栅变回原来大小 pRect->bottom = pRect->top + m_oldWndHeight; m_isSizeChanged = FALSE; } if(m_isSetTimer) { //如果Timer开启了,则关闭之 if(KillTimer(1) == 1) m_isSetTimer = FALSE; } m_hideMode = HM_NONE; //GetDlgItem(IDC_TIMER)->SetWindowText("Timer off"); } } void CQQDlg::OnTimer(UINT_PTR nIDEvent) { // TODO: Add your message handler code here and/or call default if(nIDEvent == 1 ) { POINT curPos; GetCursorPos(&curPos); //CString str; //str.Format("Timer On(%d,%d)",curPos.x,curPos.y); //GetDlgItem(IDC_TIMER)->SetWindowText(str); CRect tRect; //获取此时窗口大小 GetWindowRect(tRect); //膨胀tRect,以达到鼠标离开窗口边沿一定距离才触发事件 tRect.InflateRect(INFALTE,INFALTE); if(!tRect.PtInRect(curPos)) //如果鼠标离开了这个区域 { KillTimer(1); //关闭检测鼠标Timer m_isSetTimer = FALSE; //GetDlgItem(IDC_TIMER)->SetWindowText("Timer Off"); m_hsFinished = FALSE; m_hiding = TRUE; SetTimer(2,HS_ELAPSE,NULL); //开启收缩过程 } } if(nIDEvent == 2) { if(m_hsFinished) //如果收缩或显示过程完毕则关闭Timer KillTimer(2); else m_hiding ? DoHide() : DoShow(); } if(nIDEvent == 3) { m_staSysTime.SetText(GetStrCurrentTime(),0,RGB(27,79,116)); InvalidateRect(m_staSysTime.GetRectInParent(),TRUE); } CDialog::OnTimer(nIDEvent); } CString CQQDlg::GetStrCurrentTime() { CTime CurTime=CTime::GetCurrentTime(); int nWeek = CurTime.GetDayOfWeek(); CString strWeek,strTime; switch(nWeek) { case 1: strWeek = _T("星期日"); break; case 2: strWeek = _T("星期一"); break; case 3: strWeek = _T("星期二"); break; case 4: strWeek = _T("星期三"); break; case 5: strWeek = _T("星期四"); break; case 6: strWeek = _T("星期五"); break; case 7: strWeek = _T("星期六"); break; default: break; } //strTime = CurTime.Format("%m月%d日 星期%w %X"); strTime.Format(_T("%d月%d日 %s %s"),CurTime.GetMonth(),CurTime.GetDay(),strWeek,CurTime.Format("%X")); return strTime; } BOOL CQQDlg::SetWindowPos(const CWnd* pWndInsertAfter, LPCRECT pCRect, UINT nFlags) { return CDialog::SetWindowPos(pWndInsertAfter,pCRect->left, pCRect->top, pCRect->right - pCRect->left, pCRect->bottom - pCRect->top, nFlags); } void CQQDlg::DoHide() { if(m_hideMode == HM_NONE) return; CRect tRect; GetWindowRect(tRect); INT height = tRect.Height(); INT width = tRect.Width(); INT steps = 0; switch(m_hideMode) { case HM_TOP: steps = height/HS_STEPS; tRect.bottom -= steps; if(tRect.bottom <= m_edgeWidth) { //你可以把下面一句替换上面的 ...+=|-=steps 达到取消抽屉效果 //更好的办法是添加个BOOL值来控制,其他case同样. tRect.bottom = m_edgeWidth; m_hsFinished = TRUE; //完成隐藏过程 } tRect.top = tRect.bottom - height; break; case HM_BOTTOM: steps = height/HS_STEPS; tRect.top += steps; if(tRect.top >= (GetSystemMetrics(SM_CYSCREEN) - m_edgeWidth)) { tRect.top = GetSystemMetrics(SM_CYSCREEN) - m_edgeWidth; m_hsFinished = TRUE; } tRect.bottom = tRect.top + height; break; case HM_LEFT: steps = width/HS_STEPS; tRect.right -= steps; if(tRect.right <= m_edgeWidth) { tRect.right = m_edgeWidth; m_hsFinished = TRUE; } tRect.left = tRect.right - width; tRect.top = -m_edgeHeight; tRect.bottom = GetSystemMetrics(SM_CYSCREEN) - m_taskBarHeight; break; case HM_RIGHT: steps = width/HS_STEPS; tRect.left += steps; if(tRect.left >= (GetSystemMetrics(SM_CXSCREEN) - m_edgeWidth)) { tRect.left = GetSystemMetrics(SM_CXSCREEN) - m_edgeWidth; m_hsFinished = TRUE; } tRect.right = tRect.left + width; tRect.top = -m_edgeHeight; tRect.bottom = GetSystemMetrics(SM_CYSCREEN) - m_taskBarHeight; break; default: break; } SetWindowPos(&wndTopMost,tRect); } void CQQDlg::DoShow() { if(m_hideMode == HM_NONE) return; CRect tRect; GetWindowRect(tRect); INT height = tRect.Height(); INT width = tRect.Width(); INT steps = 0; switch(m_hideMode) { case HM_TOP: steps = height/HS_STEPS; tRect.top += steps; if(tRect.top >= -m_edgeHeight) { //你可以把下面一句替换上面的 ...+=|-=steps 达到取消抽屉效果 //更好的办法是添加个BOOL值来控制,其他case同样. tRect.top = -m_edgeHeight; m_hsFinished = TRUE; //完成显示过程 } tRect.bottom = tRect.top + height; break; case HM_BOTTOM: steps = height/HS_STEPS; tRect.top -= steps; if(tRect.top <= (GetSystemMetrics(SM_CYSCREEN) - height)) { tRect.top = GetSystemMetrics(SM_CYSCREEN) - height; m_hsFinished = TRUE; } tRect.bottom = tRect.top + height; break; case HM_LEFT: steps = width/HS_STEPS; tRect.right += steps; if(tRect.right >= width) { tRect.right = width; m_hsFinished = TRUE; } tRect.left = tRect.right - width; tRect.top = -m_edgeHeight; tRect.bottom = GetSystemMetrics(SM_CYSCREEN) - m_taskBarHeight; break; case HM_RIGHT: steps = width/HS_STEPS; tRect.left -= steps; if(tRect.left <= (GetSystemMetrics(SM_CXSCREEN) - width)) { tRect.left = GetSystemMetrics(SM_CXSCREEN) - width; m_hsFinished = TRUE; } tRect.right = tRect.left + width; tRect.top = -m_edgeHeight; tRect.bottom = GetSystemMetrics(SM_CYSCREEN) - m_taskBarHeight; break; default: break; } SetWindowPos(&wndTopMost,tRect); } int CQQDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CDialog::OnCreate(lpCreateStruct) == -1) return -1; //获得任务栏高度 CWnd* p; p = this->FindWindow("Shell_TrayWnd",NULL); if(p != NULL) { CRect tRect; p->GetWindowRect(tRect); m_taskBarHeight = tRect.Height(); } //修改风格使得他不在任务栏显示 //ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW); //去掉关闭按键(如果想画3个按键的话) //ModifyStyle(WS_SYSMENU,NULL); //获得边缘高度和宽度 m_edgeHeight = GetSystemMetrics(SM_CYEDGE); m_edgeWidth = GetSystemMetrics(SM_CXFRAME); //可以在这里读取上次关闭后保存的大小 return 0; } LRESULT CQQDlg::OnNcHitTest(CPoint point) { //CString str; //str.Format("Mouse (%d,%d)",point.x,point.y); //GetDlgItem(IDC_CURSOR)->SetWindowText(str); if(m_hideMode != HM_NONE && !m_isSetTimer && //防止鼠标超出屏幕右边时向右边收缩造成闪烁 point.x < GetSystemMetrics(SM_CXSCREEN) + INFALTE) { //鼠标进入时,如果是从收缩状态到显示状态则开启Timer SetTimer(1,CM_ELAPSE,NULL); m_isSetTimer = TRUE; m_hsFinished = FALSE; m_hiding = FALSE; SetTimer(2,HS_ELAPSE,NULL); //开启显示过程 } return CDialog::OnNcHitTest(point); } void CQQDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 //SetCapture(); CDialog::OnLButtonDown(nFlags, point); } void CQQDlg::OnBnClickedBtnMainmenu() { // TODO: 在此添加控件通知处理程序代码 CAboutDlg dlg; dlg.DoModal(); } void CQQDlg::OnBnClickedBtnColor() { // TODO: 在此添加控件通知处理程序代码 CAboutDlg dlg; dlg.DoModal(); }