BOOL CheckFileRelation(const TCHAR* strExt, const TCHAR* strAppKey)
{
HKEY hExtKey;
BOOL bRet = RegOpenKey(HKEY_CLASSES_ROOT, _T(".itxb"), &hExtKey);
if(!bRet) return FALSE;
TCHAR szPath[_MAX_PATH];
DWORD dwSize = sizeof(szPath);
RegQueryValueEx(hExtKey, NULL, NULL, NULL, (LPBYTE)szPath, &dwSize);
if(_tcscmp(szPath, strAppKey)==0)
{
RegCloseKey(hExtKey);
return TRUE;
}
RegCloseKey(hExtKey);
return FALSE;
}
/************************************************************************/
/*
注册文件关联,将文件的后缀名与具体的程序关联在一起
*/
/************************************************************************/
void RegisterFileRelation(TCHAR* strExt, TCHAR* strAppKey, TCHAR* strAppName)
{
HKEY hKey;
::RegCreateKey(HKEY_CLASSES_ROOT, strExt, &hKey);
::RegSetValue(hKey, _T(""), REG_SZ, strAppKey, _tcslen(strAppKey)+1);
::RegCloseKey(hKey);
TCHAR strTemp[_MAX_PATH];
_stprintf(strTemp, _T("%s\\shell\\open\\command"), strAppKey);
::RegCreateKey(HKEY_CLASSES_ROOT, strTemp, &hKey);
_stprintf(strTemp, _T("%s \"%%1\""), strAppName);
::RegSetValue(hKey, _T(""), REG_SZ, strTemp, _tcslen(strTemp)+1);
::RegCloseKey(hKey);
}
QDemoWinApp::QDemoWinApp(void)
{
}
QDemoWinApp::~QDemoWinApp(void)
{
}
QDemoWinApp theApp;
CGragh gGragh;
BOOL QDemoWinApp::InitInstance()
{
BOOL bIsRegester = CheckFileRelation(_T(".itxb"), _T("itxbfile"));
if(!bIsRegester)
{
RegisterFileRelation(_T(".itxb"), _T("itxbfile"), _T("F:\\itxb\\windows programme design\\10 ini and regedit\\Demo10-1\\Debug\\Demo.exe"));
}
LPTSTR lpszCommandName = GetCommandLine();
CString strCommandName = lpszCommandName;
int nOrder = strCommandName.Find(_T("\" \""));
if(nOrder>=0)
{
int l1 = strCommandName.Find("\"", 0);
int l2 = strCommandName.Find("\"", l1+1);
int l3 = strCommandName.Find("\"", l2+1);
int l4 = strCommandName.Find("\"", l3+1);
CString strFileName = strCommandName.Mid(l3+1, l4-(l3+1));
gGragh.GetGraghFromFile(strFileName.GetBuffer(0));
}
QMainFrame* pMainWnd = new QMainFrame();
assert(pMainWnd);
m_pMainWnd = pMainWnd;
BOOL bRet = pMainWnd->CreateEx(0, _T("www.itxueba.org"), _T("www.itxueba.org"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL);
if(!bRet)
{
MessageBox(NULL, _T("创建窗口失败!"), _T("创建窗口!"), 0);
return FALSE;
}
pMainWnd->ShowWindow(SW_SHOW);
pMainWnd->UpdateWindow();
return TRUE;
}