100個vc小項目開發:一、仿qq主介面

來源:互聯網
上載者:User

100個vc小項目開發:一、仿qq主介面

作者 July

------------------

一、我是來兌現承諾的。在之前的一篇博文中,已說過,

整理完那微軟等面試題系列V0.1版,便把那100套vc項目的源碼給放出來。現在,正是時機。

二、有問題,望各位不吝指正。:D。

-------------------------- 

 

我看,之前,已經有不少人做過這個仿qq的介面了。因此,本文會盡量保持簡短。

來看下,最後的(介面粗糙之處,還請海涵):

             

====

呵呵,沒錯,我的qq頭像是手塚。我和我老弟,都很喜歡這部網球王子。

由於沒有qq2010的皮膚庫,所以盜用了qq2008的皮膚。:D。

-------------------------------------------------------------------------------

 

一、MyICQApp檔案裡頭,對話方塊的建立:

CMyICQDlg dlg;
 m_pMainWnd = &dlg;
 int nResponse = dlg.DoModal();
 if (nResponse == IDOK)
 {
  // TODO: Place code here to handle when the dialog is
  //  dismissed with OK
 }
 else if (nResponse == IDCANCEL)
 {
  // TODO: Place code here to handle when the dialog is
  //  dismissed with Cancel
 }

 // Since the dialog has been closed, return FALSE so that we exit the
 //  application, rather than start the application's message pump.
 return FALSE;

 

二、介面主對話方塊的初始化:

