示例#1
0
文件: Main.cpp 项目: localvar/backup
int MessageBoxV( HWND hWnd, UINT uTextFmt, UINT uType, ... )
{
	TCHAR fmt[256], caption[32];
	if( AtlLoadString( uTextFmt, fmt, _countof(fmt) ) <= 0 )
	{
		ATLASSERT( FALSE );
		fmt[0] = 0;
	}

	LPTSTR text = NULL;
	va_list arg;
	va_start( arg, uType );
	FormatMessage(
		FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
		fmt,
		0,
		0,
		reinterpret_cast<LPTSTR>( &text ),
		0,
		&arg
		);

	AtlLoadString( IDR_MAINFRAME, caption, _countof(caption) );

	int res = MessageBox( hWnd, text, caption, uType );
	LocalFree( text );
	return res;
}
示例#2
0
文件: Main.cpp 项目: localvar/backup
static void LoadInternalExceptionList()
{
	g_aException.SetCount( 0, 32 );

	LPCTSTR rs = NULL;
	size_t len = AtlLoadString(
		IDS_INTERNAL_EXCEPTIONS,
		reinterpret_cast<LPTSTR>(&rs),
		0
		);

	LPTSTR buf = reinterpret_cast<LPTSTR>( malloc((len + 1) * sizeof(TCHAR)) );
	_tcsncpy( buf, rs, len );
	buf[len] = 0;

	LPCTSTR p = _tcstok( buf, _T("|") );
	while( p != NULL )
	{
		CExceptionInfo ei;
		ei.bUser = false;
		ei.bFiltered = false;
		ei.dwCode = _tcstoul( p, NULL, 0 );
		p = _tcstok( NULL, _T("|") );
		_tcsncpy( ei.szName, p, _countof(ei.szName) );
		ei.szName[_countof(ei.szName) - 1] = 0;
		g_aException.Add( ei );
		p = _tcstok( NULL, _T("|") );
	}

	free( buf );
}
示例#3
0
文件: Main.cpp 项目: localvar/backup
void LogEvent( UINT uEventId, ... )
{
	if( g_pMainWnd == NULL )
		return;

	TCHAR fmt[256];
	if( AtlLoadString( uEventId, fmt, _countof(fmt) ) <= 0 )
	{
		ATLASSERT( FALSE );
		return;
	}

	LPTSTR log = NULL;
	va_list arg;
	va_start( arg, uEventId );
	FormatMessage(
		FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
		fmt,
		0,
		0,
		reinterpret_cast<LPTSTR>( &log ),
		0,
		&arg
		);

	g_pMainWnd->PostMessage( WM_LOG_EVENT, reinterpret_cast<WPARAM>(log), 0 );
}
示例#4
0
BOOL CMiniPieFrame::SetCommandButton(INT iID, bool bRight)
{
	TBBUTTONINFO tbbi = { sizeof(TBBUTTONINFO), TBIF_TEXT | TBIF_COMMAND | TBIF_BYINDEX };
	tbbi.idCommand =  iID;
	tbbi.pszText = (LPTSTR)AtlLoadString(iID);
	return CMenuBarCtrl(m_hWndCECommandBar).SetButtonInfo(bRight, &tbbi);
}
示例#5
0
LRESULT CSelProcDlg::OnInitDialog( UINT, WPARAM, LPARAM, BOOL& )
{
	m_hProc = NULL;

	DlgResize_Init( false );

	m_lst.SubclassWindow( GetDlgItem( IDC_PROCESS_LIST ) );
	DWORD dwStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;
	dwStyle |= LVS_EX_HEADERDRAGDROP;
	m_lst.SetExtendedListViewStyle( dwStyle );

	TCHAR szHeaders[128];
	AtlLoadString( IDS_PROCESS_LIST_HEADER, szHeaders, _countof(szHeaders) );

	RECT rect;
	m_lst.GetWindowRect( &rect );
	int nWidth = rect.right - rect.left;

	int nIndex = 0;
	LPCTSTR sz = _tcstok( szHeaders, _T("\n") );
	while( sz != NULL )
	{
		int w = _ttoi(_tcstok( NULL, _T("\n") )) * nWidth / 100;
		m_lst.InsertColumn( nIndex++, sz, LVCFMT_LEFT, w, 0 );
		sz = _tcstok( NULL, _T("\n") );
	}

	m_lst.SetColumnSortType( 0, LVCOLSORT_TEXTNOCASE );
	m_lst.SetColumnSortType( 1, LVCOLSORT_LONG );
	m_lst.SetColumnSortType( 2, LVCOLSORT_TEXTNOCASE );
	m_lst.SetSortColumn( 0 );

	RefreshProcessList();
	return TRUE;
}
示例#6
0
bool CScriptEditView::OnFileSaveAs()
{
	bool bRet = false;

	TCHAR szFilter[256];
	::ZeroMemory( szFilter, DIMOF(szFilter) );
	int nChar = AtlLoadString( IDS_FILE_FILTER, szFilter, DIMOF(szFilter) );

	DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
	CFileDialog dlg( FALSE, _T("*.txt"), m_szFilePath, dwFlags, szFilter );
	if( dlg.DoModal() == IDOK )
	{
		ATLTRACE( _T("File path: %s\n"), dlg.m_ofn.lpstrFile );
		bRet = SaveFile( dlg.m_szFileName );
		if( bRet )
		{
			Init( dlg.m_szFileName, dlg.m_szFileTitle );
		}
		else
		{
			AtlMessageBox(
				WtlGetMainWnd(),
				IDS_WRITE_FILE_FAILED,
				IDR_MAINFRAME,
				MB_OK|MB_ICONERROR
				);
		}
	}

	return bRet;
}
示例#7
0
bool CScriptEditView::QueryClose()
{
	if( !GetModify() )
		return true;

	TCHAR szFmt[32];
	AtlLoadString( IDS_SAVE_MODIFIED, szFmt, DIMOF(szFmt) );
	TCHAR szBuff[MAX_PATH + 40];
	wsprintf( szBuff, szFmt, m_szFileName );
	int nRet = AtlMessageBox(
		WtlGetMainWnd(),
		szBuff,
		IDR_MAINFRAME,
		MB_YESNOCANCEL | MB_ICONEXCLAMATION
		);

	if(nRet == IDCANCEL)
		return false;

	if(nRet == IDYES)
		return OnFileSave();

	return true;
}
示例#8
0
	BOOL Install() throw()
	{
		if (IsInstalled())
			return TRUE;

		// Get the executable file path
		TCHAR szFilePath[MAX_PATH + _ATL_QUOTES_SPACE];
		DWORD dwFLen = ::GetModuleFileName(NULL, szFilePath + 1, MAX_PATH);
		if( dwFLen == 0 || dwFLen == MAX_PATH )
			return FALSE;

		// Quote the FilePath before calling CreateService
		szFilePath[0] = _T('\"');
		szFilePath[dwFLen + 1] = _T('\"');
		szFilePath[dwFLen + 2] = 0;

		SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
		if (hSCM == NULL)
		{
			TCHAR szBuf[1024];
			if (AtlLoadString(ATL_SERVICE_MANAGER_OPEN_ERROR, szBuf, 1024) == 0)
#ifdef UNICODE
				Checked::wcscpy_s(szBuf, _countof(szBuf), _T("Could not open Service Manager"));
#else
				Checked::strcpy_s(szBuf, _countof(szBuf), _T("Could not open Service Manager"));
#endif
			MessageBox(NULL, szBuf, m_szServiceName, MB_OK);
			return FALSE;
		}

		SC_HANDLE hService = ::CreateService(
			hSCM, ROUTER_SERVICE, ROUTER_SERVICE,
			SERVICE_ALL_ACCESS, SERVICE_WIN32_SHARE_PROCESS,
			SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
			szFilePath, NULL, NULL, ROUTER_SERVICE_DEPEND, NULL, NULL);

		if (hService == NULL)
		{
			::CloseServiceHandle(hSCM);
			TCHAR szBuf[1024];
			if (AtlLoadString(ATL_SERVICE_START_ERROR, szBuf, 1024) == 0)
#ifdef UNICODE
				Checked::wcscpy_s(szBuf, _countof(szBuf), _T("Could not start service"));
#else
				Checked::strcpy_s(szBuf, _countof(szBuf), _T("Could not start service"));
#endif
			MessageBox(NULL, szBuf, m_szServiceName, MB_OK);
			return FALSE;
		}
		else
		{
			HMODULE hAdvApi = ::LoadLibrary(_T("Advapi32"));
			LPFN_ChangeServiceConfig2 pfnChangeServiceConfig2 = NULL; 
			if(hAdvApi)
			{
				pfnChangeServiceConfig2 = (LPFN_ChangeServiceConfig2)GetProcAddress(hAdvApi, ChangeServiceConfig2Name);

				if(pfnChangeServiceConfig2)
				{
					SERVICE_DESCRIPTION sd = { (PTSTR) ROUTER_SERVICE_DESC };
					pfnChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &sd);
				}

				::FreeLibrary(hAdvApi);
			}
		}

		::CloseServiceHandle(hService);
		::CloseServiceHandle(hSCM);
		return TRUE;
	}
