www.pudn.com > PG20101.zip > Sample.cpp


// 
//	Application 
// 
//		Copyright (c) 2000-2001 Chihiro.SAKAMOTO (HyperWorks) 
// 
#include "StdAfx.h" 
#include "Sample.h" 
#include "resource.h" 
 
// 
// Application的物件個體(instance) 
// 
CSampleApp	theApp; 
 
// 
// 建構式 
// 
CSampleApp::CSampleApp() 
{ 
	hMutex = 0; 
} 
 
// 
// 解構式 
// 
CSampleApp::~CSampleApp() 
{ 
	if (hMutex) 
		::CloseHandle(hMutex); 
} 
 
// 
// Application 初始化 
// 
BOOL CSampleApp::InitInstance() 
{ 
	// 防止Application多重啟動 
	if ((hMutex = ::CreateMutex(NULL, FALSE, ApplicationName "_Running")) == NULL) 
		return FALSE; 
 
	DWORD	Ret = ::WaitForSingleObject(hMutex, 0); 
	if (Ret == WAIT_TIMEOUT || Ret == WAIT_FAILED) 
		return FALSE; 
 
	// 若不是全彩模式則不能啟動應用程式 
	HDC		dc = GetDC(0); 
	int		nbits = GetDeviceCaps(dc, BITSPIXEL); 
	ReleaseDC(0, dc); 
 
	if (nbits < 15) { 
		::MessageBox(0, "程式不能在256色以下執行。\n請更換顯示模式。", 
			ApplicationTitle, MB_ICONSTOP|MB_OK); 
		return FALSE; 
	} 
 
	// 產生主視窗MainWin 
	if (!MainWin.Create(this, ApplicationTitle, LoadMenu(IDC_APPMENU))) 
		return FALSE; 
 
	MainWnd = &MainWin; 
 
	return TRUE; 
}