BOOL CMyICQDlg::OnInitDialog()
{
 CDialog::OnInitDialog();

 // 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

 //1.畫主介面,關閉、放大、縮小等,qq頭像,功能表按鈕,顯示狀態,郵件等按鈕。

 //關鍵字:SetBmp
 CRect rc;GetClientRect(&rc);

 //Close Btn
 btnClose.Create(NULL,WS_VISIBLE|WS_CHILD,CRect(rc.right-35,0,rc.right-5,19),this,DE_WM_CLOSE);
 btnClose.SetBmp(IDB_BIT_CLOSE_NORMAL,IDB_BIT_CLOSE_HOVER,IDB_BIT_CLOSE_HDOWN,NULL);
 //Cro Btn
 btnCro.Create(NULL,WS_VISIBLE|WS_CHILD,CRect(rc.right-66,0,rc.right-36,19),this,DE_WM_CRO);
 btnCro.SetBmp(IDB_BIT_CRO_NORMAL,IDB_BIT_CRO_HOVER,IDB_BIT_CRO_HDOWN,NULL);
 //Min Btn
 btnMin.Create(NULL,WS_VISIBLE|WS_CHILD,CRect(rc.right-97,0,rc.right-67,19),this,DE_WM_MIN);

 btnMin.SetBmp(IDB_BIT_MIN_NORMAL,IDB_BIT_MIN_HOVER,IDB_BIT_MIN_HDOWN,NULL);

 //Head Btn
 btnHead.Create(NULL,WS_VISIBLE|WS_CHILD,CRect(4,37,51,77),this,DE_WM_HEAD);
 btnHead.SetBmp(IDB_BIT_HEAD,IDB_BIT_HEAD,IDB_BIT_HEAD,NULL);

 //Menu Btn
 btnMenu.Create(NULL,WS_VISIBLE|WS_CHILD,CRect(0,rc.bottom-34,54,rc.bottom),this,DE_WM_MENU);
 btnMenu.SetBmp(IDB_BIT_MENU_NORMAL,IDB_BIT_MENU_HOVER,IDB_BIT_MENU_HDOWN,NULL);

 btnState.Create("隱藏",WS_VISIBLE|WS_CHILD,CRect(70,50,115,70),this,DE_WM_STATE);
 btnState.SetIcon(IDI_STATE,16);

   btnMail.Create("(0)",WS_VISIBLE|WS_CHILD,CRect(125,50,165,70),this,DE_WM_MAIL);
   btnMail.SetIcon(IDI_MAIL,16);
 
 
 //2.畫底部的按鈕,手機,qq音樂,寵物,qq空間

 //關鍵字:SetIcon
 btnMobile.Create(NULL,WS_VISIBLE|WS_CHILD,CRect(30,rc.bottom-55,50,rc.bottom-35),this,DE_WM_MOBILE);
 btnMobile.SetIcon(IDI_MOBILE,16);

 btnMusic.Create(NULL,WS_VISIBLE|WS_CHILD,CRect(55,rc.bottom-55,75,rc.bottom-35),this,DE_WM_MUSIC);
 btnMusic.SetIcon(IDI_MUSIC,16);

 btnPet.Create(NULL,WS_VISIBLE|WS_CHILD,CRect(80,rc.bottom-55,100,rc.bottom-35),this,DE_WM_PET);
 btnPet.SetIcon(IDI_PET,16);

 btnResearch.Create(NULL,WS_VISIBLE|WS_CHILD,CRect(105,rc.bottom-55,125,rc.bottom-35),this,DE_WM_RESEARCH);
 btnResearch.SetIcon(IDI_RESEARCH,16);

 btnZone.Create(NULL,WS_VISIBLE|WS_CHILD,CRect(130,rc.bottom-55,150,rc.bottom-35),this,DE_WM_ZONE);
 btnZone.SetIcon(IDI_ZONE,16);

  CRect rcFolderCtrl;rcFolderCtrl.SetRect(rc.left+35,rc.top+89,rc.right-4,rc.bottom-68);

 

 //3.畫連絡人分組,我的好友,我的同學之類的
 CGfxOutBarCtrl *gfx=new CGfxOutBarCtrl;
 DWORD dwf = CGfxOutBarCtrl::fDragItems|CGfxOutBarCtrl::fEditGroups|CGfxOutBarCtrl::fEditItems|CGfxOutBarCtrl::fRemoveGroups|
  CGfxOutBarCtrl::fRemoveItems|CGfxOutBarCtrl::fAddGroups|CGfxOutBarCtrl::fAnimation
  |CGfxOutBarCtrl::fSelHighlight;
 gfx->Create(WS_VISIBLE|WS_CHILD,rcFolderCtrl,this,111111,dwf);
 gfx->AddFolder("一生好友",0);
 gfx->AddFolder("如今同學",1);
 gfx->AddFolder("親人姐弟",2);
 gfx->AddFolder("大學老師",3);
 gfx->AddFolder("東華志友",4);
 gfx->AddFolder("Csdn小組",5);
 gfx->AddFolder("100題討論",6);
 
//  gfx->InsertItem(0,0,"劉若英",0,0);
//  gfx->InsertItem(0,1,"001",0,0);
//  gfx->InsertItem(0,1,"002",0,0);

 CInternet *net=new CInternet;
 net->Create(NULL,NULL,WS_CHILD|WS_VISIBLE,rcFolderCtrl,this,22222222);
 net->ShowWindow(SW_HIDE);

 //4.畫主介面左邊的拍拍,線上電影,之類的。
///Tab

 //關鍵字:SetIcon
 tabMem.Create(NULL,WS_CHILD|WS_VISIBLE,CRect(0,90,35,300),this,DE_WM_MEM);
// tabMem.AddTabItem(IDB_BIT_TAB_NORMAL,IDB_BIT_TAB_HOVER,IDB_BIT_TAB_HOVER,IDI_PAI,NULL);
 tabMem.SetBmp(IDB_BIT_TAB_NORMAL,IDB_BIT_TAB_HOVER,IDB_BIT_TAB_HDOWN);
 tabMem.SetIcon(0,IDI_PAI,gfx);
 tabMem.SetIcon(1,IDI_IT,net);
 tabMem.SetIcon(2,IDI_ONE,NULL);
 tabMem.SetIcon(3,IDI_HEART,NULL);
 tabMem.SetIcon(4,IDI_ONLINE,NULL);
 tabMem.m_iCurrentSelect=0;
// tabMem.SetIcon(IDI_PAI,NULL);

//  CRect rect;GetClientRect(&rect);
//  CMainTabCtrl *pTab=new CMainTabCtrl;
//  pTab->Create(WS_VISIBLE|WS_CHILD,rect,this,10000);

 
//  CFolderCtrl *pFolder=new CFolderCtrl;
//  pFolder->Create(WS_VISIBLE|WS_CHILD,rect,pTab,20000);
//  CFolderCtrl *pFolder=new CFolderCtrl;
//  pFolder->Create(WS_VISIBLE|WS_CHILD,CRect(0,0,64,69),this,DE_WM_CLOSE);
 return TRUE;  // return TRUE  unless you set the focus to a control
}

 

三、畫頂角、中心段等處。

 //關鍵字:CBitmap

