PPExplorerDlg.cpp
上传用户:huashan618
上传日期:2013-03-26
资源大小:261k
文件大小:13k
- // PPExplorerDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "PPExplorer.h"
- #include "PPExplorerDlg.h"
- #include ".ppexplorerdlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- CCustomTabCtrl g_explorer;
- CMyFrameWnd* g_frame;
- // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
- #define TITLE_BUTTON_DIV 4 //标题框按钮的间隔
- #define TITLE_BUTTON_WIDTH 24//标题框按钮的大小
- static UINT BASED_CODE indicators[] =
- {
- ID_INDICATOR_CORPINF,
- ID_INDICATOR_WEBPAGE,
- ID_INDICATOR_ONLINE
- };
- 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()
- // CPPExplorerDlg 对话框
- CPPExplorerDlg::CPPExplorerDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CPPExplorerDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_status=TRUE;
- GdiplusStartupInput gplus;
- GdiplusStartup(&m_gtoken, &gplus, NULL);
- m_fmove=FALSE;
- m_fmin=FALSE;
- g_frame=NULL;
- }
- void CPPExplorerDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_BUTT_THUMN, m_thumn);
- DDX_Control(pDX, IDC_BUT_CLOSE, m_butclose);
- DDX_Control(pDX, IDC_BUT_MAXWIN, m_butmax);
- DDX_Control(pDX, IDC_BUT_MINWIN, m_butmin);
- }
- BEGIN_MESSAGE_MAP(CPPExplorerDlg, CDialog)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- ON_BN_CLICKED(IDC_BUTT_THUMN, OnBnClickedButtThumn)
- ON_WM_DESTROY()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_MESSAGE(WM_NOTIFY_MIN,OnNotifyRegion)
- ON_MESSAGE(WM_STATUS_MESSAGE,OnStatusBarMessage)
- ON_MESSAGE(WM_NEW_IEVIEW,OnCreateNewIEView)
- ON_BN_CLICKED(IDC_BUT_CLOSE, OnBnClickedButClose)
- ON_BN_CLICKED(IDC_BUT_MAXWIN, OnBnClickedButMaxwin)
- ON_BN_CLICKED(IDC_BUT_MINWIN, OnBnClickedButMinwin)
- END_MESSAGE_MAP()
- // CPPExplorerDlg 消息处理程序
- BOOL CPPExplorerDlg::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); // 设置小图标
- //设置托图标
- NOTIFYICONDATA nc;
- nc.cbSize = sizeof(NOTIFYICONDATA);
- nc.hIcon = AfxGetApp()->LoadIcon(IDI_NOTIFY);
- nc.hWnd = m_hWnd;
- lstrcpy(nc.szTip,"PPExplorer");
- nc.uCallbackMessage =WM_NOTIFY_MIN;
- nc.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
- nc.uID = IDC_NC;
- Shell_NotifyIcon(NIM_ADD, &nc);
- //处理窗口信息
- m_cxwnd=GetSystemMetrics(SM_CXFULLSCREEN);
- m_cywnd=GetSystemMetrics(SM_CYFULLSCREEN);
- //m_cxwnd=GetSystemMetrics(SM_CXSCREEN);
- //m_cywnd=GetSystemMetrics(SM_CYSCREEN);
- MoveWindow(&CRect(0,0,m_cxwnd,m_cywnd));
- //初始化背景DC
- CDC* pDC=GetDC();
- m_maindc.CreateCompatibleDC(pDC);
- ReleaseDC(pDC);
- SetDlgSkin();
- InitialChildWindow();
- //重绘窗浏览窗口和广告窗口
- //先定出左窗口的大小
- int lwidth=int(m_cxwnd/3);
- m_left.SetRect(FROM_LEFT,MENU_FROM_TOP,FROM_LEFT+lwidth,m_cywnd-FROM_BOTTOM);
- m_adverse.Create(NULL,NULL,WS_VISIBLE|WS_CHILD|WS_BORDER,m_left,this,0);
- m_adverse.ShowWindow(SW_SHOW);
- m_adverse.MoveWindow(&m_left);
- m_rthumn.SetRect(FROM_LEFT+lwidth+1,m_cywnd/2,FROM_LEFT+lwidth+THUMN_WIDTH-1,m_cywnd/2+THUMN_HEIGHT);
- m_thumn.MoveWindow(&m_rthumn);
- m_right.SetRect(FROM_LEFT+lwidth+THUMN_WIDTH,MENU_FROM_TOP+TOOL_HEIGHT,m_cxwnd-FROM_LEFT,m_cywnd-FROM_BOTTOM);
- g_explorer.Create(WS_CHILD|WS_VISIBLE,m_right,this,1);
- g_explorer.ModifyStyle(0,CTCS_TOOLTIPS,0);
- g_explorer.SetItemTooltipText(CTCID_PREVBUTTON,"向前翻一页");
- g_explorer.SetItemTooltipText(CTCID_NEXTBUTTON,"各后翻一页");
- g_explorer.ShowWindow(SW_SHOW);
- g_explorer.InsertItem(0,_T("about:blank"),RUNTIME_CLASS(CIEView));
- g_explorer.SetCurSel(0);
- //建立用于添加浮动工具栏的框架窗口
- g_frame=new CMyFrameWnd;
- if(!g_frame) return FALSE;
- 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);
- g_frame->ShowWindow(SW_SHOW);
- //添加状态栏
- m_statusbar.Create(this);//,WS_CHILD|WS_VISIBLE|WS_BORDER|CBRS_BOTTOM|CBRS_NOALIGN,AFX_IDW_STATUS_BAR+1);
- m_statusbar.SetIndicators(indicators,3);
- CRect rect;
- GetClientRect(&rect);
- m_statusbar.SetPaneInfo(0,ID_INDICATOR_CORPINF,SBPS_NORMAL,200);
- m_statusbar.SetPaneInfo(1,ID_INDICATOR_WEBPAGE,SBPS_NORMAL,140);
- m_statusbar.SetPaneInfo(2,ID_INDICATOR_ONLINE,SBPS_STRETCH ,200);
- m_statusbar.GetStatusBarCtrl().SetBkColor(RGB(192,218,255));
- m_statusbar.SetPaneText(0,_T("TeazleMoon软件"));
- m_statusbar.SetPaneText(1,_T("在线人数:0"));
- m_statusbar.SetPaneText(2,_T("打开网页信息显示"));
- RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,
- ID_INDICATOR_WEBPAGE);
- return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
- }
- void CPPExplorerDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- //接收托区发来的消息
- LRESULT CPPExplorerDlg::OnNotifyRegion(WPARAM wParam,LPARAM lParam)
- {
- if(lParam == WM_LBUTTONDBLCLK)
- ShowWindow(SW_SHOW);
- m_fmin=FALSE;
- return 1;
- }
- // 如果向对话框添加最小化按钮,则需要下面的代码
- // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
- // 这将由框架自动完成。
- void CPPExplorerDlg::OnPaint()
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- if (IsIconic())
- {
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(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
- {
- dc.BitBlt(0,0,m_cxwnd,m_cywnd,&m_maindc,0,0,SRCCOPY);
- g_frame->Invalidate();
- CDialog::OnPaint();
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标显示。
- HCURSOR CPPExplorerDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CPPExplorerDlg::OnBnClickedButtThumn()
- {
- if(m_status)
- {
- ::MoveWindow(m_thumn.GetSafeHwnd(),0,m_cywnd/2,THUMN_WIDTH,THUMN_HEIGHT,TRUE);
- HWND hwnd=m_adverse.GetSafeHwnd();
- ::MoveWindow(hwnd,0,0,0,0,TRUE);
- ::EnableWindow(hwnd,FALSE);
- ::ShowWindow(hwnd,SW_HIDE);
- g_explorer.ResetWindowSize(CRect(m_left.left,m_right.top,m_right.right,m_right.bottom));
- m_status=FALSE;
- }
- else
- {
- ::MoveWindow(m_adverse.GetSafeHwnd(),m_left.left,m_left.top,m_left.Width(),m_left.Height(),TRUE);
- ::EnableWindow(m_adverse.GetSafeHwnd(),TRUE);
- ::ShowWindow(m_adverse.GetSafeHwnd(),SW_SHOW);
- g_explorer.ResetWindowSize(m_right);
- ::MoveWindow(m_thumn.GetSafeHwnd(),m_rthumn.left,m_rthumn.top,m_rthumn.Width(),m_rthumn.Height(),TRUE);
- m_status=TRUE;
- }
- }
- // 根据窗口大小制作皮肤,绘制标题栏
- void CPPExplorerDlg::SetDlgSkin(void)
- {
- CBitmap bitmap;
- CDC* pDC=GetDC();
- bitmap.CreateCompatibleBitmap(pDC,m_cxwnd,m_cywnd);
- CBitmap* pold=m_maindc.SelectObject(&bitmap);
- Graphics graph(m_maindc.m_hDC);
- //定义边框使用的画笔
- CPen pen(PS_SOLID,2,RGB(64,64,255));
- CPen* poldpen=m_maindc.SelectObject(&pen);
- //绘制窗口边框
- m_maindc.Rectangle(1,1,m_cxwnd-1,m_cywnd-1);
- //用GDI+填充整个窗口
- //Bitmap backbmp(LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BACKGROUND)),NULL);
- //TextureBrush backbrush(&backbmp);
- //graph.FillRectangle(&backbrush,Rect(2,TITLE_HEIGTH,m_cxwnd-4,m_cywnd-4));
- CFont font;
- font.CreatePointFont(324,_T("隶书"),&m_maindc);
- CFont* oldf=m_maindc.SelectObject(&font);
- m_maindc.SetTextColor(RGB(255,0,0));
- m_maindc.SetBkMode(TRANSPARENT);
- m_maindc.TextOut(20,TITLE_HEIGTH+20,_T("VC制作,性能卓越"));
- LinearGradientBrush backbrush(Point(2,TITLE_HEIGTH),Point(2,m_cywnd-2),
- Color(128,64,128,64),Color(128,64,128,64));
- graph.FillRectangle(&backbrush,2,TITLE_HEIGTH,m_cxwnd-4,m_cywnd-4);
- //画标题栏边框
- m_maindc.Rectangle(1,1,m_cxwnd-1,TITLE_HEIGTH);
- //用GDI+进行标题栏填充
- LinearGradientBrush titlebrush(Point(2,2),Point(2,TITLE_HEIGTH-2),
- Color(64,32,192,32),Color(192,32,254,32));
- graph.FillRectangle(&titlebrush,2,2,m_cxwnd-4,TITLE_HEIGTH-4);
- //CFont font;
- font.CreatePointFont(144,_T("隶书"),&m_maindc);
- oldf=m_maindc.SelectObject(&font);
- m_maindc.SetTextColor(RGB(128,0,255));
- m_maindc.TextOut(8,4,_T("PPExplorer"));
- m_maindc.SelectObject(oldf);
- m_maindc.SelectObject(pold);
- m_maindc.SelectObject(poldpen);
- font.DeleteObject();
- bitmap.DeleteObject();
- pen.DeleteObject();
- ReleaseDC(pDC);
- }
- // 回收所有已创对象
- void CPPExplorerDlg::ClearAllObject(void)
- {
- GdiplusShutdown(m_gtoken);
- NOTIFYICONDATA nc;
- nc.cbSize = sizeof(NOTIFYICONDATA);
- nc.hWnd = m_hWnd;
- nc.uID = IDC_NC;
- Shell_NotifyIcon(NIM_DELETE, &nc);
- }
- //窗口销除时
- void CPPExplorerDlg::OnDestroy()
- {
- CDialog::OnDestroy();
- g_frame->SendMessage(WM_DESTROY);
- m_statusbar.SendMessage(WM_DESTROY);
- ClearAllObject();
- }
- void CPPExplorerDlg::OnMouseMove(UINT nFlags, CPoint point)
- {
- if(m_fmove && point.x>m_cxwnd)
- {
- int width=m_posfocus.Width();
- m_posfocus.left=point.x-m_start;//-m_posfocus.Width()/2;
- m_posfocus.right=m_posfocus.left+width;//point.x+m_posfocus.Width()/2;
- m_oldfocus=m_posfocus;
- }
- CDialog::OnMouseMove(nFlags, point);
- }
- void CPPExplorerDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
- CDialog::OnLButtonDown(nFlags, point);
- if(point.x>m_posfocus.left && point.x<m_posfocus.right &&
- point.y>MENU_FROM_TOP && point.y<m_cywnd-FROM_BOTTOM)
- {
- m_start=point.x-m_posfocus.left;
- this->SetCapture();
- m_oldfocus=m_posfocus;
- m_fmove=TRUE;
- }
- else
- PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
- }
- void CPPExplorerDlg::OnLButtonUp(UINT nFlags, CPoint point)
- {
- if(m_fmove)
- {
- CDC* pDC=GetDC();
- ::ReleaseCapture();
- int width=m_posfocus.Width();
- m_fmove=FALSE;
- }
- CDialog::OnLButtonUp(nFlags, point);
- }
- //LRESULT CPPExplorerDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- //{
- // switch(message)
- // {
- // case WM_STATUS_MESSAGE://接收状态栏发生变化的消息
- // {
- // LPCTSTR statusinf=(LPCTSTR)lParam;
- // m_statusbar.SetPaneText(2,_T("statusinf"));
- // }
- // break;
- // default:
- // break;
- // }
- // return CDialog::WindowProc(message, wParam, lParam);
- //}
- // 初始化子窗口
- void CPPExplorerDlg::InitialChildWindow(void)
- {
- //将窗口按钮置于标题框上
- int fromtop=4;
- CRect rect;
- rect.left=m_cxwnd-3*TITLE_BUTTON_WIDTH-2*TITLE_BUTTON_DIV-4;
- rect.top=fromtop;
- rect.right=rect.left+TITLE_BUTTON_WIDTH;
- rect.bottom=rect.top+TITLE_BUTTON_WIDTH;
- m_butmin.MoveWindow(&rect);
- rect.left=rect.right+TITLE_BUTTON_DIV;
- rect.right=rect.left+TITLE_BUTTON_WIDTH;
- m_butmax.MoveWindow(&rect);
- rect.left=rect.right+TITLE_BUTTON_DIV;
- rect.right=rect.left+TITLE_BUTTON_WIDTH;
- m_butclose.MoveWindow(&rect);
-
- }
- //关闭窗口
- void CPPExplorerDlg::OnBnClickedButClose()
- {
- CDialog::OnOK();
- }
- void CPPExplorerDlg::OnBnClickedButMaxwin()
- {
- // TODO: 在此添加控件通知处理程序代码
- /*if(m_nstat)
- {
- int cx=GetSystemMetrics(SM_CXSCREEN);
- int cy=GetSystemMetrics(SM_CYSCREEN);
- this->MoveWindow(&CRect(0,0,cx,cy));6
- m_nstat=FALSE;
- }
- else
- {
- this->MoveWindow(&CRect(0,0,800,600));
- this->CenterWindow();
- m_nstat=TRUE;
- }*/
- }
- void CPPExplorerDlg::OnBnClickedButMinwin()
- {
- if(m_fmin) return;
- ShowWindow(FALSE);
- m_fmin=TRUE;
- }
- LRESULT CPPExplorerDlg::OnStatusBarMessage(WPARAM wParam,LPARAM lParam)
- {
- LPCTSTR statusinf=(LPCTSTR)lParam;
- CString info;
- info.Format("%sn",statusinf);
- m_statusbar.SetPaneText(2,info);
- return 1L;
- }
- //从CIEView中获得正在新建窗口的消息
- LRESULT CPPExplorerDlg::OnCreateNewIEView(WPARAM wParam,LPARAM lParam)
- {
- int index=g_explorer.GetItemCount();
- CWnd* pwnd=g_explorer.InsertItem(index,_T(""),RUNTIME_CLASS(CIEView));
- g_explorer.SetCurSel(index);
- if(pwnd==NULL) AfxMessageBox("返回的句柄为空!");
- return (LRESULT)pwnd;
- }