{"id":36,"date":"2013-02-12T11:06:54","date_gmt":"2013-02-12T02:06:54","guid":{"rendered":"http:\/\/yoonhada.netai.net\/?p=36"},"modified":"2023-12-28T04:32:23","modified_gmt":"2023-12-27T19:32:23","slug":"debug-console-class","status":"publish","type":"post","link":"http:\/\/yoonhada.com\/?p=36","title":{"rendered":"Debug Console class"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">H<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class CDebugConsole : public CSingleton&lt;CDebugConsole>\n{\nfriend class CSingleton&lt;CDebugConsole>;\n\nprivate:\nHANDLE m_hOut;\nHWND m_hWnd;\n\npublic:\nenum { CSL_TR = 0, CSL_TL, CSL_BR, CSL_BL }; \/\/ Edge\n\nprivate:\nCDebugConsole()\n{\nthis->Initialize();\n}\nvirtual ~CDebugConsole()\n{\nthis->Release();\n}\n\nVOID Initialize();\nVOID Release();\n\nVOID GetConsoleHwnd( HWND&amp;amp; _hWnd );\nVOID GetEdgePosition( DWORD _Edge );\n\npublic:\n\/\/ CDebugConsole::m_Console().Message( \" \" );\nVOID Message( LPWSTR str );\nVOID Message( LPSTR str );\n\n\/\/ CDebugConsole::m_Console().Messagef( \"%s %d %f\", char, int, float );\nVOID Messagef( LPWSTR str, ... );\nVOID Messagef( LPSTR str, ... );\n\n\/\/ \ubaa8\ub2c8\ud130\uac00 \uc218\ud3c9 \ubc30\uce58\uac00 \uc544\ub2cc \uc218\uc9c1 \ubc30\uce58\uc77c\ub54c\ub294 \uc9c0\uc6d0\ud558\uc9c0 \uc54a\uc74c\nVOID SetPosition( DWORD _dEdge, BOOL _bTopMost );\n};\n\ufeff<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">CPP<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#include \"stdafx.h\"\n#include \"DebugConsole.h\"\n\nVOID CDebugConsole::Initialize()\n{\n    if( !AllocConsole() )\n    {\n        MessageBox( NULL, L\"CDebugConsole::AllocConsole()\", NULL, MB_OK );\n        return;\n    }\n\n    if( ( m_hOut = CreateFile(L\"CONOUT$\",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,0) ) == INVALID_HANDLE_VALUE )\n    {\n        MessageBox( NULL, L\"CDebugConsole::Initialize() failed\", NULL, MB_OK );\n        return;\n    }\n\n    SetConsoleTitle( L\"1.0v\" );\n}\n\nVOID CDebugConsole::Release()\n{\n    CloseHandle( m_hOut );\n    FreeConsole();\n}\n\nVOID CDebugConsole::GetConsoleHwnd( HWND* _hWnd )\n{\n    const INT BUFSIZE = 1024;\n\n    TCHAR pszNewWindowTitle[ BUFSIZE ]; \/\/ Contains fabricated\n    TCHAR pszOldWindowTitle[ BUFSIZE ]; \/\/ Contains original\n\n    \/\/ Fetch current window title.\n    GetConsoleTitle(pszOldWindowTitle, BUFSIZE);\n\n    wsprintf( pszNewWindowTitle, L\"%d\/%d\", GetTickCount(), GetCurrentProcessId() );\n\n    \/\/ Change current window title.\n    SetConsoleTitle(pszNewWindowTitle);\n\n    \/\/ Ensure window title has been updated.\n    Sleep(40);\n\n    \/\/ Look for NewWindowTitle.\n    _hWnd = FindWindow(NULL, pszNewWindowTitle);\n\n    \/\/ Restore original window title.\n    SetConsoleTitle(pszOldWindowTitle);\n}\n\nVOID CDebugConsole::GetEdgePosition( DWORD _Edge )\n{\n    \/\/ Get Display Impormation\n    HDC hDC;\n    hDC = CreateDC( TEXT(\"DISPLAY\"), NULL, NULL, NULL );\n    INT iWidth = GetDeviceCaps( hDC, HORZRES );\n    INT iHeight = GetDeviceCaps( hDC, VERTRES );\n    INT iNumMonitor = GetSystemMetrics( SM_CMONITORS);\n    DeleteDC( hDC );\n\n    this->;Messagef( L\"\ubaa8\ub2c8\ud130 \uac2f\uc218 : %dn \ud574\uc0c1\ub3c4 : %d * %dn\", iNumMonitor, iWidth, iHeight );\n\n    iWidth *= iNumMonitor;\n\n    RECT rt;\n    GetClientRect( m_hWnd, *rt );\n    INT x = 0, y = 0;\n\n    switch( _Edge )\n    {\n        case CSL_TL:\n            x = 0;\n            y = 0;\n            break;\n        case CSL_TR:\n            x = iWidth - rt.right;\n            y = 0;\n            break;\n        case CSL_BL:\n            x = 0;\n            y = iHeight - rt.bottom;\n            break;\n        case CSL_BR:\n            x = iWidth - rt.right;\n            y = iHeight - rt.bottom;\n            break;\n    }\n\n    MoveWindow( m_hWnd, x, y, rt.right, rt.bottom, FALSE );\n}\n\nVOID CDebugConsole::Message( LPWSTR _str )\n{\n    DWORD sz;\n\n    \/\/ \uba40\ud2f0\ubc14\uc774\ud2b8 ->; \uc720\ub2c8\ucf54\ub4dc\n    CHAR str[ 256 ];\n    WideCharToMultiByte( CP_ACP, 0, _str, -1, str, 256, NULL, NULL );\n    \/\/ End\n\n    WriteFile( m_hOut, str, strlen( str ), *sz, NULL );\n}\n\nVOID CDebugConsole::Message( LPSTR _str )\n{\n    DWORD sz;\n\n    WriteFile( m_hOut, _str, strlen( _str ), *sz, NULL );\n}\n\nVOID CDebugConsole::Messagef( LPWSTR _str, ... )\n{\n    \/\/ \uba40\ud2f0\ubc14\uc774\ud2b8 -> \uc720\ub2c8\ucf54\ub4dc\n    CHAR str[ 256 ];\n    WideCharToMultiByte( CP_ACP, 0, _str, -1, str, 256, NULL, NULL );\n    \/\/ End\n\n    va_list argp;\n    CHAR szBuf[ 1024 ];\n\n    va_start( argp, _str );\n    vsprintf_s( szBuf, str, argp );\n    va_end( argp );\n\n    DWORD sz;\n    WriteFile( m_hOut, szBuf, strlen( szBuf ), *sz, NULL );\n}\n\nVOID CDebugConsole::Messagef( LPSTR _str, ... )\n{\n    va_list argp;\n    CHAR szBuf[ 1024 ];\n\n    va_start( argp, _str );\n    vsprintf_s( szBuf, _str, argp );\n    va_end( argp );\n\n    DWORD sz;\n    WriteFile( m_hOut, szBuf, strlen( szBuf ), *sz, NULL );\n}\n\nVOID CDebugConsole::SetPosition( DWORD _dEdge, BOOL _bTopMost )\n{\n    \/\/ Get HWND\n    GetConsoleHwnd( m_hWnd );\n\n    \/\/ Set Position\n    GetEdgePosition( _dEdge );\n\n    \/\/ Set TopMost\n    if( _bTopMost )\n    SetWindowPos( m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );\n    else\n    SetWindowPos( m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );\n\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>H CPP<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[83],"tags":[64,65],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-archive","tag-programming","tag-windows-api"],"_links":{"self":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/posts\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=36"}],"version-history":[{"count":2,"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":1614,"href":"http:\/\/yoonhada.com\/index.php?rest_route=\/wp\/v2\/posts\/36\/revisions\/1614"}],"wp:attachment":[{"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yoonhada.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}