PPExplorerDlg.cpp
上传用户:huashan618
上传日期:2013-03-26
资源大小:261k
文件大小:13k
源码类别:

浏览器

开发平台:

Visual C++

  1. // PPExplorerDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "PPExplorer.h"
  5. #include "PPExplorerDlg.h"
  6. #include ".ppexplorerdlg.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. CCustomTabCtrl g_explorer;
  11. CMyFrameWnd* g_frame;
  12. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  13. #define TITLE_BUTTON_DIV     4 //标题框按钮的间隔
  14. #define TITLE_BUTTON_WIDTH   24//标题框按钮的大小
  15. static UINT BASED_CODE indicators[] =
  16. {
  17. ID_INDICATOR_CORPINF,
  18. ID_INDICATOR_WEBPAGE,
  19. ID_INDICATOR_ONLINE
  20. };
  21. class CAboutDlg : public CDialog
  22. {
  23. public:
  24. CAboutDlg();
  25. // 对话框数据
  26. enum { IDD = IDD_ABOUTBOX };
  27. protected:
  28. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
  29. // 实现
  30. protected:
  31. DECLARE_MESSAGE_MAP()
  32. };
  33. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  34. {
  35. }
  36. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CDialog::DoDataExchange(pDX);
  39. }
  40. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  41. END_MESSAGE_MAP()
  42. // CPPExplorerDlg 对话框
  43. CPPExplorerDlg::CPPExplorerDlg(CWnd* pParent /*=NULL*/)
  44. : CDialog(CPPExplorerDlg::IDD, pParent)
  45. {
  46. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  47. m_status=TRUE;
  48. GdiplusStartupInput gplus;
  49. GdiplusStartup(&m_gtoken, &gplus, NULL);
  50. m_fmove=FALSE;
  51. m_fmin=FALSE;
  52. g_frame=NULL;
  53. }
  54. void CPPExplorerDlg::DoDataExchange(CDataExchange* pDX)
  55. {
  56. CDialog::DoDataExchange(pDX);
  57. DDX_Control(pDX, IDC_BUTT_THUMN, m_thumn);
  58. DDX_Control(pDX, IDC_BUT_CLOSE, m_butclose);
  59. DDX_Control(pDX, IDC_BUT_MAXWIN, m_butmax);
  60. DDX_Control(pDX, IDC_BUT_MINWIN, m_butmin);
  61. }
  62. BEGIN_MESSAGE_MAP(CPPExplorerDlg, CDialog)
  63. ON_WM_SYSCOMMAND()
  64. ON_WM_PAINT()
  65. ON_WM_QUERYDRAGICON()
  66. //}}AFX_MSG_MAP
  67. ON_BN_CLICKED(IDC_BUTT_THUMN, OnBnClickedButtThumn)
  68. ON_WM_DESTROY()
  69. ON_WM_MOUSEMOVE()
  70. ON_WM_LBUTTONDOWN()
  71. ON_WM_LBUTTONUP()
  72. ON_MESSAGE(WM_NOTIFY_MIN,OnNotifyRegion)
  73. ON_MESSAGE(WM_STATUS_MESSAGE,OnStatusBarMessage)
  74. ON_MESSAGE(WM_NEW_IEVIEW,OnCreateNewIEView)
  75. ON_BN_CLICKED(IDC_BUT_CLOSE, OnBnClickedButClose)
  76. ON_BN_CLICKED(IDC_BUT_MAXWIN, OnBnClickedButMaxwin)
  77. ON_BN_CLICKED(IDC_BUT_MINWIN, OnBnClickedButMinwin)
  78. END_MESSAGE_MAP()
  79. // CPPExplorerDlg 消息处理程序
  80. BOOL CPPExplorerDlg::OnInitDialog()
  81. {
  82. CDialog::OnInitDialog();
  83. // IDM_ABOUTBOX 必须在系统命令范围内。
  84. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  85. ASSERT(IDM_ABOUTBOX < 0xF000);
  86. CMenu* pSysMenu = GetSystemMenu(FALSE);
  87. if (pSysMenu != NULL)
  88. {
  89. CString strAboutMenu;
  90. strAboutMenu.LoadString(IDS_ABOUTBOX);
  91. if (!strAboutMenu.IsEmpty())
  92. {
  93. pSysMenu->AppendMenu(MF_SEPARATOR);
  94. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  95. }
  96. }
  97. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  98. //  执行此操作
  99. SetIcon(m_hIcon, TRUE); // 设置大图标
  100. SetIcon(m_hIcon, FALSE); // 设置小图标
  101.     //设置托图标
  102. NOTIFYICONDATA nc;
  103. nc.cbSize = sizeof(NOTIFYICONDATA);
  104. nc.hIcon = AfxGetApp()->LoadIcon(IDI_NOTIFY);
  105. nc.hWnd = m_hWnd;
  106. lstrcpy(nc.szTip,"PPExplorer");
  107. nc.uCallbackMessage =WM_NOTIFY_MIN;
  108. nc.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  109. nc.uID = IDC_NC;
  110. Shell_NotifyIcon(NIM_ADD, &nc);
  111. //处理窗口信息
  112. m_cxwnd=GetSystemMetrics(SM_CXFULLSCREEN);
  113. m_cywnd=GetSystemMetrics(SM_CYFULLSCREEN);
  114. //m_cxwnd=GetSystemMetrics(SM_CXSCREEN);
  115. //m_cywnd=GetSystemMetrics(SM_CYSCREEN);
  116.     MoveWindow(&CRect(0,0,m_cxwnd,m_cywnd));
  117. //初始化背景DC
  118. CDC* pDC=GetDC();
  119. m_maindc.CreateCompatibleDC(pDC);
  120. ReleaseDC(pDC);
  121. SetDlgSkin();
  122. InitialChildWindow();
  123. //重绘窗浏览窗口和广告窗口
  124. //先定出左窗口的大小
  125. int lwidth=int(m_cxwnd/3);
  126. m_left.SetRect(FROM_LEFT,MENU_FROM_TOP,FROM_LEFT+lwidth,m_cywnd-FROM_BOTTOM);
  127. m_adverse.Create(NULL,NULL,WS_VISIBLE|WS_CHILD|WS_BORDER,m_left,this,0);
  128. m_adverse.ShowWindow(SW_SHOW);
  129. m_adverse.MoveWindow(&m_left);
  130.   m_rthumn.SetRect(FROM_LEFT+lwidth+1,m_cywnd/2,FROM_LEFT+lwidth+THUMN_WIDTH-1,m_cywnd/2+THUMN_HEIGHT);
  131. m_thumn.MoveWindow(&m_rthumn);
  132. m_right.SetRect(FROM_LEFT+lwidth+THUMN_WIDTH,MENU_FROM_TOP+TOOL_HEIGHT,m_cxwnd-FROM_LEFT,m_cywnd-FROM_BOTTOM);
  133. g_explorer.Create(WS_CHILD|WS_VISIBLE,m_right,this,1);
  134. g_explorer.ModifyStyle(0,CTCS_TOOLTIPS,0);
  135. g_explorer.SetItemTooltipText(CTCID_PREVBUTTON,"向前翻一页");
  136. g_explorer.SetItemTooltipText(CTCID_NEXTBUTTON,"各后翻一页");
  137. g_explorer.ShowWindow(SW_SHOW);
  138. g_explorer.InsertItem(0,_T("about:blank"),RUNTIME_CLASS(CIEView));
  139. g_explorer.SetCurSel(0);
  140. //建立用于添加浮动工具栏的框架窗口
  141. g_frame=new CMyFrameWnd;
  142. if(!g_frame) return FALSE;
  143. g_frame->Create(NULL,NULL,WS_CHILD|WS_VISIBLE,CRect(FROM_LEFT+lwidth+THUMN_WIDTH,MENU_FROM_TOP,m_cxwnd-10,MENU_FROM_TOP+TOOL_HEIGHT),this,2);
  144. g_frame->ShowWindow(SW_SHOW);
  145. //添加状态栏
  146. m_statusbar.Create(this);//,WS_CHILD|WS_VISIBLE|WS_BORDER|CBRS_BOTTOM|CBRS_NOALIGN,AFX_IDW_STATUS_BAR+1);
  147. m_statusbar.SetIndicators(indicators,3);
  148. CRect rect;
  149. GetClientRect(&rect);
  150. m_statusbar.SetPaneInfo(0,ID_INDICATOR_CORPINF,SBPS_NORMAL,200);
  151. m_statusbar.SetPaneInfo(1,ID_INDICATOR_WEBPAGE,SBPS_NORMAL,140);
  152. m_statusbar.SetPaneInfo(2,ID_INDICATOR_ONLINE,SBPS_STRETCH ,200);
  153. m_statusbar.GetStatusBarCtrl().SetBkColor(RGB(192,218,255));
  154. m_statusbar.SetPaneText(0,_T("TeazleMoon软件"));
  155. m_statusbar.SetPaneText(1,_T("在线人数:0"));
  156. m_statusbar.SetPaneText(2,_T("打开网页信息显示"));
  157. RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,
  158.                                          ID_INDICATOR_WEBPAGE);
  159. return TRUE;  // 除非设置了控件的焦点,否则返回 TRUE
  160. }
  161. void CPPExplorerDlg::OnSysCommand(UINT nID, LPARAM lParam)
  162. {
  163. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  164. {
  165. CAboutDlg dlgAbout;
  166. dlgAbout.DoModal();
  167. }
  168. else
  169. {
  170. CDialog::OnSysCommand(nID, lParam);
  171. }
  172. }
  173. //接收托区发来的消息
  174. LRESULT CPPExplorerDlg::OnNotifyRegion(WPARAM wParam,LPARAM lParam)
  175. {
  176. if(lParam == WM_LBUTTONDBLCLK)
  177.       ShowWindow(SW_SHOW);
  178.   m_fmin=FALSE;
  179. return 1;
  180. }
  181. // 如果向对话框添加最小化按钮,则需要下面的代码
  182. //  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  183. //  这将由框架自动完成。
  184. void CPPExplorerDlg::OnPaint() 
  185. {
  186. CPaintDC dc(this); // 用于绘制的设备上下文
  187. if (IsIconic())
  188. {
  189.    SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  190. // 使图标在工作矩形中居中
  191. int cxIcon = GetSystemMetrics(SM_CXICON);
  192. int cyIcon = GetSystemMetrics(SM_CYICON);
  193. CRect rect;
  194. GetClientRect(&rect);
  195. int x = (rect.Width() - cxIcon + 1) / 2;
  196. int y = (rect.Height() - cyIcon + 1) / 2;
  197. // 绘制图标
  198. dc.DrawIcon(x, y, m_hIcon);
  199. }
  200. else
  201. {
  202. dc.BitBlt(0,0,m_cxwnd,m_cywnd,&m_maindc,0,0,SRCCOPY);
  203. g_frame->Invalidate();
  204. CDialog::OnPaint();
  205. }
  206. }
  207. //当用户拖动最小化窗口时系统调用此函数取得光标显示。
  208. HCURSOR CPPExplorerDlg::OnQueryDragIcon()
  209. {
  210. return static_cast<HCURSOR>(m_hIcon);
  211. }
  212. void CPPExplorerDlg::OnBnClickedButtThumn()
  213. {
  214. if(m_status)
  215. {
  216. ::MoveWindow(m_thumn.GetSafeHwnd(),0,m_cywnd/2,THUMN_WIDTH,THUMN_HEIGHT,TRUE);
  217. HWND hwnd=m_adverse.GetSafeHwnd();
  218. ::MoveWindow(hwnd,0,0,0,0,TRUE);
  219. ::EnableWindow(hwnd,FALSE);
  220. ::ShowWindow(hwnd,SW_HIDE);
  221.  g_explorer.ResetWindowSize(CRect(m_left.left,m_right.top,m_right.right,m_right.bottom));
  222. m_status=FALSE;
  223. }
  224. else
  225.    ::MoveWindow(m_adverse.GetSafeHwnd(),m_left.left,m_left.top,m_left.Width(),m_left.Height(),TRUE);
  226.    ::EnableWindow(m_adverse.GetSafeHwnd(),TRUE);
  227.    ::ShowWindow(m_adverse.GetSafeHwnd(),SW_SHOW);
  228.      g_explorer.ResetWindowSize(m_right);
  229.    ::MoveWindow(m_thumn.GetSafeHwnd(),m_rthumn.left,m_rthumn.top,m_rthumn.Width(),m_rthumn.Height(),TRUE);
  230.        m_status=TRUE;
  231. }
  232. }
  233. // 根据窗口大小制作皮肤,绘制标题栏
  234. void CPPExplorerDlg::SetDlgSkin(void)
  235. {
  236. CBitmap bitmap;
  237. CDC* pDC=GetDC();
  238. bitmap.CreateCompatibleBitmap(pDC,m_cxwnd,m_cywnd);
  239. CBitmap* pold=m_maindc.SelectObject(&bitmap);
  240. Graphics graph(m_maindc.m_hDC);
  241. //定义边框使用的画笔
  242. CPen pen(PS_SOLID,2,RGB(64,64,255));
  243. CPen* poldpen=m_maindc.SelectObject(&pen);
  244. //绘制窗口边框
  245. m_maindc.Rectangle(1,1,m_cxwnd-1,m_cywnd-1);
  246. //用GDI+填充整个窗口
  247. //Bitmap backbmp(LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BACKGROUND)),NULL);
  248. //TextureBrush backbrush(&backbmp);
  249. //graph.FillRectangle(&backbrush,Rect(2,TITLE_HEIGTH,m_cxwnd-4,m_cywnd-4));
  250. CFont font;
  251. font.CreatePointFont(324,_T("隶书"),&m_maindc);
  252. CFont* oldf=m_maindc.SelectObject(&font);
  253. m_maindc.SetTextColor(RGB(255,0,0));
  254.     m_maindc.SetBkMode(TRANSPARENT);
  255. m_maindc.TextOut(20,TITLE_HEIGTH+20,_T("VC制作,性能卓越"));
  256. LinearGradientBrush backbrush(Point(2,TITLE_HEIGTH),Point(2,m_cywnd-2),
  257.                             Color(128,64,128,64),Color(128,64,128,64));
  258. graph.FillRectangle(&backbrush,2,TITLE_HEIGTH,m_cxwnd-4,m_cywnd-4);
  259. //画标题栏边框
  260.     m_maindc.Rectangle(1,1,m_cxwnd-1,TITLE_HEIGTH);
  261. //用GDI+进行标题栏填充
  262. LinearGradientBrush titlebrush(Point(2,2),Point(2,TITLE_HEIGTH-2),
  263.                             Color(64,32,192,32),Color(192,32,254,32));
  264. graph.FillRectangle(&titlebrush,2,2,m_cxwnd-4,TITLE_HEIGTH-4);
  265. //CFont font;
  266. font.CreatePointFont(144,_T("隶书"),&m_maindc);
  267. oldf=m_maindc.SelectObject(&font);
  268. m_maindc.SetTextColor(RGB(128,0,255));
  269. m_maindc.TextOut(8,4,_T("PPExplorer"));
  270. m_maindc.SelectObject(oldf);
  271. m_maindc.SelectObject(pold);
  272. m_maindc.SelectObject(poldpen);
  273. font.DeleteObject();
  274. bitmap.DeleteObject();
  275. pen.DeleteObject();
  276. ReleaseDC(pDC);
  277. }
  278. // 回收所有已创对象
  279. void CPPExplorerDlg::ClearAllObject(void)
  280. {
  281. GdiplusShutdown(m_gtoken);
  282. NOTIFYICONDATA nc;
  283.     nc.cbSize = sizeof(NOTIFYICONDATA);
  284.     nc.hWnd = m_hWnd;
  285.     nc.uID = IDC_NC;
  286.     Shell_NotifyIcon(NIM_DELETE, &nc);
  287. }
  288. //窗口销除时
  289. void CPPExplorerDlg::OnDestroy()
  290. {
  291. CDialog::OnDestroy();
  292. g_frame->SendMessage(WM_DESTROY);
  293. m_statusbar.SendMessage(WM_DESTROY);
  294. ClearAllObject();
  295. }
  296. void CPPExplorerDlg::OnMouseMove(UINT nFlags, CPoint point)
  297. {
  298.  if(m_fmove && point.x>m_cxwnd)
  299. {
  300. int width=m_posfocus.Width();
  301. m_posfocus.left=point.x-m_start;//-m_posfocus.Width()/2;
  302. m_posfocus.right=m_posfocus.left+width;//point.x+m_posfocus.Width()/2;
  303.         m_oldfocus=m_posfocus;
  304. }
  305. CDialog::OnMouseMove(nFlags, point);
  306. }
  307. void CPPExplorerDlg::OnLButtonDown(UINT nFlags, CPoint point)
  308. {
  309. CDialog::OnLButtonDown(nFlags, point);
  310. if(point.x>m_posfocus.left && point.x<m_posfocus.right &&
  311.                  point.y>MENU_FROM_TOP && point.y<m_cywnd-FROM_BOTTOM)
  312. {
  313. m_start=point.x-m_posfocus.left;
  314.         this->SetCapture();
  315.     m_oldfocus=m_posfocus;
  316. m_fmove=TRUE;
  317.  }
  318. else
  319.   PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
  320. }
  321. void CPPExplorerDlg::OnLButtonUp(UINT nFlags, CPoint point)
  322. {
  323.    if(m_fmove)
  324.    {
  325.   CDC* pDC=GetDC();
  326.  ::ReleaseCapture(); 
  327.  int width=m_posfocus.Width();
  328.  m_fmove=FALSE;
  329.    }
  330. CDialog::OnLButtonUp(nFlags, point);
  331. }
  332. //LRESULT CPPExplorerDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  333. //{
  334. // switch(message)
  335. // {
  336. //   case WM_STATUS_MESSAGE://接收状态栏发生变化的消息
  337. // {
  338. //    LPCTSTR statusinf=(LPCTSTR)lParam;
  339. //    m_statusbar.SetPaneText(2,_T("statusinf"));
  340. // }
  341. //     break;
  342. //   default:
  343. //   break;
  344. // }
  345. // return CDialog::WindowProc(message, wParam, lParam);
  346. //}
  347. // 初始化子窗口
  348. void CPPExplorerDlg::InitialChildWindow(void)
  349. {
  350. //将窗口按钮置于标题框上
  351. int fromtop=4;
  352. CRect rect;
  353. rect.left=m_cxwnd-3*TITLE_BUTTON_WIDTH-2*TITLE_BUTTON_DIV-4;
  354. rect.top=fromtop;
  355. rect.right=rect.left+TITLE_BUTTON_WIDTH;
  356. rect.bottom=rect.top+TITLE_BUTTON_WIDTH;
  357. m_butmin.MoveWindow(&rect);
  358. rect.left=rect.right+TITLE_BUTTON_DIV;
  359. rect.right=rect.left+TITLE_BUTTON_WIDTH;
  360. m_butmax.MoveWindow(&rect);
  361. rect.left=rect.right+TITLE_BUTTON_DIV;
  362. rect.right=rect.left+TITLE_BUTTON_WIDTH;
  363. m_butclose.MoveWindow(&rect);
  364. }
  365. //关闭窗口
  366. void CPPExplorerDlg::OnBnClickedButClose()
  367. {
  368. CDialog::OnOK();
  369. }
  370. void CPPExplorerDlg::OnBnClickedButMaxwin()
  371. {
  372. // TODO: 在此添加控件通知处理程序代码
  373. /*if(m_nstat)
  374.    {
  375.      int cx=GetSystemMetrics(SM_CXSCREEN);
  376.      int cy=GetSystemMetrics(SM_CYSCREEN);
  377.      this->MoveWindow(&CRect(0,0,cx,cy));6
  378.  m_nstat=FALSE;
  379.    }
  380.    else
  381.    {
  382.   this->MoveWindow(&CRect(0,0,800,600));
  383.   this->CenterWindow();
  384.   m_nstat=TRUE;
  385. }*/
  386. }
  387. void CPPExplorerDlg::OnBnClickedButMinwin()
  388. {
  389.    if(m_fmin) return;
  390.    ShowWindow(FALSE);
  391.    m_fmin=TRUE;
  392. }
  393. LRESULT CPPExplorerDlg::OnStatusBarMessage(WPARAM wParam,LPARAM lParam)
  394. {
  395.   LPCTSTR statusinf=(LPCTSTR)lParam;
  396.   CString info;
  397.   info.Format("%sn",statusinf);
  398.   m_statusbar.SetPaneText(2,info);
  399.   return 1L;
  400. }
  401. //从CIEView中获得正在新建窗口的消息
  402. LRESULT CPPExplorerDlg::OnCreateNewIEView(WPARAM wParam,LPARAM lParam)
  403. {
  404. int index=g_explorer.GetItemCount();
  405. CWnd* pwnd=g_explorer.InsertItem(index,_T(""),RUNTIME_CLASS(CIEView));
  406. g_explorer.SetCurSel(index);
  407. if(pwnd==NULL) AfxMessageBox("返回的句柄为空!");
  408. return (LRESULT)pwnd;
  409. }