jovibor / HexCtrl

Fully-featured Hex Control written in C++/MFC.
Other
164 stars 61 forks source link

Chinese charset question? #40

Closed gzhwl closed 3 years ago

gzhwl commented 3 years ago

Hello, I'm a Chinese developer, I use HexCtrl in my MFC App, using it with 'Building From The Sources' type,create window with these code:

RECT rcClient = { 0 }; ::GetClientRect(GetSafeHwnd(), &rcClient); HEXCREATESTRUCT hcs; hcs.enCreateMode = EHexCreateMode::CREATE_CHILD; hcs.hwndParent = m_hWnd; hcs.rect = rcClient; if (m_HexCtrl->Create(hcs)) { // Set China locale m_HexCtrl->SetEncoding(936); // Init string whith Chinese Char std::string str = "0123456789,零一二三四五六七八九十,零壹贰叁肆伍陆柒捌玖拾"; HEXDATASTRUCT hds; hds.pData = (std::byte*)str.data(); hds.ullDataSize = str.size();

  m_HexCtrl->SetData(hds);
  m_HexCtrl->SetEncoding(936);
  // INT dpiX = GetDeviceCaps(hScreen, LOGPIXELSX);
  // float m_dScale = dpiX * 100.00f / 96.00f;
  // m_dScale = 2.0
  // m_HexCtrl->SetFontSize(UINT(14 * 2));

}

these code compiled ok, But after I run the App and click the data shown in the HEX View wnd, The data Changed random,is it a bug?

jovibor commented 3 years ago

Hi, you are using a local stack variable std::string str = to set the data, no wonder it doesn't work. It destroys as soon as it goes out of the declaration scope. You must either make it static or declare it as a class member (or global).

gzhwl commented 3 years ago

Thanks, I changed it to 'static' declare, It works !