www.pudn.com > DmyNP_source.rar > Initialize.c, change:2004-12-02,size:2729b


/*--> 
Damayi Net-Phone, 2004/11 (damayi.org) 
<--*/ 
 
#include "src\winmain.h" 
 
//创建标准字体 
//返回: 成功返回字体句柄, 失败返回NULL。 
static HFONT CreateGuiFont(void) 
{ 
   LOGFONT lf = {0}; 
   lf.lfHeight = 12; 
   lf.lfWeight = FW_DONTCARE; 
   lf.lfCharSet = GB2312_CHARSET; 
   CopyMemory(lf.lfFaceName, "宋体", 4); 
   return CreateFontIndirect(&lf); 
} 
 
//创建设备字体 
//返回: 成功返回字体句柄, 失败返回NULL。 
static HFONT CreateDevFont(void) 
{ 
   LOGFONT lf = {0}; 
   lf.lfHeight = 15; 
   lf.lfWeight = FW_DONTCARE; 
   lf.lfCharSet = DEFAULT_CHARSET; 
   CopyMemory(lf.lfFaceName, "Verdana", 7); 
   return CreateFontIndirect(&lf); 
} 
 
//加载资源数据 
//参数: 资源名 
//返回: 成功返回数据块地址, 失败返回NULL。 
static void * LoadRes(char const * const ps) 
{ 
   HRSRC hSrc; 
   HGLOBAL hRes; 
   hSrc = FindResource(g_hInst, ps, RT_RCDATA); 
   if(hSrc==NULL) return NULL; 
   hRes = LoadResource(g_hInst, hSrc); 
   if(hRes==NULL) return NULL; 
   return LockResource(hRes); 
} 
 
//初始化处理过程 
//返回: 成功返回0, 失败返回-1。 
//备注: 该过程分配全局资源对象, 并读取INI文件数据。 
int Initialize(void) 
{ 
   WSADATA stWsaData; 
 
   g_SO.iWSAStar = -1; 
   g_GJ.hMemDC = CreateCompatibleDC(0); 
   g_GJ.hGuiFont = CreateGuiFont(); 
   g_GJ.hDevFont = CreateDevFont(); 
   g_GJ.hIconB = LoadIcon(g_hInst, "Icon2"); 
   g_GJ.hIconS = LoadIcon(g_hInst, "Icon4"); 
   g_GJ.pPBusy = LoadRes("PBusy"); 
   g_GJ.pPNull = LoadRes("PNull"); 
   g_GJ.pPOver = LoadRes("POver"); 
   g_GJ.pPRefu = LoadRes("PRefu"); 
   g_GJ.pPWelc = LoadRes("PWelc"); 
   g_GJ.pSBack = LoadRes("SBack"); 
   g_GJ.pSErr  = LoadRes("SErr"); 
   g_GJ.pSHang = LoadRes("SHang"); 
   g_GJ.pSRing = LoadRes("SRing"); 
   g_GJ.pSTck  = LoadRes("STck"); 
   g_GJ.pSWarn = LoadRes("SWarn"); 
 
   if(g_GJ.hMemDC==NULL) goto initError; 
   if(g_GJ.hGuiFont==NULL) goto initError; 
   if(g_GJ.hDevFont==NULL) goto initError; 
   if(g_GJ.hIconB==NULL) goto initError; 
   if(g_GJ.hIconS==NULL) goto initError; 
   if(g_GJ.pPBusy==NULL) goto initError; 
   if(g_GJ.pPNull==NULL) goto initError; 
   if(g_GJ.pPOver==NULL) goto initError; 
   if(g_GJ.pPRefu==NULL) goto initError; 
   if(g_GJ.pPWelc==NULL) goto initError; 
   if(g_GJ.pSBack==NULL) goto initError; 
   if(g_GJ.pSErr==NULL)  goto initError; 
   if(g_GJ.pSHang==NULL) goto initError; 
   if(g_GJ.pSRing==NULL) goto initError; 
   if(g_GJ.pSTck==NULL)  goto initError; 
   if(g_GJ.pSWarn==NULL) goto initError; 
 
   g_SO.bAvaiINI = ReadIniFile(&g_IV); 
   if(!g_SO.bAvaiINI) SetDefaultInivar(&g_IV); 
   if(WSAStartup(0x101, &stWsaData)!=0) goto initError; 
   g_SO.iWSAStar = 0; 
   return 0; 
 
   initError: 
      PromptError("初始化操作失败!"); 
   return -1; 
}