gusucode.com > VC++模仿QQ界面风格源码程序 > VC++模仿QQ界面风格/MICQDlg.cpp
// MICQDlg.cpp : implementation file // #include "stdafx.h" #include "MICQ.h" #include "MICQDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define DETASTEP 10 #define IDC_MYLIST 10100 #define ID_QMENU_ITEMS WM_USER+10 ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About #include "hyperlink.h" class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; CHyperLink m_HomePage; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) DDX_Control(pDX, IDC_HOMEPAGE, m_HomePage); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMICQDlg dialog int g_bDlgStatus=0; BOOL AdjustPos(CRect* lpRect) {//自动靠边 int iSX=GetSystemMetrics(SM_CXFULLSCREEN); int iSY=GetSystemMetrics(SM_CYFULLSCREEN); RECT rWorkArea; BOOL bResult = SystemParametersInfo(SPI_GETWORKAREA, sizeof(RECT), &rWorkArea, 0); CRect rcWA; if(!bResult) {//如果调用不成功就利用GetSystemMetrics获取屏幕面积 rcWA=CRect(0,0,iSX,iSY); } else rcWA=rWorkArea; int iX=lpRect->left; int iY=lpRect->top; if(iX < rcWA.left + DETASTEP && iX!=rcWA.left) {//调整左 //pWnd->SetWindowPos(NULL,rcWA.left,iY,0,0,SWP_NOSIZE); lpRect->OffsetRect(rcWA.left-iX,0); AdjustPos(lpRect); g_bDlgStatus=1; return TRUE; } if(iY < rcWA.top + DETASTEP && iY!=rcWA.top) {//调整上 //pWnd->SetWindowPos(NULL ,iX,rcWA.top,0,0,SWP_NOSIZE); lpRect->OffsetRect(0,rcWA.top-iY); AdjustPos(lpRect); g_bDlgStatus=2; return TRUE; } if(iX + lpRect->Width() > rcWA.right - DETASTEP && iX !=rcWA.right-lpRect->Width()) {//调整右 //pWnd->SetWindowPos(NULL ,rcWA.right-rcW.Width(),iY,0,0,SWP_NOSIZE); lpRect->OffsetRect(rcWA.right-lpRect->right,0); AdjustPos(lpRect); g_bDlgStatus=3; return TRUE; } if(iY + lpRect->Height() > rcWA.bottom - DETASTEP && iY !=rcWA.bottom-lpRect->Height()) {//调整下 //pWnd->SetWindowPos(NULL ,iX,rcWA.bottom-rcW.Height(),0,0,SWP_NOSIZE); lpRect->OffsetRect(0,rcWA.bottom-lpRect->bottom); g_bDlgStatus=4; return TRUE; } g_bDlgStatus=0; return FALSE; } CMICQDlg::CMICQDlg(CWnd* pParent /*=NULL*/) : CDialog(CMICQDlg::IDD, pParent) { //{{AFX_DATA_INIT(CMICQDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CMICQDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMICQDlg) DDX_Control(pDX, IDC_SEARCH, m_SearchBtn); DDX_Control(pDX, IDC_NEWS, m_NewsBtn); DDX_Control(pDX, IDC_MICQ, m_MicqBtn); DDX_Control(pDX, IDC_MESSAGE, m_MessageBtn); DDX_Control(pDX, IDC_LOGIN, m_LoginBtn); DDX_Control(pDX, IDC_IE, m_IeBtn); DDX_Control(pDX, IDC_HANDTEL, m_HandBtn); DDX_Control(pDX, IDC_FRIEND, m_FriBtn); DDX_Control(pDX, IDC_CHAT, m_ChatBtn); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMICQDlg, CDialog) //{{AFX_MSG_MAP(CMICQDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_MOVING() ON_BN_CLICKED(IDC_MICQ, OnMicq) ON_COMMAND(ID_QMENU_ITEMS, OnMenu) ON_COMMAND(ID_QMENU_ITEMS+1, OnMenu) ON_COMMAND(ID_QMENU_ITEMS+2, OnMenu) ON_COMMAND(ID_QMENU_ITEMS+3, OnMenu) ON_COMMAND(ID_QMENU_ITEMS+4, OnMenu) ON_COMMAND(ID_QMENU_ITEMS+5, OnMenu) ON_COMMAND(ID_QMENU_ITEMS+6, OnMenu) ON_COMMAND(ID_QMENU_ITEMS+7, OnMenu) ON_COMMAND(ID_QMENU_ITEMS+8, OnMenu) ON_COMMAND(ID_QMENU_ITEMS+9, OnMenu) ON_COMMAND(ID_QMENU_ITEMS+10, OnMenu) ON_COMMAND(ID_QMENU_ITEMS+11, OnMenu) //}}AFX_MSG_MAP ON_MESSAGE(WM_OUTBAR_NOTIFY, OnOutbarNotify) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMICQDlg message handlers BOOL CMICQDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. 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); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here // TODO: Add extra initialization here DWORD dwf = CGfxOutBarCtrl::fDragItems|CGfxOutBarCtrl::fEditGroups|CGfxOutBarCtrl::fEditItems|CGfxOutBarCtrl::fRemoveGroups| CGfxOutBarCtrl::fRemoveItems|CGfxOutBarCtrl::fAddGroups|CGfxOutBarCtrl::fAnimation |CGfxOutBarCtrl::fSelHighlight; wndBar.Create(WS_CHILD|WS_VISIBLE, CRect(0,22,83,272), this,IDC_MYLIST, dwf); wndBar.SetOwner(this); imaLarge.Create(IDB_IMAGELIST, 32, 0, RGB(0,130,132)); imaSmall.Create(IDB_SMALL_IMAGELIST, 16, 0, RGB(0,128,128)); wndBar.SetImageList(&imaLarge, CGfxOutBarCtrl::fLargeIcon); wndBar.SetImageList(&imaSmall, CGfxOutBarCtrl::fSmallIcon); wndBar.SetAnimationTickCount(20); wndBar.SetAnimSelHighlight(200); wndBar.AddFolder("我的好友", 0); wndBar.AddFolder("mm",1); wndBar.AddFolder("小妹妹", 2); wndBar.AddFolder("陌生人", 3); wndBar.AddFolder("黑名单", 4); wndBar.InsertItem(0, 0, "mm", 0, 0); wndBar.InsertItem(0, 1, "angle", 1, 0); wndBar.InsertItem(0, 2, "格格", 2, 0); wndBar.InsertItem(0, 3, "丁晶", 3, 0); wndBar.InsertItem(0, 4, "CoCo", 0, 0); wndBar.InsertItem(0, 5, "frost", 1, 0); wndBar.InsertItem(0, 6, "谢朝阳", 2, 0); wndBar.InsertItem(0, 7, "Kelly", 3, 0); wndBar.InsertItem(0, 8, "宝贝", 0, 0); wndBar.InsertItem(0, 9, "雪儿", 1, 0); wndBar.InsertItem(0, 10, "闭月体花", 2, 0); wndBar.InsertItem(0, 11, "Love", 3, 0); wndBar.InsertItem(0, 12, "wife", 0, 0); wndBar.InsertItem(0, 13, "Yangdd", 1, 0); wndBar.InsertItem(0, 14, "秋叶子", 2, 0); wndBar.InsertItem(0, 15, "马世俊", 3, 0); wndBar.InsertItem(0, 1, "宫立波", 3, 0); wndBar.InsertItem(0, 17, "大师", 3, 0); wndBar.InsertItem(2, 0, "我们", 0, 0); wndBar.InsertItem(2, 1, "测试",0,0); wndBar.InsertItem(2, 2, "fox", 2, 0); wndBar.InsertItem(2, 3, "Virus", 3, 0); wndBar.SetSelFolder(0); m_openWindow.left = m_openWindow.top = m_openWindow.right = m_openWindow.bottom = 0; m_SearchBtn.SetIcon(IDR_SEARCH); m_NewsBtn.SetIcon(IDR_SJ); m_MicqBtn.SetBitmap(IDB_XICQ,IDB_MICQ); m_MessageBtn.SetIcon(IDR_MESSAGE); m_LoginBtn.SetIcon(IDR_MDISABLE,IDR_QQ); m_IeBtn.SetIcon(IDR_HOMEPAGE); m_HandBtn.SetIcon(IDR_SJ1); m_FriBtn.SetIcon(IDR_FRIEND); m_ChatBtn.SetIcon(IDR_CHAT); m_resize.Create( this, TRUE,300); CResizeInfo rInfo[] = { // id l t w h { IDC_MYLIST, 0, 0, 300, 300 }, { IDC_CHAT, 0, 300, 0, 0 }, { IDC_SEARCH, 0, 300, 300, 0 }, { IDC_IE, 0, 300, 0, 0 }, { IDC_MESSAGE, 0, 300, 300, 0 }, { IDC_MICQ, 0, 300, 0, 0 }, { IDC_LOGIN, 0, 300, 300, 0 }, { 0 }, }; m_resize.Add( rInfo ); m_resize.SetMinimumTrackingSize(); return TRUE; // return TRUE unless you set the focus to a control } void CMICQDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CMICQDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle 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; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CMICQDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CMICQDlg::OnMoving(UINT fwSide, LPRECT pRect) { if (rand()%2) { CRect r=*pRect; AdjustPos(&r); *pRect=(RECT)r; } else CDialog::OnMoving(fwSide,pRect); // TODO: Add your message handler code here } long CMICQDlg::OnOutbarNotify(WPARAM wParam, LPARAM lParam) { switch (wParam) { case NM_OB_ITEMCLICK: // cast the lParam to an integer to get the clicked item { int index = (int) lParam; CString cs, cs1; cs1 = wndBar.GetItemText(index); cs.Format("Clicked on %d - <%s>", (int)lParam, cs1); AfxMessageBox(cs); } return 0; case NM_OB_ONLABELENDEDIT: // cast the lParam to an OUTBAR_INFO * struct; it will contain info about the edited item // return 1 to do the change and 0 to cancel it { OUTBAR_INFO * pOI = (OUTBAR_INFO *) lParam; TRACE2("Editing item %d, new text:%s\n", pOI->index, pOI->cText); } return 1; case NM_OB_ONGROUPENDEDIT: // cast the lParam to an OUTBAR_INFO * struct; it will contain info about the edited folder // return 1 to do the change and 0 to cancel it { OUTBAR_INFO * pOI = (OUTBAR_INFO *) lParam; TRACE2("Editing folder %d, new text:%s\n", pOI->index, pOI->cText); } return 1; case NM_OB_DRAGITEM: // cast the lParam to an OUTBAR_INFO * struct; it will contain info about the dragged items // return 1 to do the change and 0 to cancel it { OUTBAR_INFO * pOI = (OUTBAR_INFO *) lParam; TRACE2("Drag item %d at position %d\n", pOI->iDragFrom, pOI->iDragTo); } return 1; } return 0; } struct FOpenInfo { CResizeCtrl * resize; CRect * rect; }; UINT CALLBACK CMICQDlg::HookProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { // subclassing is dont in the first WM_NOTIFY after CDN_INITDONE if( msg == WM_NOTIFY && lParam ) { OFNOTIFY * notify = (OFNOTIFY *)lParam; FOpenInfo * info = reinterpret_cast<FOpenInfo *>(notify->lpOFN->lCustData); // don't use CDN_INITDONE, because at this time // the listview is not created if( notify->hdr.code != CDN_INITDONE && info && info->resize == NULL ) { HWND hWndParent = ::GetParent( hWnd ); CResizeCtrl * resize = new CResizeCtrl( hWndParent ); // save object in lpOFN->lCustData info->resize = resize; // Find Toolbar, because its ID = IDOK HWND hWndToolBar = NULL; for( HWND hWndCtl = ::GetWindow(hWndParent, GW_CHILD); hWndToolBar == NULL && ::IsWindow( hWndCtl); hWndCtl = ::GetWindow( hWndCtl, GW_HWNDNEXT ) ) { char szBuf[ 64 ]; ::GetClassName( hWndCtl, szBuf, sizeof szBuf ); if( ::lstrcmpi( szBuf, TOOLBARCLASSNAME ) == 0 ) hWndToolBar = hWndCtl; } if( hWndToolBar ) // toolbar 1 resize->Add( hWndToolBar, 100, 0, 0, 0 ); // ComboBox resize->Add( 0x471, 0, 0, 100, 0 ); // ListView 461 resize->Add( 0x461, 0, 0, 100, 100 ); // Edit 480 resize->Add( 0x480, 0, 100, 100, 0 ); // ComboBox 470 resize->Add( 0x470, 0, 100, 100, 0 ); // Mit Schreibschutz 410 resize->Add( 0x410, 0, 100, 0, 0 ); // Dateiname 442 // DateiTyp 441 resize->Add( 0x441, 0, 100, 0, 0 ); resize->Add( 0x442, 0, 100, 0, 0 ); // 謋fnen 1 resize->Add( 1, 100, 100, 0, 0 ); resize->Add( 2, 100, 100, 0, 0 ); resize->SetMinimumTrackingSize(); resize->SetGripEnabled( TRUE ); // restore previous Position if( info->rect && info->rect->Width() > 0 && info->rect->Height() > 0 ) { ::MoveWindow( hWndParent, info->rect->left, info->rect->top, info->rect->Width(), info->rect->Height(), TRUE ); } } } return 0; } void CMICQDlg::OnMicq() { // TODO: Add your control notification handler code here //UpdateData(TRUE); QMenu ezmenu; CMenu menu; menu.LoadMenu(IDR_MENU_XICQ); ezmenu.Attach(menu.GetSubMenu(0)->GetSafeHmenu()); CBitmap bmp; bmp.LoadBitmap(IDB_MICQLEFT/*The title bitmap*/); ezmenu.SetTotalItems(11); ezmenu.SetMenuBitmap((HBITMAP)bmp.Detach()); ezmenu.SetBitmapDimension(CSize(20,230)); //ezmenu.SetLargeIcon(m_bLargeIcons); ezmenu.SetExtensionColor(RGB(10,10,10)); QMENUITEMDATA lpez[12]; for(int i=0;i<10;++i) { if (i%2) { lpez[i].SetItemIcon(IDR_SJ1); lpez[i].SetItemText("谢谢评论"); } else if (i%3) { lpez[i].SetItemIcon(IDR_SJ); lpez[i].SetItemText("请你光临"); } else { lpez[i].SetItemIcon(IDR_CHAT); lpez[i].SetItemText("我的免费之家"); } ezmenu.InsertOwnerDrawnMenuItem(ID_QMENU_ITEMS+i,&lpez[i]); } ezmenu.RemoveMenu(ID_MENU_TEMP,MF_BYCOMMAND); lpez[11].SetSeperator(TRUE); ezmenu.InsertOwnerDrawnMenuItem(ID_QMENU_ITEMS+11,&lpez[11],1); CRect rect; m_MicqBtn.GetWindowRect(&rect); CSize size=ezmenu.GetMenuSize(); ezmenu.TrackPopupMenu(TPM_RIGHTALIGN,rect.left+size.cx,rect.top-size.cy,this); // ezmenu.DestroyMenu(); } void CMICQDlg::OnMenu() { ShellExecute(NULL, _T("open"), "http://www.kl.gz.cn/~glb/", NULL,NULL, SW_SHOW); }