Artifact 45f14add3bfa4c0a508fef2963704e408821bebc
1 //--- K.I.LIB ---
2 // kl_app.h : application class for K.I.LIB
3
4 #ifndef AFX_KIAPP_H__AC24C8AF_2187_4873_83E8_AB4F2325017B__INCLUDED_
5 #define AFX_KIAPP_H__AC24C8AF_2187_4873_83E8_AB4F2325017B__INCLUDED_
6
7 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
8 // 汎用アプリケーションクラス
9
10 class kiApp
11 {
12 friend kiApp* app();
13 friend void kilib_startUp();
14
15 public: //-- 外向きインターフェイス --------------------------
16
17 // インスタンス
18 HINSTANCE inst() const
19 {
20 return m_hInst;
21 }
22
23 // メインウインドウ
24 HWND mainhwnd() const
25 {
26 return m_pMainWnd ? m_pMainWnd->hwnd() : NULL;
27 }
28 kiWindow* mainwnd() const
29 {
30 return m_pMainWnd;
31 }
32 void setMainWnd( kiWindow* wnd )
33 {
34 m_pMainWnd = wnd;
35 }
36
37 // OSバージョン
38 const OSVERSIONINFO& osver() const
39 {
40 return m_OsVer;
41 }
42
43 // メッセージボックス
44 int msgBox( const char* msg, const char* caption=NULL, UINT type=MB_OK )
45 {
46 return ::MessageBox( mainhwnd(), msg, caption, type );
47 }
48
49 // シェルのアロケータでメモリ解放
50 void shellFree( void* ptr ) const
51 {
52 m_pShellAlloc->Free( ptr );
53 }
54
55 // 仮想コード vKey のキーは押されているか?
56 static bool keyPushed( int vKey )
57 {
58 return( 0!=(::GetAsyncKeyState( vKey )>>15) );
59 }
60
61 // CommonControl / OLE 初期化
62 void shellInit()
63 {
64 if( !m_bShellInit )
65 {
66 ::InitCommonControls();
67 ::OleInitialize( NULL );
68 m_bShellInit = true;
69 }
70 }
71
72 #ifdef KILIB_LOG
73 void log( const char* str )
74 {
75 if( !m_log.isOpened() )
76 {
77 kiPath logtxt( kiPath::Exe ); logtxt += "log.txt";
78 m_log.open( logtxt, false );
79 }
80 m_log.write( str, ki_strlen(str) );
81 m_log.write( "\r\n", 2 );
82 }
83 #endif
84
85 protected: //-- 派生クラス向け -----------------------------
86
87 // 起動時に呼ばれる関数。必須。
88 virtual void run( kiCmdParser& cmd ) = 0;
89
90 protected: //-- 内部処理 -----------------------------------
91
92 kiApp()
93 {
94 st_pApp = this;
95 m_hInst = ::GetModuleHandle( NULL );
96 m_pMainWnd = NULL;
97 m_bShellInit = false;
98 m_OsVer.dwOSVersionInfoSize = sizeof( m_OsVer );
99 ::GetVersionEx( &m_OsVer );
100 ::SHGetMalloc( &m_pShellAlloc );
101 }
102
103 protected:
104
105 virtual ~kiApp()
106 {
107 m_pShellAlloc->Release();
108 if( m_bShellInit )
109 ::OleUninitialize();
110 }
111
112 private:
113
114 HINSTANCE m_hInst;
115 IMalloc* m_pShellAlloc;
116 bool m_bShellInit;
117 OSVERSIONINFO m_OsVer;
118 kiWindow* m_pMainWnd;
119 static kiApp* st_pApp;
120 #ifdef KILIB_LOG
121 kiFile m_log;
122 #endif
123 };
124
125 #endif