BOOL CDeleteMasterApp::RegClass() { WNDCLASS wndcls,wndSecInfo; CBrush bs(bkRGB); memset(&wndcls, 0, sizeof(WNDCLASS)); wndcls.style = CS_BYTEALIGNWINDOW; wndcls.lpfnWndProc = ::DefWindowProc; wndcls.hInstance = AfxGetInstanceHandle(); wndcls.hIcon = LoadIcon(IDR_MAINFRAME); // or load a different wndcls.hCursor = LoadStandardCursor(IDC_ARROW); wndcls.hbrBackground = (HBRUSH)COLOR_WINDOW; wndcls.lpszMenuName = NULL; wndcls.lpszClassName = DMMainWinClass; memset(&wndSecInfo, 0, sizeof(WNDCLASS)); wndSecInfo.style = CS_BYTEALIGNWINDOW; wndSecInfo.lpfnWndProc = ::DefWindowProc; wndSecInfo.hInstance = AfxGetInstanceHandle(); wndSecInfo.hCursor = LoadStandardCursor (IDC_ARROW); wndSecInfo.hbrBackground = (HBRUSH)COLOR_WINDOWFRAME; wndSecInfo.lpszMenuName = NULL; wndSecInfo.lpszClassName = DMSecWinClass; if(!RegisterClass(&wndcls)) return FALSE; if(!RegisterClass(&wndSecInfo)) return FALSE; return TRUE; }
virtual BOOL InitInstance() { CFrameWnd* pFrame = new CFrameWnd; CString str = AfxRegisterWndClass( 0, LoadStandardCursor(IDC_IBEAM), (HBRUSH)GetStockObject(BLACK_BRUSH), LoadStandardIcon(IDI_WINLOGO)); pFrame->Create( str, // 윈도우 클래스.. "Hello, MFC", WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX, CRect(100,100,200,200), 0, 0, WS_EX_TOPMOST); // 확장 윈도우 style pFrame->ShowWindow( SW_SHOW ); pFrame->UpdateWindow( ); m_pMainWnd = pFrame; return TRUE; }
BOOL VFDTestApp::InitInstance() { // 防止重复启动,扫描程序重复启动时异常。 // Add this code in InistInstance function TCHAR *lpszName = _T("VFDTEST"); HANDLE hMutex = ::CreateMutex(NULL, FALSE, lpszName); DWORD dwRet = ::GetLastError(); if (hMutex) { if (ERROR_ALREADY_EXISTS == dwRet) { AfxMessageBox(_T("VFDTEST has been running.")); CloseHandle(hMutex); // should be closed hMutex = 0; return FALSE; } } else { AfxMessageBox(_T("Create Mutex Error")); } // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。否则,将无法创建窗口。 INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinAppEx::InitInstance(); // 初始化 OLE 库 if (!AfxOleInit()) { AfxMessageBox(IDP_OLE_INIT_FAILED); return FALSE; } //取应用程序路径 GetModuleFileName(NULL, m_szAppPath, MAX_PATH); PathRemoveFileSpec( m_szAppPath ); // 取临时文件夹 GetTempPath(MAX_PATH-1, m_szTempPath );//获取临时文件夹路径 AfxEnableControlContainer(); EnableTaskbarInteraction(FALSE); // 使用 RichEdit 控件需要 AfxInitRichEdit2() // AfxInitRichEdit2(); // 标准初始化 // 如果未使用这些功能并希望减小 // 最终可执行文件的大小,则应移除下列 // 不需要的特定初始化例程 // 更改用于存储设置的注册表项 // TODO: 应适当修改该字符串, // 例如修改为公司或组织名 SetRegistryKey(_T("VFDTest")); /* 改为创建一个普通的主窗口 // 若要创建主窗口,此代码将创建新的框架窗口 // 对象,然后将其设置为应用程序的主窗口对象 CMainFrame* pFrame = new CMainFrame; if (!pFrame) return FALSE; m_pMainWnd = pFrame; // 创建并加载框架及其资源 pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL); */ // Register your unique class name that you wish to use WNDCLASS wndcls; memset(&wndcls, 0, sizeof(WNDCLASS)); // start with NULL // defaults //wndcls.style = CS_DBLCLKS; //双击 //you can specify your own window procedure wndcls.lpfnWndProc = ::DefWindowProc; wndcls.hInstance = AfxGetInstanceHandle(); wndcls.hIcon = LoadIcon(IDR_MAINFRAME); // or load a different icon wndcls.hCursor = LoadStandardCursor( IDC_ARROW ); //backGrush.CreateSolidBrush(RGB(247,247,247)); // Blue brush. //wndcls.hbrBackground = (HBRUSH)backGrush.m_hObject; wndcls.lpszMenuName = NULL; // Specify your own class name for using FindWindow later wndcls.lpszClassName = _T("VFDTest"); // Register the new class and exit if it fails if(!AfxRegisterClass(&wndcls)) { TRACE(_T("Class Registration Failed\n")); return FALSE; } // 主窗口 MainForm* pFrame = new MainForm(); // 取系统参数,确定显示位置和大小 CRect drc; // 桌面工作区大小,不算任务栏 SystemParametersInfo(SPI_GETWORKAREA,0,drc,0); int dwidth = drc.Width(); // 桌面工作区宽 int dheight = drc.Height(); // 桌面工作区高 // 上次保存的窗口大小 CRect rc; rc.right = dwidth; // 第一次进窗口状态,充满桌面,有边框,可改变大小。 rc.bottom = dheight; //this->GetInt(); rc.left = GetInt( _T("WindowLeft"), rc.left ); rc.top = GetInt( _T("WindowTop"), rc.top ); rc.right = GetInt( _T("WindowRight"), rc.right ); rc.bottom = GetInt( _T("WindowBottom"), rc.bottom ); // 最小尺寸200x200 const int s = 300; // ?? 应该考虑系统DPI if( rc.Width() < s ) rc.right = rc.left + s; if( rc.Height() < s ) rc.bottom = rc.top + s; // 与桌面相交最少200 int dx = 0, dy = 0, d = 0; if( rc.right < s ) dx = s - rc.right; else if( (d = dwidth - rc.left) < s ) dx = d - s; if( rc.bottom < s ) dy = s - rc.bottom; else if( (d = dheight - rc.top) < s ) dy = d - s; // 窗口的左右都超出桌面,窗口移到桌面内 if( rc.left < 0 && rc.right > dwidth ) dx = -rc.left; if( rc.top < 0 && rc.bottom > dheight ) dy = -rc.top; // 移动显示区 if( dx || dy ) rc.OffsetRect( dx, dy ); // 创建窗口 // 唯一的一个窗口已初始化,因此显示它并对其进行更新 m_nFullScreen = GetInt( _T("FullScreen"), m_nFullScreen ); // 全屏状态 m_nMaximized = GetInt( _T("ShowMaximized"), m_nMaximized ); // 最大化状态 DWORD style = (m_nFullScreen ? WS_POPUP : WS_OVERLAPPEDWINDOW); if( m_nFullScreen | m_nMaximized ) style |= WS_MAXIMIZE; if( !pFrame->CreateEx( NULL, wndcls.lpszClassName, _T("VFDTest"), style, rc, NULL, NULL, NULL ) ) // 无边框,充满屏 { delete pFrame; return FALSE; } m_pMainWnd = pFrame; pFrame->ShowWindow(SW_SHOW); //pFrame->UpdateWindow(); // 仅当具有后缀时才调用 DragAcceptFiles // 在 SDI 应用程序中,这应在 ProcessShellCommand 之后发生 return TRUE; }
BOOL CAdminControlApp::InitInstance() { //TODO: call AfxInitRichEdit2() to initialize richedit2 library. // 如果一个运行在 Windows XP 上的应用程序清单指定要 // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, //则需要 InitCommonControlsEx()。否则,将无法创建窗口。 //崩溃开始处 // CR_INSTALL_INFO info = {0}; // info.cb = sizeof(CR_INSTALL_INFO); // info.pszAppName = TEXT("AdminControl"); // info.pszAppVersion = TEXT("1.0.0"); // info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; // info.dwFlags |= CR_INST_DONT_SEND_REPORT; // info.dwFlags |= CR_INST_NO_GUI; // info.pszErrorReportSaveDir = TEXT("./UMErrReport"); // // // Install crash handlers // int nInstResult = crInstall(&info); // //assert(nInstResult==0); // if(nInstResult!=0) // { // TCHAR buff[256]; // crGetLastErrorMsg(buff, 256); // Get last error // _tprintf(_T("%s\n"), buff); // and output it to the screen // return 1; // } INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // 将它设置为包括所有要在应用程序中使用的 // 公共控件类。 InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); CWinAppEx::InitInstance(); m_ParameterGlobal.LoadParameter(); AfxEnableControlContainer(); // 标准初始化 // 如果未使用这些功能并希望减小 // 最终可执行文件的大小,则应移除下列 // 不需要的特定初始化例程 // 更改用于存储设置的注册表项 // TODO: 应适当修改该字符串, // 例如修改为公司或组织名 SetRegistryKey(_T("应用程序向导生成的本地应用程序")); // CAdminControlDlg dlg; // CDlgLogin m_login; // if (m_login.DoModal() != IDOK) // { // return FALSE; // } // m_MissionLogon.ShowLogon(); // // m_pMainWnd = &dlg; // INT_PTR nResponse = dlg.DoModal(); // if (nResponse == IDOK) // { // // TODO: 在此放置处理何时用 // // “确定”来关闭对话框的代码 // } // else if (nResponse == IDCANCEL) // { // // TODO: 在此放置处理何时用 // // “取消”来关闭对话框的代码 // } const TCHAR szPlazaClass[]=TEXT("UM"); WNDCLASS WndClasss; ZeroMemory(&WndClasss,sizeof(WndClasss)); //注册窗口 WndClasss.style=CS_DBLCLKS; WndClasss.hIcon=NULL; WndClasss.lpfnWndProc=DefWindowProc; WndClasss.lpszClassName=szPlazaClass; WndClasss.hInstance=AfxGetInstanceHandle(); WndClasss.hCursor=LoadStandardCursor(MAKEINTRESOURCE(IDC_HAND_CUR)); if (AfxRegisterClass(&WndClasss)==FALSE) AfxThrowResourceException(); AfxInitRichEdit(); //建立窗口 CMyFrameWnd * pPlatformFrame=new CMyFrameWnd; pPlatformFrame->Create(szPlazaClass,szProduct,WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_SYSMENU,CRect(0,0,0,0)); m_pMainWnd = pPlatformFrame; m_pMainWnd->ShowWindow(SW_HIDE); m_pMainWnd->UpdateWindow(); // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, // 而不是启动应用程序的消息泵。 return TRUE; }
//初始化函数 BOOL CGamePlazaApp::InitInstance() { __super::InitInstance(); //判断是否重入 #ifndef ADMIN_PLAZA #ifndef _DEBUG bool bExistIGame=false; CMutex Mutex(FALSE,MAIN_DLG_CLASSNAME,NULL); if (Mutex.Lock(0)==FALSE) bExistIGame=true; CWnd * pIGameWnd=CWnd::FindWindow(MAIN_DLG_CLASSNAME,NULL); if (pIGameWnd!=NULL) { bExistIGame=true; if (pIGameWnd->IsIconic()) pIGameWnd->ShowWindow(SW_RESTORE); pIGameWnd->SetActiveWindow(); pIGameWnd->BringWindowToTop(); pIGameWnd->SetForegroundWindow(); } if (bExistIGame==true) return FALSE; #endif #endif //程序初始化 AfxOleInit(); AfxInitRichEdit(); AfxInitRichEdit2(); InitCommonControls(); AfxEnableControlContainer(); //设置注册表 SetRegistryKey(szSystemRegKey); //加载界面库 CSkinAttribute::LoadSkinAttribute(GET_OBJECT_INTERFACE(m_SkinRecordFile,IUnknownEx)); //加载配置 g_GlobalOption.LoadOptionParameter(); //全局信息 if (g_GlobalUnits.InitGlobalUnits()==false) { AfxMessageBox(TEXT("游戏广场初始化失败,程序即将退出!"),MB_ICONSTOP); return FALSE; } //变量定义 WNDCLASS WndClasss; ZeroMemory(&WndClasss,sizeof(WndClasss)); //注册窗口 WndClasss.style=CS_DBLCLKS; WndClasss.lpfnWndProc=DefWindowProc; WndClasss.lpszClassName=MAIN_DLG_CLASSNAME; WndClasss.hInstance=AfxGetInstanceHandle(); WndClasss.hIcon=LoadIcon(MAKEINTRESOURCE(IDR_MAINFRAME)); WndClasss.hCursor=LoadStandardCursor(MAKEINTRESOURCE(IDC_ARROW)); if (AfxRegisterClass(&WndClasss)==FALSE) AfxThrowResourceException(); //建立窗口 CGameFrame * pMainFrame=new CGameFrame(); pMainFrame->Create(MAIN_DLG_CLASSNAME,TEXT(""),WS_MINIMIZEBOX|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,CRect(0,0,0,0)); m_pMainWnd=pMainFrame; return TRUE; }