IME mode convert

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thanhtien
    New Member
    • Apr 2010
    • 7

    #1

    IME mode convert

    I'm wrinting a program that is Japanese on screen keyboard. When I use the ImmSetOpenStatu s function to open IME for the focus windows as MS words... But it have been always failed. This is my code:
    Code:
    BOOL COnscreenKeyboardDlg::SetImeSwitchON() 
    {
    	m_fLog.initLogFile();
    	HWND wnd = ::GetForegroundWindow();
    	if(IsWindow(wnd))
    	{
    		if(!AttachThreadInput(GetWindowThreadProcessId(m_hWnd,NULL),GetWindowThreadProcessId(wnd,NULL),TRUE)){
    			m_fLog.putToLogFile( __FILE__, __LINE__, "AttachThreadInput failed\n");
    		}
    		::SetFocus(wnd);
    		char cWindowsName[MAX_PATH];
    		::GetWindowText(wnd,cWindowsName,MAX_PATH);
    		m_fLog.putToLogFile( __FILE__, __LINE__, cWindowsName);
    		HIMC hIMC = ImmGetContext(wnd);
    		if(!ImmGetOpenStatus(hIMC)){
    			if(!ImmSetOpenStatus(hIMC, TRUE)){
    				m_fLog.putToLogFile( __FILE__, __LINE__, "ImmSetOpenStatus failed\n");
    			}else{
    				m_fLog.putToLogFile( __FILE__, __LINE__, "ImmSetOpenStatus successed\n");
    			}
    		}	
    		ImmReleaseContext( wnd, hIMC);
    	}else{
    		m_fLog.putToLogFile( __FILE__, __LINE__, "IsWindow(wnd) failed\n");
    	}
    	m_fLog.closeLogFile();
    	return 0;
    }
    I dont know where is wrong. please help me.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You are not checking any return values to se if things are working.

    Hev you stepped though this with your debugger?

    Comment

    • thanhtien
      New Member
      • Apr 2010
      • 7

      #3
      Hi weaknessforcats ,
      Thank you for your answer.
      Yes I have debugged step by step and put it to the log file. It always failed at the ImmSetOpenStatu s function.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        HIMC hIMC = ImmGetContext(w nd);
        Does ImmGetContext return a non-null HIMC? You don't check.

        Comment

        • thanhtien
          New Member
          • Apr 2010
          • 7

          #5
          Hi weaknessforcats ,
          Thank you for your show. really, HIMC hIMC = ImmGetContext(w nd); was return NULL. But wnd is not NULL. why it return NULL? Can you teach me to correct it?

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            Are you using a version of Windows that supports this feature?

            Comment

            • thanhtien
              New Member
              • Apr 2010
              • 7

              #7
              yes, I'm using Windows XP japanese version. It is supporting IME.

              Comment

              • weaknessforcats
                Recognized Expert Expert
                • Mar 2007
                • 9214

                #8
                If your HWND is valid and you still get a NULL HIMC then you have a question for Microsoft.

                Comment

                • thanhtien
                  New Member
                  • Apr 2010
                  • 7

                  #9
                  Hi weaknessforcats ,
                  Thank you for your help. I have solved it.

                  Comment

                  • weaknessforcats
                    Recognized Expert Expert
                    • Mar 2007
                    • 9214

                    #10
                    I'm glad to here that. But I am curious as to what the problem was. Can you share your solution?

                    Comment

                    • thanhtien
                      New Member
                      • Apr 2010
                      • 7

                      #11
                      Hi weaknessforcats ,
                      The problem was my application can not switch IME mode of another application. So that ImmGetContext(w nd) always return null.
                      My solution is create global keyboard hook and implement the IME API in it. That's all.

                      Comment

                      Working...