コード例 #1
0
ファイル: log.cpp プロジェクト: Blonder/TortoiseGit
void ConsoleMedia::Write(ELogMessageType type,
                          ELogMessageLevel nLevel,
                          LPCTSTR pszDate,
                          LPCTSTR pszTime,
                          LPCTSTR pszThreadId,
                          LPCTSTR pszThreadName,
                          LPCTSTR pszModule,
                          LPCTSTR pszMessage)
{
    if (m_hConsole==NULL)
        return;
    WORD color = FOREGROUND_GREEN|FOREGROUND_INTENSITY;
    //FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|BACKGROUND_INTENSITY;
    switch (type)
    {
    case eLM_Debug:
        color = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE;
        break;
    case eLM_Warning:
        color = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_INTENSITY;
        break;
    case eLM_Error:
        color = FOREGROUND_RED|FOREGROUND_INTENSITY;
        break;
    }

    CString output;
    FormatLogMessage(type, nLevel, pszDate, pszTime, pszThreadId, pszThreadName, pszModule, pszMessage, output);

    if (m_bRedirectedToFile)
    {
        output += _T("\n");
        CStringA outputA = output;
        outputA.AnsiToOem();

        CriticalSection::SyncLock lock(m_cs);
        DWORD dwWritten;
        WriteFile(m_hConsole, (LPCSTR)outputA, (DWORD)outputA.GetLength(), &dwWritten, NULL);
    }
    else
    {
#ifndef _UNICODE
        output.AnsiToOem();
#endif
        CriticalSection::SyncLock lock(m_cs);
        SetConsoleTextAttribute(m_hConsole, color);
        DWORD dwWritten;
        WriteConsole(m_hConsole, (LPCTSTR)output, (DWORD)output.GetLength(), &dwWritten, NULL);

        SetConsoleTextAttribute(m_hConsole, m_info.wAttributes);
        WriteConsole(m_hConsole, _T("\n"), 1, &dwWritten, NULL);
    }
}
コード例 #2
0
ファイル: Dummy.cpp プロジェクト: svn2github/xps2img
int APIENTRY _tWinMain(
					HINSTANCE	hInstance,
					HINSTANCE	/*hPrevInstance*/,
					LPTSTR		/*lpCmdLine*/,
					int			/*nCmdShow*/)
#endif
{
#ifndef EMPTY
	TCHAR szPath[MAX_PATH * 3];

	*szPath = 0;

	GetCurrentDirectory(sizeof(szPath)/sizeof(szPath[0]), szPath);

#ifndef _CONSOLE
	CString strCaption(MAKEINTRESOURCE(IDS_CAPTION));
#endif

	CString strText;
	strText.Format(IDS_TEXT, szPath, GetCommandLine());

#ifdef _CONSOLE
	strText.AnsiToOem();
	_putts(strText);
#else // _WINDOWS

	// We have to create window in order to show message box.
	// Otherwise it won't be shown on XP SP2 + latest updates.

	INITCOMMONCONTROLSEX initCtrls = { sizeof(INITCOMMONCONTROLSEX), 0 };
	ATLVERIFY(InitCommonControlsEx(&initCtrls));

	HWND hwnd = CreateWindow(_T("button"), _T(""), WS_OVERLAPPED | BS_PUSHBUTTON, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
	ATLASSERT(hwnd != NULL);

	ATLVERIFY(MessageBox(hwnd, strText, strCaption, MB_OK | MB_ICONINFORMATION | MB_TOPMOST | MB_SETFOREGROUND));

	ATLVERIFY(DestroyWindow(hwnd));
#endif // _WINDOWS
#else // EMPTY
	hInstance;
#endif // EMPTY
	return 0;
}