www.pudn.com > PhoneReaderSrc.rar > SmartBook.cpp


// SmartBook.cpp : Defines the entry point for the application. 
// 
 
#include "stdafx.h" 
 
#include "MainWnd.h" 
 
// Global variables 
CAppModule _Module; 
 
const TCHAR g_szApplicationTitle[] = _T("Phone Reader"); 
const TCHAR g_szUniqueString[] = _T("DmoQs3XbkUC6zFoS8lC/gQ=="); 
HWND g_hWndLast = NULL; 
// WinMain 
int WINAPI WinMain(HINSTANCE hInstance, 
                   HINSTANCE hPrevInstance, 
                   LPWSTR     lpCmdLine, 
                   int        CmdShow) 
{ 
	// Check if one instance is already running. 
	const HANDLE hMutex = ::CreateMutex(NULL, FALSE, g_szUniqueString); 
 
	if(NULL != hMutex) { 
		if(ERROR_ALREADY_EXISTS == ::GetLastError()) 
		{ 
			// This is not the first instance of the application. 
			// Activate the firsty instance and exit. 
			const HWND hWndExistingInstance = ::FindWindow(g_szUniqueString, NULL); 
//			VERIFY((NULL == hWndExistingInstance) || ::SetForegroundWindow(hWndExistingInstance)); 
			::SendMessage(hWndExistingInstance,WM_ACTIVATEPREINSTANCE,0,0); 
			return 0; 
		} 
 
		// Init common controls 
		// TODO: remove unused controls 
		INITCOMMONCONTROLSEX comctrex; 
		comctrex.dwSize = sizeof(comctrex); 
		comctrex.dwICC = ICC_UPDOWN_CLASS 
			| ICC_DATE_CLASSES		// date and time-picker control  
			| ICC_PROGRESS_CLASS	// progress bar control  
			| ICC_LISTVIEW_CLASSES  // list view and header control 
			| ICC_TREEVIEW_CLASSES;	// tree view control 
		::InitCommonControlsEx(&comctrex); 
 
		// Init module. 
		_Module.Init(NULL, hInstance); 
 
		// Create main window. 
		CMainWnd wnd; 
		RECT rc; 
		::SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0); 
		if(NULL == wnd.Create(NULL, rc, g_szApplicationTitle, WS_VISIBLE)) 
		{ 
			return 1; 
		} 
 
		// Run message loop. 
		CMessageLoop loop; 
		_Module.AddMessageLoop(&loop); 
		int nResult = loop.Run(); 
 
		// Terminate. 
		_Module.RemoveMessageLoop(); 
		_Module.Term(); 
 
		return nResult; 
	} 
 
	return 2; 
}