输入法状态控制 ( IME )

来源:互联网 发布:网络借贷合法逾期费用 编辑:程序博客网 时间:2024/04/29 13:33

//下面的代码用来屏蔽某一个控件的输入法状态。 

 

HIMC  m_hImc;        //  全局或者成员变量 

 

//  Function  for  Disabling  IME 

void  CMyDialog::DisableIME() 

{ 

         HWND  hWnd  =  GetDlgItem(IDC_EDIT1)->m_hWnd; 

         if  (hWnd  &&  IsWindow(hWnd)) 

         { 

                   //  Get  input  context  for  backup.   

                   m_hImc  =  ImmGetContext(hWnd); 

 

                   //  Remove  association  the  testing   

                   if  (m_hImc) 

                                        ImmAssociateContext(hWnd,  NULL); 

 

                   //  Release  input  context 

                   ImmReleaseContext(hWnd,  m_hImc); 

                   ::SetFocus(hWnd); 

         } 

} 

 

 

//  Function  for  Enabling  IME 

void  CMyDlg::EnableIME()   

{ 

         HWND  hWnd  =  GetDlgItem(IDC_EDIT1)->m_hWnd; 

         if  (hWnd  &&  IsWindow(hWnd)) 

         { 

                   //  Enable  IME 

                   if  (m_hImc) 

                   { 

                                        //  Associate  the  input  context  with  testing  window 

                                        ImmAssociateContext(hWnd,  m_hImc); 

                                        m_hImc  =  NULL; 

                   } 

 

                   ::SetFocus(hWnd); 

         } 

} 

 

原创粉丝点击