void CMyICQDlg::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
 {
  CPaintDC dc(this);
  CRect rc;GetClientRect(&rc);
  //rc.InflateRect(CSize(2,12));
  CDC memDC;memDC.CreateCompatibleDC(&dc);
  CBitmap bit;bit.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());
  CBitmap *OldBmp = memDC.SelectObject(&bit);
  memDC.DrawEdge(rc,EDGE_SUNKEN,0);

  //-------Title1
  //Title1 Left
  CBitmap bmpTitle1Left;bmpTitle1Left.LoadBitmap(IDB_BIT_TITLE1_LEFT);
  DrawBmpByPoint(&memDC,bmpTitle1Left,CPoint(0,0));
  //Title1 Mid
  CBitmap bmpTitle1Mid;bmpTitle1Mid.LoadBitmap(IDB_BIT_TITLE1_MID);
  DrawBmpByCRect(&memDC,bmpTitle1Mid,CRect(64,0,rc.right-79,22));
  //Title1 Right
  CBitmap bmpTitle1Right;bmpTitle1Right.LoadBitmap(IDB_BIT_TITLE1_RIGHT);
  DrawBmpByPoint(&memDC,bmpTitle1Right,CPoint(rc.right-79,0));
  
  //-------Title2
  //Title2 Left
  CBitmap bmpTitle2Left;bmpTitle2Left.LoadBitmap(IDB_BIT_TITLE2_LEFT);
  DrawBmpByPoint(&memDC,bmpTitle2Left,CPoint(0,22));
  //Title2 Mid
  CBitmap bmpTitle2Mid;bmpTitle2Mid.LoadBitmap(IDB_BIT_TITLE2_MID);
  DrawBmpByCRect(&memDC,bmpTitle2Mid,CRect(63,22,rc.right-115,67));
  //Title2 Right
  CBitmap bmpTitle2Right;bmpTitle2Right.LoadBitmap(IDB_BIT_TITLE2_RIGHT);
  DrawBmpByPoint(&memDC,bmpTitle2Right,CPoint(rc.right-115,22));
  
  //-------Center
   //Center Left
  CBitmap bmpCenterLeft;bmpCenterLeft.LoadBitmap(IDB_BIT_CENTER_LEFT);
  DrawBmpByCRect(&memDC,bmpCenterLeft,CRect(0,89,35,rc.bottom-68));
  //Center Right
   CBitmap bmpCenterRight;bmpCenterRight.LoadBitmap(IDB_BIT_CENTER_RIGHT);
   DrawBmpByCRect(&memDC,bmpCenterRight,CRect(rc.right-4,89,rc.right,rc.bottom-68));

  //-------Bottom
  //Bottom Left
  CBitmap bmpBottomLeft;bmpBottomLeft.LoadBitmap(IDB_BIT_BOTTON_LEFT);
  DrawBmpByPoint(&memDC,bmpBottomLeft,CPoint(0,rc.bottom-68));
  //Bottom Mid
  CBitmap bmpBottomMid;bmpBottomMid.LoadBitmap(IDB_BIT_BOTTOM_MID);
  DrawBmpByCRect(&memDC,bmpBottomMid,CRect(73,rc.bottom-68,rc.right-68,rc.bottom));
  //Bottom Right
  CBitmap bmpBottomRight;bmpBottomRight.LoadBitmap(IDB_BIT_BOTTOM_RIGHT);
  DrawBmpByPoint(&memDC,bmpBottomRight,CPoint(rc.right-68,rc.bottom-68));

  //BitBlt
  dc.BitBlt(0,0,rc.Width(),rc.Height(),&memDC,0,0,SRCCOPY);
  //
  CDialog::OnPaint();
 }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMyICQDlg::OnQueryDragIcon()
{
 return (HCURSOR) m_hIcon;
}

//Change Client-Msg To Caption-Msg
UINT CMyICQDlg::OnNcHitTest(CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 
 UINT nHitTest = CDialog::OnNcHitTest(point);

 if(nHitTest==HTCLIENT)
  nHitTest=HTCAPTION;
 return nHitTest;
}

//Set Bmp by Point
void CMyICQDlg::DrawBmpByPoint(CDC *pDC, CBitmap &mainBmp, const CPoint &pt)
{
 CDC tmpDC;tmpDC.CreateCompatibleDC(pDC);
 BITMAP tmpBmp;
 mainBmp.GetBitmap(&tmpBmp);
 
 CBitmap *oldBmp = tmpDC.SelectObject(&mainBmp);

 pDC->BitBlt(pt.x,pt.y,tmpBmp.bmWidth,tmpBmp.bmHeight,&tmpDC,0,0,SRCCOPY);
 
 tmpDC.SelectObject(&oldBmp);
 oldBmp->DeleteObject();
}

//Set Bmp By CRect
void CMyICQDlg::DrawBmpByCRect(CDC *pDC, CBitmap &bitRect, CRect &rect)
{
 CDC tmpDC;tmpDC.CreateCompatibleDC(pDC);
 BITMAP tmpBmp;
 bitRect.GetBitmap(&tmpBmp);

 CBitmap *oldBmp = tmpDC.SelectObject(&bitRect);

 for(int y=rect.top;y<rect.bottom;y+=tmpBmp.bmHeight)
 {
  for(int x=rect.left;x<rect.right;x+=tmpBmp.bmWidth)
  {
   pDC->BitBlt(x,y,tmpBmp.bmWidth,tmpBmp.bmHeight,&tmpDC,0,0,SRCCOPY);
  }
 }
 tmpDC.SelectObject(&oldBmp);
 oldBmp->DeleteObject();
}

//關閉
void CMyICQDlg::OnDeClose()
{
 exit(0);
}

//最小化

void CMyICQDlg::Min()
{
 ShowWindow(SW_MINIMIZE);
}

-------------------

完。July、二零一零年十二月二十二日。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.