⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frontdlg.cpp

📁 一个多方面查询的系统,也是很辛苦找到,并且做管理系统很多方面都用到的
💻 CPP
字号:
// frontDlg.cpp : implementation file
//

#include "stdafx.h"
#include "front.h"
#include "frontDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


CDialog *GlobyFrontDlg;  //全局FrontDlg对话框指针,用于tray
extern CFrontApp theApp;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CFrontDlg dialog

CFrontDlg::CFrontDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFrontDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFrontDlg)
		// 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 CFrontDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFrontDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFrontDlg, CDialog)
	//{{AFX_MSG_MAP(CFrontDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_ERASEBKGND()
	ON_WM_NCHITTEST()
	ON_WM_SHOWWINDOW()
	ON_WM_DESTROY()
	ON_WM_KEYDOWN()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
//END_MESSAGE_MAP()


ON_MESSAGE(WM_TASKBAR,OnTaskbar) //响应任务栏图标
	//{{AFX_MSG_MAP(CTrayDlg)

	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFrontDlg message handlers

BOOL CFrontDlg::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
	
	SetWindowText("前台");
	// TODO: Add extra initialization here
	IrregularWindow(); 

	WriteTray();

	GlobyFrontDlg=this;

	SetTimer(1,500,NULL);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFrontDlg::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 CFrontDlg::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 CFrontDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

BOOL CFrontDlg::OnEraseBkgnd(CDC* pDC) 
{
	CRect rc;
	GetClientRect(&rc);
	//使用系统默认字体
	CFont * of = pDC->SelectObject(CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT)));
	//所画东西不改变背景色
	int obk = pDC->SetBkMode(TRANSPARENT);
	//背景色
	CBrush *pOldBrush,brush;
	brush.CreateSolidBrush(GetSysColor(COLOR_BACKGROUND));
	pOldBrush = pDC->SelectObject(&brush);
	//画一个轮廓框
	rc.SetRect(rc.left+2,rc.top+2,rc.right,rc.bottom);
	pDC->RoundRect(rc,CPoint(17,17));


	//TODO,自己做



	//恢复
	pDC->SelectObject(pOldBrush);
	pDC->SelectObject(of);
	pDC->SelectObject(&obk);
	return true;
}




UINT CFrontDlg::OnNcHitTest(CPoint point) 
{
	UINT nHitTest = CDialog::OnNcHitTest(point); 

    return (nHitTest == HTCLIENT)? HTCAPTION:nHitTest;
}

void CFrontDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	
	// TODO: Add your message handler code here
	CRect rc;
	GetWindowRect(&rc);
	rc.right = rc.left + 188;
	rc.bottom = rc.top + 528;
	MoveWindow(&rc,TRUE);

	SetWindowPos(&wndTopMost,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);  //使窗口保持最前
}



void CFrontDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	delete m_wnd;
	delete TitleButton;

	//用NIM_DELETE删除图标
	Shell_NotifyIcon(NIM_DELETE, Tray);
	delete Tray;
}


void CFrontDlg::IrregularWindow()
{
	CRect cRect,rc;
	CDC* pDC;
	CDC	 memDC;
	CBitmap	cBitmap;
	CBitmap* pOldMemBmp = NULL;
	COLORREF col;
	int	x, y;
	CRgn wndRgn, rgnTemp;

	pDC = GetDC();
	GetWindowRect(&cRect);

	//将模板位图选进设备场景中
	cBitmap.LoadBitmap(IDB_BACK);
	memDC.CreateCompatibleDC(pDC);
	pOldMemBmp = memDC.SelectObject(&cBitmap);

	//创建模板形状的不规则区域
	wndRgn.CreateRectRgn(0, 0, cRect.Width(), cRect.Height());
	for(x=0; x<=cRect.Width(); x++)
	{
		for(y=0; y<=cRect.Height(); y++)
		{
			//将位图中黑色小圆洞对应的区域抠掉
			col = memDC.GetPixel(x, y);
			if(col == RGB(255,255,255))
			{
				rgnTemp.CreateRectRgn(x, y, x+1, y+1);
				wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_XOR);
				rgnTemp.DeleteObject();	
			}
		}
	}
	if (pOldMemBmp) memDC.SelectObject(pOldMemBmp);

	//将不规则区域分配给窗体,也就是创建不规则的窗体
	SetWindowRgn((HRGN)wndRgn, TRUE);
	ReleaseDC(pDC);



	//初始化绘图面板
	rc.SetRect(cRect.left,cRect.top+25,cRect.right,cRect.bottom);
	m_wnd=new CMyWnd;
	m_wnd->sSeverAddress.Format("%s",theApp.sServerAddr);
	m_wnd->Create(WS_CHILD|WS_VISIBLE, rc, this,IDC_MYWND,1);
	m_wnd->bIsOnline=theApp.bIsLogin;
	m_wnd->bFlush=true;
	m_wnd->SetOwner(this);
	
	rc.SetRect(cRect.left+3,cRect.top+3,cRect.left+80,cRect.top+25);
	TitleButton=new CMyButton;
	TitleButton->pParentWnd=m_wnd;
	TitleButton->Create(WS_CHILD|WS_VISIBLE, rc, this,IDC_TITLEBUTTON,0);
}

