#include <map>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
template<typename F, typename S>
class value_equal
{
private:
S second;
public:
value_equal(const S& s) : second(s){}
bool operator() (pair<const F, S> elem)
{ return elem.second == second; }
};
typedef map<int, string> isMap;
typedef isMap::value_type isValType;
typedef isMap::iterator isMapItor;
void main()
{
isMap c;
c.insert(isValType(100, "one Hundred"));
c.insert(isValType(3, "Three"));
c.insert(isValType(150, "one Hundred Fifty"));
c.insert(isValType(99, "Ninety Nine"));
for(isMapItor itor = c.begin(); itor != c.end(); ++itor)
cout << "Key = " << (*itor).first << ", Value = " << (*itor).second << endl;
cout << "Key 3 displays value " << c[3].c_str() << endl;
c[123] = "One Hundred Twenty Three";
isMapItor pos = c.find(123);
if(pos != c.end())
c.erase(pos);
pos = find_if(c.begin(), c.end(), value_equal<int, string>("Ninety Nine"));
if(pos != c.end())
c.erase(pos);
for(isMapItor itor = c.begin(); itor != c.end();)
{
if(itor->second == "Three")
c.erase(itor++);
else
++itor;
}
cout << endl;
for(isMapItor itor = c.begin(); itor != c.end(); ++itor)
cout << "Key = " << (*itor).first << ", Value = " << (*itor).second << endl;
}
블로그
-
std::map
-
Debug Console class
H
class CDebugConsole : public CSingleton<CDebugConsole> { friend class CSingleton<CDebugConsole>; private: HANDLE m_hOut; HWND m_hWnd; public: enum { CSL_TR = 0, CSL_TL, CSL_BR, CSL_BL }; // Edge private: CDebugConsole() { this->Initialize(); } virtual ~CDebugConsole() { this->Release(); } VOID Initialize(); VOID Release(); VOID GetConsoleHwnd( HWND& _hWnd ); VOID GetEdgePosition( DWORD _Edge ); public: // CDebugConsole::m_Console().Message( " " ); VOID Message( LPWSTR str ); VOID Message( LPSTR str ); // CDebugConsole::m_Console().Messagef( "%s %d %f", char, int, float ); VOID Messagef( LPWSTR str, ... ); VOID Messagef( LPSTR str, ... ); // 모니터가 수평 배치가 아닌 수직 배치일때는 지원하지 않음 VOID SetPosition( DWORD _dEdge, BOOL _bTopMost ); }; CPP
#include "stdafx.h" #include "DebugConsole.h" VOID CDebugConsole::Initialize() { if( !AllocConsole() ) { MessageBox( NULL, L"CDebugConsole::AllocConsole()", NULL, MB_OK ); return; } if( ( m_hOut = CreateFile(L"CONOUT$",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,0) ) == INVALID_HANDLE_VALUE ) { MessageBox( NULL, L"CDebugConsole::Initialize() failed", NULL, MB_OK ); return; } SetConsoleTitle( L"1.0v" ); } VOID CDebugConsole::Release() { CloseHandle( m_hOut ); FreeConsole(); } VOID CDebugConsole::GetConsoleHwnd( HWND* _hWnd ) { const INT BUFSIZE = 1024; TCHAR pszNewWindowTitle[ BUFSIZE ]; // Contains fabricated TCHAR pszOldWindowTitle[ BUFSIZE ]; // Contains original // Fetch current window title. GetConsoleTitle(pszOldWindowTitle, BUFSIZE); wsprintf( pszNewWindowTitle, L"%d/%d", GetTickCount(), GetCurrentProcessId() ); // Change current window title. SetConsoleTitle(pszNewWindowTitle); // Ensure window title has been updated. Sleep(40); // Look for NewWindowTitle. _hWnd = FindWindow(NULL, pszNewWindowTitle); // Restore original window title. SetConsoleTitle(pszOldWindowTitle); } VOID CDebugConsole::GetEdgePosition( DWORD _Edge ) { // Get Display Impormation HDC hDC; hDC = CreateDC( TEXT("DISPLAY"), NULL, NULL, NULL ); INT iWidth = GetDeviceCaps( hDC, HORZRES ); INT iHeight = GetDeviceCaps( hDC, VERTRES ); INT iNumMonitor = GetSystemMetrics( SM_CMONITORS); DeleteDC( hDC ); this->;Messagef( L"모니터 갯수 : %dn 해상도 : %d * %dn", iNumMonitor, iWidth, iHeight ); iWidth *= iNumMonitor; RECT rt; GetClientRect( m_hWnd, *rt ); INT x = 0, y = 0; switch( _Edge ) { case CSL_TL: x = 0; y = 0; break; case CSL_TR: x = iWidth - rt.right; y = 0; break; case CSL_BL: x = 0; y = iHeight - rt.bottom; break; case CSL_BR: x = iWidth - rt.right; y = iHeight - rt.bottom; break; } MoveWindow( m_hWnd, x, y, rt.right, rt.bottom, FALSE ); } VOID CDebugConsole::Message( LPWSTR _str ) { DWORD sz; // 멀티바이트 ->; 유니코드 CHAR str[ 256 ]; WideCharToMultiByte( CP_ACP, 0, _str, -1, str, 256, NULL, NULL ); // End WriteFile( m_hOut, str, strlen( str ), *sz, NULL ); } VOID CDebugConsole::Message( LPSTR _str ) { DWORD sz; WriteFile( m_hOut, _str, strlen( _str ), *sz, NULL ); } VOID CDebugConsole::Messagef( LPWSTR _str, ... ) { // 멀티바이트 -> 유니코드 CHAR str[ 256 ]; WideCharToMultiByte( CP_ACP, 0, _str, -1, str, 256, NULL, NULL ); // End va_list argp; CHAR szBuf[ 1024 ]; va_start( argp, _str ); vsprintf_s( szBuf, str, argp ); va_end( argp ); DWORD sz; WriteFile( m_hOut, szBuf, strlen( szBuf ), *sz, NULL ); } VOID CDebugConsole::Messagef( LPSTR _str, ... ) { va_list argp; CHAR szBuf[ 1024 ]; va_start( argp, _str ); vsprintf_s( szBuf, _str, argp ); va_end( argp ); DWORD sz; WriteFile( m_hOut, szBuf, strlen( szBuf ), *sz, NULL ); } VOID CDebugConsole::SetPosition( DWORD _dEdge, BOOL _bTopMost ) { // Get HWND GetConsoleHwnd( m_hWnd ); // Set Position GetEdgePosition( _dEdge ); // Set TopMost if( _bTopMost ) SetWindowPos( m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); else SetWindowPos( m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); } -
Win-base source
WinMain+Singleton
#pragma once class CWndEx : public CSingleton<CWndEx> { private: // ENUM // PRE friend class CSingleton; // MEMBER HWND m_hWnd; HINSTANCE m_hInstance; LPWSTR m_lpszTitle; CWndEx(); ~CWndEx(); VOID Clear(); VOID Create(); VOID Destory(); VOID Render(); VOID Update(); // Method ATOM RegisterClass( WNDPROC, LPTSTR, UINT ); BOOL InitInstance( INT ); static LRESULT CALLBACK FramWndProc( HWND, UINT, WPARAM, LPARAM ); VOID CreateStatusWindowEx( HWND ); VOID SetStatusRGB(); // MESSAGE // Frame MESSAGE VOID OnCommand( HWND, INT, HWND, UINT ); BOOL OnCreate( HWND, LPCREATESTRUCT ); VOID OnDestroy( HWND ); public: static INT MessageLoop( HINSTANCE = NULL ); };