// SurveillanceDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Surveillance.h"
#include "SurveillanceDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//建一个图片类,加载资源设置窗体背影图片
CBitmap m_bmpBackground;
//---------------------------------------
CSurveillanceDlg::CSurveillanceDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSurveillanceDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSurveillanceDlg)
//}}AFX_DATA_INIT
}
void CSurveillanceDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSurveillanceDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSurveillanceDlg, CDialog)
//{{AFX_MSG_MAP(CSurveillanceDlg)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CSurveillanceDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE,
GetWindowLong(this->GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
//设置窗体透明---------------------------------------------------------
HINSTANCE hInst = LoadLibrary("User32.DLL");
if(hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL;
fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
if(fun)fun(this->GetSafeHwnd(),0,150,2);
FreeLibrary(hInst);
}
//------------------------------------------------------------------------
//任务栏中隐藏--------------------------------------------------
ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);
//--------------------------------------------------------------
//从资源中加载图片,以备设置窗体背景
m_bmpBackground.LoadBitmap(IDB_BITMAP1);
//----------------------------------------------------------------
//设置窗体至前--------------------------------------------------------------------
::SetWindowPos(AfxGetMainWnd()->m_hWnd,HWND_TOPMOST,0,0,36,36,SWP_NOMOVE/SWP_NOSIZE);
//--------------------------------------------------------------------------------------
return TRUE;
}
void CSurveillanceDlg::OnPaint()
{
//窗体加背景图片-----------------------------------
CPaintDC dc(this); //对话框的dc
CDC dcMem;
dcMem.CreateCompatibleDC(&dc); //创建与对话框dc兼容的内存dc
CRect rect;
GetClientRect(&rect);
BITMAP bitMap;
m_bmpBackground.GetBitmap(&bitMap);
CBitmap *pbmpOld=dcMem.SelectObject(&m_bmpBackground); //将背景位图选入内存dc中
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY); //将内存dc中的位图拉伸显示在对话框的dc中
//------------------------------------------------------
}
void CSurveillanceDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
//移动无边框窗体-------------------------------------------------
PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x,point.y));
//---------------------------------------------------------------
CDialog::OnLButtonDown(nFlags, point);
}
BOOL CSurveillanceDlg::PreTranslateMessage(MSG* pMsg)
{
//阻止接ESC键退出,及ATL+F4关闭--------------------------------------------------
TCHAR nchar=pMsg->wParam;
if (nchar==VK_F4)
return TRUE;
if(pMsg->message==WM_KEYDOWN && (nchar==VK_ESCAPE||nchar==VK_RETURN))
return TRUE;
else
return CDialog::PreTranslateMessage(pMsg);
//-------------------------------------------------------------------------------
}