【VC开源代码栏目提醒】:本文主要为网学会员提供ServiceDlg.cpp,希望对需要ServiceDlg.cpp网友有所帮助,学习一下!
// ServiceDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Service.h"
#include "ServiceDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const RSP_SIMPLE_SERVICE = 1;
/////////////////////////////////////////////////////////////////////////////
// CServiceDlg dialog
CServiceDlg::CServiceDlg(CWnd* pParent /*=NULL*/)
: CDialog(CServiceDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CServiceDlg)
// 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);
bShow = FALSE;
}
void CServiceDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CServiceDlg)
DDX_Control(pDX, IDC_LIST, m_ctrlList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CServiceDlg, CDialog)
//{{AFX_MSG_MAP(CServiceDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_MESSAGE(WM_HOTKEY, OnHotKey)
ON_LBN_KILLFOCUS(IDC_LIST, OnKillfocusList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CServiceDlg message handlers
BOOL CServiceDlg::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
handle = GetSafeHwnd();
UINT ALT = 1;
UINT CONTROL = 2;
UINT R = 82;
if(GlobalFindAtom("MyHotkey") == 0)
{
//注册全局热键Ctrl + Alt + R
id = GlobalAddAtom("MyHotkey");
RegisterHotKey(handle, id, CONTROL + ALT, R);
typedef DWORD (WINAPI *RSP)(DWORD dwProcessId,DWORD dwType);
HMODULE m_hKernel = ::GetModuleHandle("Kernel32.DLL");
RSP m_rsp = (RSP)::GetProcAddress(m_hKernel, "RegisterServiceProcess");
m_rsp(::GetCurrentProcessId(),1);
}
else
PostQuitMessage(0);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CServiceDlg::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();
}
if (bShow == FALSE)
ShowWindow(SW_HIDE);
if (bShow == TRUE)
ShowWindow(SW_SHOW);
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CServiceDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CServiceDlg::DestroyWindow()
{
UnregisterHotKey(handle, id);
GlobalDeleteAtom(id);
return CDialog::DestroyWindow();
}
void CServiceDlg::OnHotKey(WPARAM wParam, LPARAM lParam)
{
if (wParam == id)
{
m_ctrlList.AddString("Alt+Ctrl+R按下");
bShow = TRUE;
PostMessage(WM_PAINT, 0, 0);
}
}
void CServiceDlg::OnKillfocusList()
{
bShow = FALSE;
PostMessage(WM_PAINT, 0, 0);
}
上一篇:
Service.cpp
下一篇:
学术论文摘要的定义及写作基本要求