MSNDlg.cpp
资源名称:MSN.rar [点击查看]
上传用户:seeker_wen
上传日期:2016-05-23
资源大小:2084k
文件大小:12k
源码类别:
ICQ/即时通讯
开发平台:
Visual C++
- // MSNDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MSN.h"
- #include "MSNDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #include <mshtml.h>
- #include <comdef.h>
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}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)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMSNDlg dialog
- CMSNDlg::CMSNDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMSNDlg::IDD, pParent)
- {
- iShowButton = 0;
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CMSNDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMSNDlg)
- DDX_Control(pDX, 8001, m_MoveRight);
- DDX_Control(pDX, 8000, m_MoveLeft);
- DDX_Control(pDX, 14003, m_Search);
- DDX_Control(pDX, IDC_EXPLORER1, m_Browser);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMSNDlg, CDialog)
- //{{AFX_MSG_MAP(CMSNDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_SIZE()
- ON_WM_NCCREATE()
- ON_WM_SIZING()
- ON_BN_CLICKED(8000, On8000)
- ON_BN_CLICKED(8001, On8001)
- ON_WM_GETMINMAXINFO()
- ON_WM_NCHITTEST()
- ON_WM_NCLBUTTONDOWN()
- ON_BN_CLICKED(1200, On1200)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMSNDlg message handlers
- BOOL CMSNDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 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
- CRect rc;
- GetClientRect(rc);
- CButton *btn = (CButton*)GetDlgItem(888);
- btn->MoveWindow(7, 2, 60, 60);
- CRect rctic;
- m_Browser.GetClientRect(rctic);
- m_Browser.MoveWindow(12, rc.Height()-108, rc.Width()-22, 62);
- CWnd *tic = (CWnd*)GetDlgItem(IDC_EXPLORER1);
- tic = (CStatic*)GetDlgItem(1500);
- tic->MoveWindow(12, rc.Height()-130, 30,14);
- ///////////////////////////////////////////////////
- m_ILtabItem.Create(28, 28, ILC_MASK | ILC_COLOR32, 10, 10);
- CBitmap bmp;
- bmp.LoadBitmap(IDB_BITMAP2);
- ImageList_AddMasked(m_ILtabItem.m_hImageList, bmp, 0xff00ff);
- CTabCtrl *tab = (CTabCtrl *)GetDlgItem(IDC_TABITEM);
- tab->ModifyStyle(TCS_MULTILINE,0, 0);
- tab->SetImageList(&m_ILtabItem); // 设置图标链标
- ::SendMessage(tab->m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(36,31));
- tab->MoveWindow(CRect(0, 127-28, 31, rc.Height()-133));
- TCITEM tcItem = {0};
- tcItem.mask = TCIF_IMAGE;
- tcItem.pszText = "";
- tcItem.cchTextMax = 30;
- for(int i = 0; i <7; i++)
- {
- tab->InsertItem(0, "" );
- tcItem.iImage = i; // 图标索引
- tab->SetItem( 0, &tcItem);
- }
- userlist.Create(IDD_DIALOG1, this);
- userlist.ShowWindow(SW_NORMAL);
- userlist.MoveWindow(32, 127-28, rc.Width()-31, rc.Height()-233);
- //SetWindowNoSkinHwnd(userlist.m_hWnd, FALSE);
- SetDialogEraseBkgnd(userlist.m_hWnd);
- CRect rcEditArea(20,4,125,17);
- m_Search.SetEditArea(rcEditArea);
- CRect rcButtonArea(128,3,143,18);
- m_Search.SetButtonArea(rcButtonArea);
- m_Search.SetOwner(this);
- m_Search.SetButtonClickedMessageId(WM_USER_EDITBUTTON_CLICKED);
- m_Search.SetButtonExistsAlways(FALSE);
- m_Search.SetBitmaps("bitmap2.bmp", "bitmap2_e.bmp");
- m_Search.MoveWindow(7, rc.Height()-42, rc.Width()-11, 32);
- HitButton();
- VARIANT vInfo;
- vInfo.vt = VT_EMPTY;
- m_Browser.Navigate("http://rad.msn.com/ADSAdClient31.dll?GetAd=&PG=IMSCHI&AP=1007",&vInfo,&vInfo,&vInfo,&vInfo);
- m_Browser.SetVisible(TRUE);
- SetColorize(0xf832ff);
- return TRUE;
- }
- void CMSNDlg::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 CMSNDlg::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 CMSNDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CMSNDlg::OnSize(UINT nType, int cx, int cy)
- {
- CDialog::OnSize(nType, cx, cy);
- Invalidate();
- CButton *btn = (CButton*)GetDlgItem(6000);
- if (btn==NULL) {
- return;
- }
- btn->MoveWindow( 74, 11, cx - 26 - 74, 22);
- CTabCtrl *tab = (CTabCtrl *)GetDlgItem(IDC_TABITEM);
- tab->MoveWindow(CRect(0, 127-28, 31, cy-133));
- CEdit *edit = (CEdit*)GetDlgItem(14003);
- edit->MoveWindow(7, cy-42, cx-11, 32);
- CStatic *tic = (CStatic*)GetDlgItem(1500);
- tic->MoveWindow(12, cy-130, 30,14);
- userlist.MoveWindow(32, 127-28, cx-31, cy -233);
- CRect rctic;
- m_Browser.GetClientRect(rctic);
- if (cx-rctic.Width()<24) {
- m_Browser.MoveWindow(12, cy-108, cx-22, 62);
- }
- else
- {
- m_Browser.MoveWindow((cx-236)/2, cy-108, 236, 62);
- }
- HitButton();
- }
- BOOL CMSNDlg::OnNcCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (!CDialog::OnNcCreate(lpCreateStruct))
- return FALSE;
- SetWindowSkinResID(m_hWnd, 777);
- return TRUE;
- }
- BEGIN_EVENTSINK_MAP(CMSNDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CMSNDlg)
- ON_EVENT(CMSNDlg, IDC_EXPLORER1, 259 /* DocumentComplete */, OnDocumentCompleteExplorer1, VTS_DISPATCH VTS_PVARIANT)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
- void CMSNDlg::OnDocumentCompleteExplorer1(LPDISPATCH pDisp, VARIANT FAR* URL)
- {
- HRESULT hr = S_OK;
- IWebBrowser2* pWB = NULL;
- hr = pDisp->QueryInterface(IID_IWebBrowser2, reinterpret_cast<void**>(&pWB));
- IDispatch* pDocDisp = NULL;
- hr = pWB->get_Document(&pDocDisp);
- if(pDocDisp)
- {
- VARIANT v;
- VariantInit(&v);
- IHTMLDocument2* pDoc = NULL;
- hr = pDocDisp->QueryInterface(IID_IHTMLDocument2, reinterpret_cast<void**>(&pDoc));
- IHTMLElement* pElement = NULL;
- hr = pDoc->get_body(&pElement);
- IHTMLBodyElement* pBodyElement = NULL;
- hr = pElement->QueryInterface(IID_IHTMLBodyElement, (void**)&pBodyElement);
- if(pBodyElement)
- {
- pBodyElement->put_scroll(::SysAllocString(L"no"));
- _variant_t v;
- v.vt = VT_INT;
- v.intVal = 0;
- pBodyElement->put_leftMargin(v);
- pBodyElement->put_topMargin(v);
- pBodyElement->Release();
- }
- pElement->Release();
- pDoc->Release();
- pDocDisp->Release();
- }
- pWB->Release();
- }
- void CMSNDlg::OnSizing(UINT fwSide, LPRECT pRect)
- {
- CDialog::OnSizing(fwSide, pRect);
- //m_Browser.SetRedraw(false);
- }
- void CMSNDlg::HitButton()
- {
- //1201 -- 1204
- int iWidth = WIDTH1201 + WIDTH1202 + WIDTH1203 + WIDTH1204 + 2 * 3; //间距2
- CRect rc;
- GetClientRect(rc);
- m_MoveLeft.MoveWindow(9, 71, 12, 24);
- m_MoveRight.MoveWindow( rc.right-74-13, 71, 12, 24);
- //如果足够宽,左右按扭不显示
- if (rc.Width()-9-86>iWidth) {
- iShowButton = 0;
- CButton *btn = NULL;
- for(int i = 0; i <4; i++)
- {
- btn = (CButton*)GetDlgItem(1201 + i);
- btn->ShowWindow(SW_NORMAL);
- btn->MoveWindow(10+(26+2)*i, 99-28, 26, 24);
- }
- m_MoveLeft.ShowWindow(SW_HIDE);
- m_MoveRight.ShowWindow(SW_HIDE);
- }
- else if(rc.Width()-9-86 > WIDTH1201*3 + 2*3 + 12) //3 BUTTON + 1 LEFTRIGHT
- {
- //显示3个按扭1个左右
- CButton *btn = NULL;
- for(int i = 0; i < 3; i++)
- {
- btn = (CButton*)GetDlgItem(1201 + i + iShowButton);
- btn->ShowWindow(SW_NORMAL);
- btn->MoveWindow( (iShowButton==0?0:12+2) + 10+(26+2)*i, 99-28, 26, 24);
- btn->Invalidate();
- }
- if ( iShowButton ==0) {
- btn = (CButton*)GetDlgItem(1204);
- btn->ShowWindow(SW_HIDE);
- m_MoveRight.ShowWindow(SW_NORMAL);
- m_MoveLeft.ShowWindow(SW_HIDE);
- }
- else{
- btn = (CButton*)GetDlgItem(1201);
- btn->ShowWindow(SW_HIDE);
- m_MoveRight.ShowWindow(SW_HIDE);
- m_MoveLeft.ShowWindow(SW_NORMAL);
- }
- }
- else if(rc.Width()-9-86 > WIDTH1201*2 + 2*2 + 12)
- {
- //显示2个按扭2个左右
- CButton *btn = NULL;
- for(int i = 0; i < 4; i++)
- {
- btn = (CButton*)GetDlgItem(1201 + i);
- btn->ShowWindow(SW_HIDE);
- }
- for( i = 0; i < 2; i++)
- {
- if (iShowButton==3&&i==1) {
- break;
- }
- btn = (CButton*)GetDlgItem(1201 + i + iShowButton);
- btn->ShowWindow(SW_NORMAL);
- btn->MoveWindow( (iShowButton==0?0:12+2) + 10+(26+2)*i, 99-28, 26, 24);
- btn->Invalidate();
- }
- if ( iShowButton ==0) {
- m_MoveRight.ShowWindow(SW_NORMAL);
- m_MoveLeft.ShowWindow(SW_HIDE);
- }
- else if (iShowButton ==3) {
- m_MoveRight.ShowWindow(SW_HIDE);
- m_MoveLeft.ShowWindow(SW_NORMAL);
- }
- else
- {
- m_MoveRight.ShowWindow(SW_NORMAL);
- m_MoveLeft.ShowWindow(SW_NORMAL);
- }
- }
- else
- {
- //显示1个按扭2个左右
- //
- int c = (float)(rc.Width()-9-86 - 24+4) / (float)(WIDTH1201+2);
- CButton *btn = NULL;
- for(int i = 0; i < 4; i++)
- {
- btn = (CButton*)GetDlgItem(1201 + i);
- btn->ShowWindow(SW_HIDE);
- }
- for( i = 0; i < 1; i++)
- {
- btn = (CButton*)GetDlgItem(1201 + i + iShowButton);
- btn->ShowWindow(SW_NORMAL);
- btn->MoveWindow( (iShowButton==0?0:12+2) + 10+(26+2)*i, 99-28, 26, 24);
- btn->Invalidate();
- }
- if ( iShowButton ==0) {
- m_MoveRight.ShowWindow(SW_NORMAL);
- m_MoveLeft.ShowWindow(SW_HIDE);
- }
- else if (iShowButton ==3) {
- m_MoveRight.ShowWindow(SW_HIDE);
- m_MoveLeft.ShowWindow(SW_NORMAL);
- }
- else
- {
- m_MoveRight.ShowWindow(SW_NORMAL);
- m_MoveLeft.ShowWindow(SW_NORMAL);
- }
- }
- }
- void CMSNDlg::On8000()
- {
- //move left
- if (iShowButton>0) {
- iShowButton--;
- CButton *btn = NULL;
- for(int i = 0; i < 4; i++)
- {
- btn = (CButton*)GetDlgItem(1201 + i);
- btn->ShowWindow(SW_HIDE);
- }
- HitButton();
- }
- }
- void CMSNDlg::On8001()
- {
- //move right
- if (iShowButton<3) {
- iShowButton++;
- CButton *btn = NULL;
- for(int i = 0; i < 4; i++)
- {
- btn = (CButton*)GetDlgItem(1201 + i);
- btn->ShowWindow(SW_HIDE);
- }
- HitButton();
- }
- }
- BOOL CMSNDlg::PreTranslateMessage(MSG* pMsg)
- {
- if ((pMsg->message == WM_RBUTTONDOWN)||(pMsg->message == WM_RBUTTONDBLCLK)){
- return TRUE;
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- void CMSNDlg::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
- {
- // TODO: Add your message handler code here and/or call default
- lpMMI->ptMinTrackSize.x = 153;// m_MinSize为最小尺寸
- lpMMI->ptMinTrackSize.y = 302;// m_MinSize为最小尺寸
- CDialog::OnGetMinMaxInfo(lpMMI);
- }
- void CMSNDlg::On1200()
- {
- CAboutDlg dlg;
- dlg.DoModal();
- }