如何在编辑控件上使用 EM_SETHANDLE? [英] How to use EM_SETHANDLE on edit control?

查看:32
本文介绍了如何在编辑控件上使用 EM_SETHANDLE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何正确使用 EM_SETHANDLE 机制来设置编辑控件的文本.获取和设置窗口文本对于我的应用程序来说太慢了.

I am unable to figure out how to properly use the EM_SETHANDLE mechanism to set the text for an edit control. Get and Set window text will be too slow for my application.

从文档中我了解到分配的缓冲区将被控件起诉,并且它部分对我有用.

From the documentation I understand that the allocated buffer will be sued by the control and it works partially for me.

在控件中输入文本时,它会在缓冲区中看到,但是当使用 memcpy 等更新缓冲区时(代码中没有错误),更新后的文本将无法正确显示.我什至在每次更新后都尝试了 EM_SETHANDLE (SetHandle() ),但在几次尝试后它失败了.存在某种堆分配失败.RedrawWindow() 也不起作用.

When the text is entered in the control, it is seen in the buffer but when the buffer is updated using memcpy etc (no bug in the code), the updated text won't show properly. I even tried EM_SETHANDLE (SetHandle() ) after every update but it fails after a couple of attempts. There is some kind of heap allocation failure. RedrawWindow() won't work either.

我无法在网上获得有关使用情况的任何正确信息.帮助!

I am unable to get any proper info on the net on the usage. Help!

我的代码,留下了应用程序的具体细节,看起来像这样.

My code, leaving the app specific details, looks like this.

// init
HANDLE m_hMem = HeapAlloc(...)
m_edit.SetHandle(m_hMem)

// on some event
char *pbuf = (char*)m_hMem;
memcpy(...)

提前致谢

推荐答案

EM_GETHANDLE 的文档告诉你,这个内存必须是 LocalAlloc 分配的可移动内存.

The docs for EM_GETHANDLE tells you that this memory has to be movable memory allocated by LocalAlloc.

我猜你可以通过这样的方式逃脱:

I'm guess you can get away with something like this:

int cbCh = sizeof(TCHAR) > 1 ? sizeof(TCHAR) : IsUsingComCtlV6() ? sizeof(WCHAR) : sizeof(char);
HLOCAL hOrgMem = SendMessage(hEdit,EM_GETHANDLE,0,0);
HLOCAL hNewMem = LocalReAlloc(hOrgMem,cbCh * cchYourTextLength,LMEM_MOVEABLE);
if (hNewMem)
{
  //LocalLock, assign string, LocalUnlock
  SendMessage(hEdit,EM_SETHANDLE,(WPARAM)hNewMem,0);
}

这篇关于如何在编辑控件上使用 EM_SETHANDLE?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