LRESULT CChildFrame::OnFileExtractData(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{ 
    HRESULT hr = E_FAIL; 

    TREE_ITEM_DATA * pTmp = (TREE_ITEM_DATA *)m_pData.GetData(); 

    if (NULL == pTmp) return 0; 

    TCHAR szText[MAX_PATH] = { 0 }; 
    m_pData.GetText(szText, _countof(szText)); 
    ATLTRACE(_T("---------%s\n"), szText); 

    if (STGTY_STREAM == pTmp->dwStgType) 
    { 
        TCHAR szFileName[MAX_PATH] = { 0 }; 

        if (NULL == _tcschr(szText, '.')) 
        { 
            _tcscat(szText, _T(".bin")); 
        } 

        AdjustFileName(szText); 

        TCHAR szFilter[MAX_PATH] = { 0 }; 
        { 
            // assembling filter string 
            TCHAR szAllFiles[MAX_PATH] = { 0 }; 
            AtlLoadString(IDS_ALL_FILES, szAllFiles, _countof(szAllFiles)); 

            wnsprintf(szFilter, _countof(szFilter), _T("%s(*.*)|*.*||"), szAllFiles); 
        } 

        CModifiedFileDialog fd ( FALSE, _T(""), szText, OFN_HIDEREADONLY, szFilter, m_hWnd ); 

        
        if ( IDOK != fd.DoModal(this->m_hWnd) ) 
            return 0; 
        
        lstrcpyn(szFileName, fd.m_szFileName, _countof(szFileName)); 

        if (PathFileExists(szFileName)) { 
            TCHAR szFmt[MAX_PATH] = { 0 }; 
            AtlLoadString(IDS_FILE_EXISTS, szFmt, _countof(szFmt)); 
            TCHAR szMsg[MAX_PATH*2] = { 0 }; 
            wnsprintf(szMsg, _countof(szMsg), szFmt, szFileName); 
            if ( IDYES != AtlMessageBox(m_hWnd, szMsg, IDS_WARNING, MB_YESNO|MB_ICONWARNING)) { 
                return 0; 
            } 
        } 

        CComPtr<IStream> spFile; 
        hr = pTmp->spStgOrStrm->QueryInterface(&spFile); 
        if (FAILED(hr)) return hr; 

        hr = WriteStreamToFile(szFileName, spFile); 
    } 

    else if (STGTY_STORAGE == pTmp->dwStgType) 
    { 
        CModifiedFolderDialog fd ( GetTopLevelParent(), IDS_SELECT_DIR, 
            BIF_RETURNONLYFSDIRS|BIF_NEWDIALOGSTYLE ); 

        TCHAR szCurrPath[MAX_PATH] = { 0 }; 
        GetCurrentDirectory(_countof(szCurrPath), szCurrPath); 

        fd.SetInitialDir( szCurrPath ); 

        if ( IDOK != fd.DoModal() ) 
            return 0; 

        lstrcpyn(szCurrPath, fd.GetFolderPath(), _countof(szCurrPath)); 
        PathAddBackslash(szCurrPath); 

        SHCreateDirectoryEx(*this, szCurrPath, NULL); 

        // recursion 
        _RecursionExtractData(szCurrPath, m_pData, &m_wndCatalog); 
    } 

    return 0; 
} 
BOOL CChildFrame::OpenCompositeDocument(LPCTSTR lpszFileName) 
{ 
    USES_CONVERSION; 

    CWaitCursor wait; 

    HRESULT hResult = E_FAIL; 
    IStorage * ptrRootStg = NULL; // root storage 
    HWND hWnd = (HWND)m_hWnd; 

    hResult = ::StgIsStorageFile( T2COLE(m_szFileName) ); 
    if( S_OK != hResult ) 
    { 
        TCHAR szFmt[MAX_PATH] = { 0 }; 
        AtlLoadString(IDS_OPEN_ARCHIVE_ERROR, szFmt, _countof(szFmt)); 

        TCHAR szOut[MAX_PATH*2] = { 0 }; 
        wnsprintf(szOut, _countof(szOut), szFmt, lpszFileName); 

        AtlMessageBox(m_hWnd, szOut, IDS_ERROR, MB_OK|MB_ICONSTOP); 
        return FALSE; 
    }

    // open the Compound document 
    hResult = ::StgOpenStorage( T2COLE(m_szFileName), NULL, 
        STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 
        0, 0, &ptrRootStg ); 
    if( FAILED(hResult) )
    { 
        TCHAR szFmt[MAX_PATH] = { 0 }; 
        AtlLoadString(IDS_OPEN_FILE_ERROR, szFmt, _countof(szFmt)); 

        TCHAR szError[MAX_PATH] = { 0 }; 

        TCHAR szOut[MAX_PATH*2] = { 0 }; 
        wnsprintf(szOut, _countof(szOut), szFmt, 
            lpszFileName, GetErrorString(S_OK, szError, _countof(szError))); 

        AtlMessageBox(m_hWnd, szOut, IDS_ERROR, MB_OK|MB_ICONSTOP); 
        return FALSE;
    } 

    TREE_ITEM_DATA * pRootData = new TREE_ITEM_DATA(ptrRootStg, STGTY_STORAGE); 

    HTREEITEM hRoot = m_wndCatalog.InsertItem ( 
        TVIF_IMAGE|TVIF_TEXT|TVIF_PARAM|TVIF_SELECTEDIMAGE, 
        PathFindFileName(m_szFileName), 
        0, 1, TVIS_EXPANDED, 0, 
        reinterpret_cast<LPARAM>(pRootData), 
        NULL, NULL); 


    std::stack < StgInfo > FolderStack; 
    HTREEITEM htiParent = hRoot; 
    IEnumSTATSTG * ptrEnum = NULL; 

    hResult = ptrRootStg->EnumElements( 0, NULL, 0, &ptrEnum ); 
    if( FAILED(hResult) ) { 
        ptrRootStg->Release(); 
        return 0; 
    } 

    TCHAR szSwap[MAX_PATH] = { 0 }; 

	LARGE_INTEGER nStorageLength;
	nStorageLength.QuadPart = 0;
    STATSTG StatStg = { 0 }; 
    while( S_OK == hResult ) 
    { 
        hResult = ptrEnum->Next( 1, &StatStg, NULL ); 
        if( S_FALSE == hResult ) 
        { 
            ptrRootStg->Release(); 
            ptrEnum->Release(); 

            // m_wndCatalog.Expand(strFolder); 

            if( !FolderStack.empty() ) 
            { 
				TCHAR szCurText[MAX_PATH] = {0};
				m_wndCatalog.GetItemText(htiParent, szCurText, _countof(szCurText));
				CString strTotal;
				strTotal.Format(TEXT("%s(%ld)"), szCurText, nStorageLength);
				m_wndCatalog.SetItemText(htiParent, strTotal);

				ptrRootStg  = FolderStack.top().pStg; 
                ptrEnum     = FolderStack.top().pEnum; 
                htiParent   = FolderStack.top().hParent; 
                FolderStack.pop(); 

                hResult = S_OK; 
            } 

            continue; 
        } 

        switch(StatStg.type) 
        { 
        case STGTY_STORAGE: // 是存储对象, "文件夹" 
            { 
				//先清零
				nStorageLength.QuadPart = 0;
                IStorage * ptrChildStg = NULL;

                HRESULT hr = ptrRootStg->OpenStorage( StatStg.pwcsName, NULL, 
                    STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 
                    0, 0, &ptrChildStg ); 
                if( SUCCEEDED(hr) ) 
                { 
                    TREE_ITEM_DATA * pData = new TREE_ITEM_DATA(ptrChildStg, StatStg.type); 

                    HTREEITEM hFolder = m_wndCatalog.InsertItem ( 
                        TVIF_IMAGE|TVIF_TEXT|TVIF_PARAM|TVIF_SELECTEDIMAGE, 
                        WCHAR2TCHAR(StatStg.pwcsName, szSwap, _countof(szSwap)), 
                        0, 1, TVIS_EXPANDED, 0, 
                        reinterpret_cast<LPARAM>(pData), 
                        htiParent, NULL); 

                    // 父存储入栈 
                    FolderStack.push( StgInfo(ptrRootStg, ptrEnum, htiParent) );

                    // 子存储替代父存储 
                    ptrRootStg = ptrChildStg; 
                    htiParent = hFolder; 
                    hr = ptrChildStg->EnumElements( 0, NULL, 0, &ptrEnum ); 
                } 
            } 
            break; 
        case STGTY_STREAM:  // 是流, "文件" 
            { 
                CComPtr<IStream> spStream; 
                HRESULT hr = ptrRootStg->OpenStream(StatStg.pwcsName, NULL, 
                    STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &spStream); 
                ATLASSERT(SUCCEEDED(hr)); 
				
				LARGE_INTEGER nSeekPos;
				nSeekPos.QuadPart = 0LL;
				ULARGE_INTEGER nLength = {0};
				hr = spStream->Seek(nSeekPos, STREAM_SEEK_END, &nLength);
				CString strStreamName;
				WCHAR2TCHAR(StatStg.pwcsName, szSwap, _countof(szSwap));
				if (SUCCEEDED(hr))
				{
					nStorageLength.QuadPart += nLength.QuadPart;
					strStreamName.Format(TEXT("%s(%ld)"), szSwap, nLength);
				}
				else
				{
					strStreamName.Format(TEXT("%s(0)"), szSwap);
				}
                TREE_ITEM_DATA * pData = new TREE_ITEM_DATA(spStream, StatStg.type); 
                m_wndCatalog.InsertItem ( 
                    TVIF_IMAGE|TVIF_TEXT|TVIF_PARAM|TVIF_SELECTEDIMAGE, 
                    strStreamName, 
                    2, 2, TVIS_EXPANDED, 0, 
                    reinterpret_cast<LPARAM>(pData), 
                    htiParent, NULL); 
            } 
            break; 
        case STGTY_LOCKBYTES: 
            ATLTRACE(_T("===== STGTY_LOCKBYTES %d ====="), StatStg.type); 
            break; 
        case STGTY_PROPERTY: 
            ATLTRACE(_T("===== STGTY_PROPERTY %d ====="), StatStg.type); 
            break; 
        default: 
            ATLASSERT(!_T("Unknown storage type!!!")); 
            break; 
        } 

        ::CoTaskMemFree( StatStg.pwcsName ); // 释放名称所使用的内存 
    }

    return 0;
}
示例#11
0
	BOOL Install() throw()
	{
		if (IsInstalled())
			return TRUE;

		//step1.register dlls:
		//WinRobotCore.dll,WinRobotHostPS.dll
#if _WIN64
		if(!RegisterComDLL(0,_T("WinRobotCorex64.dll")))
#else
		if(!RegisterComDLL(0,_T("WinRobotCorex86.dll")))
#endif
		{
			DebugOutF(filelog::log_info,"RegisterComDLL WinRobotCore failed");
			return false;
		}
#if _WIN64
		if(!RegisterComDLL(0,_T("WinRobotHostPSx64.dll")))
#else
		if(!RegisterComDLL(0,_T("WinRobotHostPSx86.dll")))
#endif
		{
			DebugOutF(filelog::log_info,"RegisterComDLL WinRobotHostPS failed");
			return false;
		}
		// Get the executable file path
		TCHAR szFilePath[MAX_PATH + _ATL_QUOTES_SPACE];
		DWORD dwFLen = ::GetModuleFileName(NULL, szFilePath + 1, MAX_PATH);
		if( dwFLen == 0 || dwFLen == MAX_PATH )
			return FALSE;

		// Quote the FilePath before calling CreateService
		szFilePath[0] = _T('\"');
		szFilePath[dwFLen + 1] = _T('\"');
		szFilePath[dwFLen + 2] = 0;

		SC_HANDLE hSCM = ::OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
		if (hSCM == NULL)
		{
			TCHAR szBuf[1024];
			if (AtlLoadString(ATL_SERVICE_MANAGER_OPEN_ERROR, szBuf, 1024) == 0)
#ifdef UNICODE
				Checked::wcscpy_s(szBuf, _countof(szBuf), _T("Could not open Service Manager"));
#else
				Checked::strcpy_s(szBuf, _countof(szBuf), _T("Could not open Service Manager"));
#endif
			MessageBox(NULL, szBuf, m_szServiceName, MB_OK);
			return FALSE;
		}
		_tcscat(szFilePath,_T(" -runas service"));
		SC_HANDLE hService = ::CreateService(
			hSCM, m_szServiceName, m_szServiceName,
			SERVICE_ALL_ACCESS, 	m_status.dwServiceType,
			SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
			szFilePath, NULL, NULL, _T("RPCSS\0"), NULL, NULL);

		if (hService == NULL)
		{
			::CloseServiceHandle(hSCM);
			TCHAR szBuf[1024];
			if (AtlLoadString(ATL_SERVICE_START_ERROR, szBuf, 1024) == 0)
#ifdef UNICODE
				Checked::wcscpy_s(szBuf, _countof(szBuf), _T("Could not start service"));
#else
				Checked::strcpy_s(szBuf, _countof(szBuf), _T("Could not start service"));
#endif
			MessageBox(NULL, szBuf, m_szServiceName, MB_OK);
			return FALSE;
		}

		::CloseServiceHandle(hService);
		::CloseServiceHandle(hSCM);
		return TRUE;
	}