utility.cpp

来自「C++写的加密程序,可对文件进行加密.」· C++ 代码 · 共 72 行

CPP
72
字号
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///	This is the starting execution point, _tWinMain calls PreMessageLoop and from then on the execution goes to
///	MainDialog class constructor & WM_INITDIALOG message processing (OnInitDialog method).
///	The Application is Using ATL (Active Template Library) only for easy Dialog/UI implementation.
///	The linkage with ATL library is disabled - The ONLY usage of ATL is the macro version of 
///	the WinProc (check MainDialog.h)
///	I hope that the usage of ATL does the code clearer and not the other way arround :)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MainDialog.h"

class CUtilityModule : public CAtlExeModuleT<CUtilityModule>
{
public :
	CUtilityModule() : _mainDialog(0)
	{
		_cmdLine[0] = 0;
	}

	~CUtilityModule()
	{
		delete _mainDialog;
	}

	/* WinMain Actual starting Point. */
	HRESULT PreMessageLoop(int nShowCmd) throw()
	{
		::InitCommonControls();

		_mainDialog = new MainDialog();

		// Checking for memory allocation error.
		if (_mainDialog == NULL)
		{
			__super::PostMessageLoop();
			return E_OUTOFMEMORY;
		}

		_mainDialog->Create(NULL);
		_mainDialog->ShowWindow(nShowCmd);
		_mainDialog->UpdateWindow();
		_mainDialog->updateUI(_cmdLine);

		// Message Processing.
		MSG msg;
		while (GetMessage(&msg, NULL, 0, 0)) 
		{
			// *_mainDialog = MainDialog Dialog Handle (hWnd).
			if (!IsDialogMessage(*_mainDialog, &msg))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}

		return __super::PreMessageLoop(nShowCmd);
	}

	void setCmdLine(char *cmdLine)	{ strcpy(_cmdLine, cmdLine); }
	char *getCmdLine()				{ return _cmdLine; }
private:
	MainDialog *_mainDialog;
	char _cmdLine[MAX_PATH];
};

CUtilityModule _AtlModule;

extern "C" int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR cmdLine, int nShowCmd)
{
	_AtlModule.setCmdLine(cmdLine);
	return _AtlModule.WinMain(nShowCmd);
}

⌨️ 快捷键说明

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