BOOL
CUIDemoApp::InitInstance()
{
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
connPool= Connection_pool::GetInstance();
//InItDBConnPool(".","","","viewdb",5, 25);
exePath=(
LPCSTR
)AfxGetApp()->m_pszHelpFilePath;
CString str=AfxGetApp()->m_pszExeName;
exePath=exePath.substr(0,exePath.length()-str.GetLength()-4);
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize =
sizeof
(InitCtrls);
// 将它设置为包括所有要在应用程序中使用的
// 公共控件类。
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinAppEx::InitInstance();
string path;
path=exePath+
"Connect.ini"
;
CString ConnectTypeCS;
CString ConnectIPC;
CString ConnectPORTC;
GetPrivateProfileString(_T(
"Connect"
),_T(
"ConnectType"
),_T(
""
),ConnectTypeCS.GetBuffer(MAX_PATH),MAX_PATH,(
LPCSTR
)path.c_str());
GetPrivateProfileString(_T(
"Connect"
),_T(
"IP"
),_T(
""
),ConnectIPC.GetBuffer(MAX_PATH),MAX_PATH,(
LPCSTR
)path.c_str());
GetPrivateProfileString(_T(
"Connect"
),_T(
"PORT"
),_T(
""
),ConnectPORTC.GetBuffer(MAX_PATH),MAX_PATH,(
LPCSTR
)path.c_str());
GetPrivateProfileString(_T(
"Connect"
),_T(
"ID"
),_T(
""
),ipid.GetBuffer(MAX_PATH),MAX_PATH,(
LPCSTR
)path.c_str());
ConnectIP=ConnectIPC.GetBuffer(0);
ConnectIPC.ReleaseBuffer();
ConnectPORT=ConnectPORTC.GetBuffer(0);
ConnectPORTC.ReleaseBuffer();
ipid.ReleaseBuffer();
transform(ConnectType.begin(), ConnectType.end(), ConnectType.begin(),
toupper
);
CDlgLogon dlg;
int
count = 0;
do
{
if
(count >= 3)
{
::MessageBox(NULL, _T(
"三次登录尝试失败!"
), _T(
"系统提示"
), MB_OK);
return
true
;
}
dlg.m_user = _T(
""
);
dlg.m_password = _T(
""
);
dlg.m_ConnectType.Format(_T(
"%s"
),ConnectTypeCS);
// =ConnectTypeCS;
dlg.m_IP.Format(_T(
"%s"
),ConnectIP.c_str());
dlg.m_Port.Format(_T(
"%s"
),ConnectPORT.c_str());;
if
(dlg.DoModal() == IDOK)
{
if
(ValidUser(dlg.m_user,dlg.m_password))
{
UserName=dlg.m_user;
WritePrivateProfileString(_T(
"Connect"
),_T(
"ConnectType"
),dlg.m_ConnectType,(
LPCSTR
)(
LPCWSTR
)path.c_str());
WritePrivateProfileString(_T(
"Connect"
),_T(
"IP"
),dlg.m_IP,(
LPCSTR
)(
LPCWSTR
)path.c_str());
WritePrivateProfileString(_T(
"Connect"
),_T(
"PORT"
),dlg.m_Port,(
LPCSTR
)(
LPCWSTR
)path.c_str());
ConnectType=dlg.m_ConnectType.GetBuffer(0);
dlg.m_ConnectType.ReleaseBuffer();
if
(ConnectType==
"SERVER"
)
{
ConnectPORT=dlg.m_Port.GetBuffer(0);
dlg.m_Port.ReleaseBuffer();
ServerConnect(ConnectPORT);
}
else
{
ConnectIP=dlg.m_IP.GetBuffer(0);
dlg.m_IP.ReleaseBuffer();
ConnectPORT=dlg.m_Port.GetBuffer(0);
dlg.m_Port.ReleaseBuffer();
ClientConnect(ConnectIP,ConnectPORT);
}
break
;
}
else
{
count++;
}
}
else
{
return
true
;
}
}
while
(1);
// 初始化 OLE 库
if
(!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return
FALSE;
}
AfxEnableControlContainer();
InitShellManager();
//初始化CMFCShellTreeCtrl和CMFCShellListCtrl
// 标准初始化
// 如果未使用这些功能并希望减小
// 最终可执行文件的大小,则应移除下列
// 不需要的特定初始化例程
// 更改用于存储设置的注册表项
// TODO: 应适当修改该字符串,
// 例如修改为公司或组织名
//lbw
SetRegistryKey(_T(
"应用程序向导生成的本地应用程序"
));
LoadStdProfileSettings(0);
// 加载标准 INI 文件选项
InitContextMenuManager();
InitKeyboardManager();
InitTooltipManager();
CMFCToolTipInfo ttParams;
ttParams.m_bVislManagerTheme = TRUE;
theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
// 注册应用程序的文档模板。文档模板
// 将用作文档、框架窗口和视图之间的连接
CSingleDocTemplate* pDocTemplate;
pDocTemplate =
new
CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CUIDemoDoc),
RUNTIME_CLASS(CMainFrame),
// 主 SDI 框架窗口
RUNTIME_CLASS(CAdminList));
if
(!pDocTemplate)
return
FALSE;
AddDocTemplate(pDocTemplate);
//CMainFrame cmainFrame;
//cmainFrame.OnQueryAdmin();
// 启用“DDE 执行”
EnableShellOpen();
RegisterShellFileTypes(TRUE);
// 分析标准外壳命令、DDE、打开文件操作的命令行
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// 调度在命令行中指定的命令。如果
// 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
if
(!ProcessShellCommand(cmdInfo))
return
FALSE;
////////////////////////////////添加其他视图类
CView *pOldActiveView=((CFrameWnd*) m_pMainWnd)->GetActiveView();
CView *pNewActiveView=(CView*)GetDlgItem(AfxGetMainWnd()->m_hWnd,IDD_VIRTUALREPORT);
//通过这两行代码可以得到当前的view,并且根据nForm的id值,得到我们的view资源。
pNewActiveView=(CView*)
new
CVirtualReport();
CCreateContext context;
context.m_pCurrentDoc=pOldActiveView->GetDocument();
pNewActiveView->Create(NULL,NULL,WS_CHILD | WS_BORDER,CFrameWnd::rectDefault,m_pMainWnd,IDD_VIRTUALREPORT,&context);
pNewActiveView->OnInitialUpdate();
// 唯一的一个窗口已初始化,因此显示它并对其进行更新
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
// 仅当具有后缀时才调用 DragAcceptFiles
// 在 SDI 应用程序中,这应在 ProcessShellCommand 之后发生
// 启用拖/放
m_pMainWnd->DragAcceptFiles();
//CWnd* LocalIp = GetDlgItem(IDC_EDIT_IP);
//LocalIp->SetWindowText(m_szServerIP);
return
TRUE;
}