dialogthread.cpp

来自「类似于文件浏览器的vc++应用程序,容易使用,能进行各种文件操作.」· C++ 代码 · 共 76 行

CPP
76
字号
// DialogThread.cpp : implementation file
//

#include "stdafx.h"
#include "FileDialogView.h"
#include "DialogThread.h"
#include "DialogFileView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDialogThread
HANDLE CDialogThread::g_hEventClosed = CreateEvent(NULL, TRUE, FALSE, NULL);;
HHOOK CDialogThread::g_hHook = NULL;
static long lThreads = 0;

IMPLEMENT_DYNCREATE(CDialogThread, CWinThread)

CDialogThread::CDialogThread()
{
	m_msgCur.wParam = 0;
	m_hWndParent = NULL;
	m_pAttachedView = NULL;
	m_nID = 0;
	InterlockedIncrement(&lThreads);
	m_hEventCreated = CreateEvent(NULL, TRUE, FALSE, NULL);
}

CDialogThread::~CDialogThread()
{
	CloseHandle(m_hEventCreated);
	if(m_pAttachedView)
		delete m_pAttachedView;
	if(0 == InterlockedDecrement(&lThreads))
		VERIFY(SetEvent(g_hEventClosed));
}

BOOL CDialogThread::InitInstance()
{
	g_hHook = SetWindowsHookEx(WH_KEYBOARD, 
						 reinterpret_cast<HOOKPROC>(CDialogThread::KeyBoardHook), 
						 NULL, GetCurrentThreadId());	

	CDialogFileView dlg(*this);
	dlg.DoModal();
	m_pMainWnd = NULL;
	return FALSE;
}

int CDialogThread::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	::UnhookWindowsHookEx(g_hHook);
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CDialogThread, CWinThread)
	//{{AFX_MSG_MAP(CDialogThread)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialogThread message handlers

UINT WINAPI CDialogThread::KeyBoardHook(int nCode, WPARAM wParam, LPARAM lParam)
{
	if (nCode >= 0 && wParam==VK_ESCAPE)
		return 1;
	return CallNextHookEx(g_hHook, nCode, wParam, lParam);
}

⌨️ 快捷键说明

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