void CFrontDlg::WriteTray()
{
	Tray=new NOTIFYICONDATA;

	//图标句柄
	HICON hIcon;
	
	char lpszTip[] = "办公系统";
	
	HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_TRAY),RT_GROUP_ICON);
				
	hIcon = (HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_TRAY),IMAGE_ICON,32,32,LR_DEFAULTCOLOR);
    	
	//给NOTIFYICONDATA结构赋值
	Tray->cbSize = sizeof(NOTIFYICONDATA); 
    Tray->hWnd = m_hWnd; 
    Tray->uID = IDI_TRAY; 
    Tray->uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; 
    Tray->uCallbackMessage = WM_TASKBAR; //自定义消息
    Tray->hIcon = hIcon; 

	if (lpszTip) 
        lstrcpyn(Tray->szTip, lpszTip, sizeof(Tray->szTip)); 
    else 
        Tray->szTip[0] = '\0'; 

	
	//调用Shell_NotifyIcon函数通过NIM_ADD向任务栏写图标
	Shell_NotifyIcon(NIM_ADD,Tray); 
	
	//释放图标资源
	if (hIcon) 
        DestroyIcon(hIcon); 
}


//响应自定义消息
LRESULT	CFrontDlg::OnTaskbar(WPARAM wParam, LPARAM lParam)
{
	UINT uMouseMsg = (UINT) lParam;
		
	switch (uMouseMsg)

	{
		case WM_LBUTTONDOWN: 
			GlobyFrontDlg->ShowWindow(SW_RESTORE);
			break;

		default: break;

	}
		
	return 0;
}

 

void CFrontDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CFrontDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(theApp.bTrayChange&&theApp.iTrayChange==1)
	{
		//提供结构大小,窗口句柄和图标ID
		HICON hIcon;
		HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_TRAYCHANGE),RT_GROUP_ICON);
		hIcon = (HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_TRAYCHANGE),IMAGE_ICON,32,32,LR_DEFAULTCOLOR);
		Tray->uFlags=NIF_ICON;
		Tray->hIcon=hIcon;
	
		//用NIM_DELETE删除图标
		Shell_NotifyIcon(NIM_MODIFY, Tray);

		theApp.iTrayChange=-1;
	}
	else
	if(theApp.bTrayChange&&theApp.iTrayChange==-1)
	{
		//提供结构大小,窗口句柄和图标ID
		HICON hIcon;
		HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_TRAY),RT_GROUP_ICON);
		hIcon = (HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_TRAY),IMAGE_ICON,32,32,LR_DEFAULTCOLOR);
		Tray->uFlags=NIF_ICON;
		Tray->hIcon=hIcon;
	
		//用NIM_DELETE删除图标
		Shell_NotifyIcon(NIM_MODIFY, Tray);

		theApp.iTrayChange=1;
	}

	if(theApp.bTrayChange==false&&theApp.iTrayChange!=0)
	{
		//提供结构大小,窗口句柄和图标ID
		HICON hIcon;
		HINSTANCE hInst = AfxFindResourceHandle(MAKEINTRESOURCE(IDI_TRAY),RT_GROUP_ICON);
		hIcon = (HICON)LoadImage(hInst,MAKEINTRESOURCE(IDI_TRAY),IMAGE_ICON,32,32,LR_DEFAULTCOLOR);
		Tray->uFlags=NIF_ICON;
		Tray->hIcon=hIcon;
	
		//用NIM_DELETE删除图标
		Shell_NotifyIcon(NIM_MODIFY, Tray);

		theApp.iTrayChange=0;
	}
	
	CDialog::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -