C:\home\SVGCats_src\src\InputDlg1.cpp
1|// InputDlg1.cpp : インプリメンテーション ファイル 2|// 3| 4|#include "mixer_precomp.h" 5|#ifdef USES_MXP_AUTOINC 6| #include "SVGCat.ah" 7|#endif 8| 9|#ifdef _DEBUG 10|#define new DEBUG_NEW 11|#undef THIS_FILE 12|static char THIS_FILE[] = __FILE__; 13|#endif 14| 15|///////////////////////////////////////////////////////////////////////////// 16|// CInputDlg1 ダイアログ 17| 18| 19|CInputDlg1::CInputDlg1(CWnd* pParent /*=NULL*/) 20| : CDialog(CInputDlg1::IDD, pParent) 21|{ 22| //{{AFX_DATA_INIT(CInputDlg1) 23| m_Msg = _T(""); 24| m_Text = _T(""); 25| //}}AFX_DATA_INIT 26| m_SelStart = 0; 27| m_SelEnd = -1; 28| m_bPath = false; 29| m_Filter = "All Files (*.*)|*.*||"; 30| m_bSetAtCursor = true; 31| m_XY.x = 0; m_XY.y = 0; 32| m_PenInputPanel = NULL; 33| m_bActive = true; 34|} 35| 36| 37|void CInputDlg1::DoDataExchange(CDataExchange* pDX) 38|{ 39| CDialog::DoDataExchange(pDX); 40| //{{AFX_DATA_MAP(CInputDlg1) 41| DDX_Control(pDX, IDC_Cut, m_CutBtn); 42| DDX_Control(pDX, IDC_Text, m_TextCtrl); 43| DDX_Control(pDX, IDC_Paste, m_PasteBtn); 44| DDX_Control(pDX, IDC_Copy, m_CopyBtn); 45| DDX_Control(pDX, IDC_Browse, m_Browse); 46| DDX_Text(pDX, IDC_Msg, m_Msg); 47| DDX_Text(pDX, IDC_Text, m_Text); 48| //}}AFX_DATA_MAP 49|} 50| 51| 52|BEGIN_MESSAGE_MAP(CInputDlg1, CDialog) 53| //{{AFX_MSG_MAP(CInputDlg1) 54| ON_BN_CLICKED(IDC_Browse, OnBrowse) 55| ON_BN_CLICKED(IDC_Paste, OnPaste) 56| ON_BN_CLICKED(IDC_Copy, OnCopy) 57| ON_BN_CLICKED(IDC_Cut, OnCut) 58| //}}AFX_MSG_MAP 59|END_MESSAGE_MAP() 60| 61|///////////////////////////////////////////////////////////////////////////// 62|// CInputDlg1 メッセージ ハンドラ 63| 64|BOOL CInputDlg1::OnInitDialog() 65|{ 66| CDialog::OnInitDialog(); 67| CString s; 68| RECT rect; 69| POINT point; 70| int w, h; 71| int scr_w = GetSystemMetrics( SM_CXFULLSCREEN ); 72| int scr_h = GetSystemMetrics( SM_CYFULLSCREEN ); 73| char ss[256]; 74| 75| 76| /* ペン入力パネルを設定する */ 77|#if 0 78| if ( m_PenInputPanel != NULL ) { 79| BSTR s; 80| HRESULT hr; 81| 82| hr = m_PenInputPanel->put_AttachedEditWindow( (LONG_PTR)m_Text2Ctrl.GetHwnd() ); 83| if ( hr != 0 ) error(); 84| 85| s = SysAllocString( OLESTR("ALL") ); 86| hr = m_PenInputPanel->put_Factoid( s ); 87| SysFreeString( s ); 88| if ( hr != 0 ) error(); 89| 90| hr = m_PenInputPanel->EnableTsf( VARIANT_TRUE ); 91| if ( hr != 0 ) error(); 92| 93| hr = m_PenInputPanel->put_AutoShow( VARIANT_FALSE ); 94| if ( hr != 0 ) error(); 95| 96| hr = m_PenInputPanel->put_HorizontalOffset( -40 ); 97| if ( hr != 0 ) error(); 98| hr = m_PenInputPanel->put_VerticalOffset( 47 ); 99| if ( hr != 0 ) error(); 100| } 101|#endif 102| 103| 104| /* テキストボックスの初期化をする */ 105| if ( m_PenInputPanel == NULL ) { 106| m_TextCtrl.SetFocus(); 107| if ( m_SelStart == -1 && m_SelEnd == -1 ) { 108| m_TextCtrl.GetWindowText( s ); 109| m_TextCtrl.SetSel( s.GetLength(), s.GetLength() ); 110| } 111| else 112| m_TextCtrl.SetSel( m_SelStart, m_SelEnd ); 113| } 114| else { 115|#if 0 116| m_Text2Ctrl.SetFocus(); 117| if ( m_SelStart == -1 && m_SelEnd == -1 ) { 118| m_Text2Ctrl.SetSelStart( m_Text.GetLength() ); 119| m_Text2Ctrl.SetSelLength( 0 ); 120| } 121| else { 122| m_Text2Ctrl.SetText( m_Text ); 123| m_Text2Ctrl.SetSelStart( m_SelStart ); 124| if ( m_SelEnd < 0 ) 125| m_Text2Ctrl.SetSelLength( m_Text.GetLength() ); 126| else 127| m_Text2Ctrl.SetSelLength( m_SelEnd - m_SelStart ); 128| } 129|#endif 130| } 131| 132| m_CutBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Cut) ); 133| m_CopyBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Copy) ); 134| m_PasteBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Paste) ); 135| 136| m_ToolTip.Create( this ); 137| LoadString( AfxGetInstanceHandle(), ID_EDIT_COPY, ss, sizeof(ss) ); 138| StrX_cpy1Line( ss, sizeof(ss), ss, 2 ); 139| m_ToolTip.AddTool( GetDlgItem(IDC_Copy), ss ); 140| 141| LoadString( AfxGetInstanceHandle(), ID_EDIT_PASTE, ss, sizeof(ss) ); 142| StrX_cpy1Line( ss, sizeof(ss), ss, 2 ); 143| m_ToolTip.AddTool( GetDlgItem(IDC_Paste), ss ); 144| 145| GetWindowRect( &rect ); 146| if ( m_bSetAtCursor ) { 147| GetCursorPos( &point ); 148| point.x += 100; point.y += 80; 149| } 150| else { 151| point.x = m_XY.x; point.y = m_XY.y; 152| } 153| w = rect.right - rect.left; h = rect.bottom - rect.top; 154| rect.left = point.x - w / 2; rect.right = rect.left + w; 155| rect.top = point.y - h / 2; rect.bottom = rect.top + h; 156| if ( rect.right >= scr_w ) { rect.left -= rect.right - scr_w; rect.right = scr_w; } 157| if ( rect.bottom >= scr_h ) { rect.top -= rect.bottom - scr_h; rect.bottom = scr_h; } 158| if ( rect.left < 0 ) { rect.right += -rect.left; rect.left = 0; } 159| if ( rect.top < 0 ) { rect.bottom += -rect.top; rect.top = 0; } 160| MoveWindow( &rect ); 161| 162| m_Browse.ShowWindow( m_bPath ? SW_SHOW : SW_HIDE ); 163| 164| WinX_setIme( m_hWnd, false ); 165| 166|// m_TextCtrl.ShowWindow( m_PenInputPanel == NULL ? SW_SHOW : SW_HIDE ); 167| m_TextCtrl.ShowWindow( SW_SHOW ); 168|// m_Text2Ctrl.ShowWindow( m_PenInputPanel == NULL ? SW_HIDE : SW_SHOW ); 169| 170| return FALSE; // コントロールにフォーカスを設定しないとき、戻り値は TRUE となります 171| // 例外: OCX プロパティ ページの戻り値は FALSE となります 172|} 173| 174|void CInputDlg1::OnBrowse() 175|{ 176| CString s; 177| m_bActive = false; 178| 179| m_TextCtrl.GetWindowText( s ); 180| { 181| CFileDialog dlg( TRUE, NULL, s, OFN_HIDEREADONLY | OFN_EXPLORER, m_Filter ); 182| 183| if ( dlg.DoModal() == IDOK ) { 184| m_TextCtrl.SetWindowText( dlg.GetPathName() ); 185|// m_Text2Ctrl.SetText( dlg.GetPathName() ); 186| } 187| } 188| 189| m_bActive = true; 190| SetFocusToEdit(); 191|} 192| 193|void CInputDlg1::OnOK() 194|{ 195|#if 0 196| if ( m_PenInputPanel != NULL ) { 197| VARIANT_BOOL busy; 198| CString s; 199| 200| m_PenInputPanel->CommitPendingInput(); 201| for (;;) { 202| m_PenInputPanel->get_Visible( &busy ); 203| if ( ! busy ) break; 204| Sleep(50); 205| } 206| 207|// s = m_Text2Ctrl.GetText(); 208| m_TextCtrl.SetWindowText( s ); 209| } 210|#endif 211| 212| 213| CDialog::OnOK(); 214|} 215| 216|void CInputDlg1::OnCut() 217|{ 218|// CWnd* editCtrl = ( m_PenInputPanel == NULL ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl; 219| CWnd* editCtrl = (CWnd*)&m_TextCtrl; 220| 221| GetKeyboardState( m_Keys ); 222| m_Keys[VK_CONTROL] = 128; 223| SetKeyboardState( m_Keys ); 224| editCtrl->PostMessage( WM_KEYDOWN, 'X', 0 ); 225| this->PostMessage( WM_COMMAND, CInputML_KeyPosted, 0 ); 226| SetFocusToEdit(); 227|} 228| 229|void CInputDlg1::OnCopy() 230|{ 231|// CWnd* editCtrl = ( m_PenInputPanel == NULL ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl; 232| CWnd* editCtrl = (CWnd*)&m_TextCtrl; 233| 234| GetKeyboardState( m_Keys ); 235| m_Keys[VK_CONTROL] = 128; 236| SetKeyboardState( m_Keys ); 237| editCtrl->PostMessage( WM_KEYDOWN, 'C', 0 ); 238| this->PostMessage( WM_COMMAND, CInputML_KeyPosted, 0 ); 239| SetFocusToEdit(); 240|} 241| 242|void CInputDlg1::OnPaste() 243|{ 244|// CWnd* editCtrl = ( m_PenInputPanel == NULL ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl; 245| CWnd* editCtrl = (CWnd*)&m_TextCtrl; 246| 247| GetKeyboardState( m_Keys ); 248| m_Keys[VK_CONTROL] = 128; 249| SetKeyboardState( m_Keys ); 250| editCtrl->PostMessage( WM_KEYDOWN, 'V', 0 ); 251| this->PostMessage( WM_COMMAND, CInputML_KeyPosted, 0 ); 252| SetFocusToEdit(); 253|} 254| 255|void CInputDlg1::SetFocusToEdit() 256|{ 257|// HRESULT hr; 258|// CWnd* editCtrl = ( m_PenInputPanel == NULL ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl; 259| CWnd* editCtrl = (CWnd*)&m_TextCtrl; 260| 261| editCtrl->SetFocus(); 262| 263|#if 0 264| if ( m_PenInputPanel != NULL ) { 265| m_TextCtrl.ShowWindow( SW_HIDE ); 266| m_Text2Ctrl.ShowWindow( SW_SHOW ); 267| 268| hr = m_PenInputPanel->put_Visible( TRUE ); 269| if ( hr != 0 ) return; /* コントロールが準備できていない */ 270| } 271|#endif 272|} 273| 274| 275| 276|BOOL CInputDlg1::OnCommand(WPARAM wParam, LPARAM lParam) 277|{ 278| switch ( wParam ) { 279| 280| case CInputML_KeyPosted: 281| 282| /* Ctrl キーを押さない状態にする */ 283| GetKeyboardState( m_Keys ); 284| m_Keys[VK_CONTROL] = 0; 285| SetKeyboardState( m_Keys ); 286| break; 287| } 288| 289| return CDialog::OnCommand(wParam, lParam); 290|} 291| 292|