Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,

I created a dialog (which has Edit Control) on it in Win 32. I derived the dialog from CDialogImpl class.

I am facing a problem in entering Unicode characters on the Edit box control.

In designer, when i enter characters in Unicode (say Hindi Language), it is showing correctly.

But when i run the program, the same edit box shows "?".

The code for the Dialog Box looks something like below :

The Header (.h) file :

C++
#pragma once
    #include "resource.h"

    // CEnterPasswordDlg dialog
    class CEnterPasswordDlg : public CDialogImpl<CEnterPasswordDlg>
    {

    public:
    	CEnterPasswordDlg();   // standard constructor
    	virtual ~CEnterPasswordDlg();

    	// Dialog Data
    	enum { IDD = IDD_DIALOG_ENTER_PASSWORD };

    	WTL::CString GetEnteredPassword() { return m_strPasswordEntered; };

    	LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    	LRESULT OnCancelCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
    	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

    protected:

    	BEGIN_MSG_MAP(CEnterPasswordDlg)
    		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
    		COMMAND_ID_HANDLER(IDOK, OnCloseCmd)
    		COMMAND_ID_HANDLER(IDCANCEL, OnCancelCmd)
    	END_MSG_MAP()

    private:

    	WTL::CString m_strPasswordEntered;
    };

The Implementation File (CPP File) :

C++
// EnterPasswordDlg.cpp : implementation file
    //

    #include "stdafx.h"
    #include "EnterPasswordDlg.h"

    // CEnterPasswordDlg dialog
    //class CFullSr
    CEnterPasswordDlg::CEnterPasswordDlg()
    	: m_strPasswordEntered(_T(""))
    {
    }

    CEnterPasswordDlg::~CEnterPasswordDlg()
    {
    }

    // CEnterPasswordDlg message handlers

    LRESULT CEnterPasswordDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
    {
    	char cPassword[MAX_PATH];
    	GetDlgItemText(IDC_EDIT_PASSWORD, cPassword, MAX_PATH);

    	m_strPasswordEntered = cPassword;	

    	EndDialog(wID);
    		
    	return 0;
    }

    LRESULT CEnterPasswordDlg::OnCancelCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
    {
    	EndDialog(wID);
    	return 0;
    }

    LRESULT CEnterPasswordDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    {
    	CenterWindow();

    	return TRUE;
    }



Could anyone tell me what could be wrong ?

How can i see the Unicode characters that i actually enter in the dialog.

My project is not an Unicode project. I didn't add the Macro "_UNICODE".

Is it possible without adding that Macro to the project properties ?
It is fine for me if i could just add Unicode properties to this dialog alone.

Any help will be greatly appreciated

Thanks and Regards,

Kishor Reddy
Posted

1 solution

For Unicode you MUST use the unicode functions and types. Microsft standard is that they have an additional W on the end.
C++
wchar_t cPassword[MAX_PATH];
GetDlgItemTextW(IDC_EDIT_PASSWORD, cPassword, MAX_PATH);

My advice is to transform your project to unicode to get rid of this stuff. It is done in some hours of annoying code changes like about, but: THEN YOU ARE DONE ;-)
 
Share this answer
 
Comments
[no name] 6-May-15 4:54am    
Even i thought of converting the whole project to Unicode. But this is a legacy application and this single change is affecting many areas (which i do not want to do at this stage).

I tried the below thing ...

// Don't use the dialog designer, instead use CreateWindowW
HWND editWnd = CreateWindowW(L"EDIT", L"Initial Text", WS_VISIBLE | WS_CHILD | WS_BORDER, 10, 10, 200, 20, ParentHWnd, (HMENU)editId, 0, 0);

SetWindowTextW(editWnd, L"Hindi Text");

wchar_t buf[256];
GetWindowTextW(editWnd, buf, _countof(buf));

BUt i could not get the parent HWND ... Even calling GetParent() is making the control place on the parent window instead of child window

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900