读书人

CEGUI的StaticText中的文字怎么选定

发布时间: 2012-02-15 12:09:44 作者: rapoo

CEGUI的StaticText中的文字如何选定?
CEGUI的StaticText中的文字如何选定?发现选定不了啊

[解决办法]

C/C++ code
void Editbox::onKeyDown(KeyEventArgs& e)    {        // EditBox增加复制,剪切,粘贴功能        HGLOBAL clipbuffer;        char * charbuf;        CEGUI::String guiStr;        CEGUI::String guiStrTemp;        std::string strTemp;        int iStart,iLen;        HGLOBAL hMem = NULL;        guiStr = getText();        iStart = getSelectionStartIndex();        iLen =  getSelectionLength();        // base class processing        Window::onKeyDown(e);        if (hasInputFocus() && !isReadOnly())        {            WindowEventArgs args(this);            switch (e.scancode)            {            case Key::C://ctrl+c copy selected text to clipboard                if (e.sysKeys & Control)                {                    if(iLen==0)break;                    guiStr = guiStr.substr(iStart,iLen);                    strTemp = Window::CEGUIStr2STDStr(guiStr);                    if (OpenClipboard(NULL))                        {                        EmptyClipboard();                        clipbuffer = GlobalAlloc(GMEM_DDESHARE, strTemp.length()+1);                        charbuf = (char*)GlobalLock(clipbuffer);                        strcpy(charbuf,strTemp.c_str());                                            GlobalUnlock(clipbuffer);                            SetClipboardData(CF_TEXT,clipbuffer);                        CloseClipboard();                                // 关闭                        //hClipOwner = ::GetClipboardOwner();                     }                }                break;            case Key::X: //ctrl+x                if (e.sysKeys & Control)                {                    if(iLen==0)break;                    setText(guiStr.substr(0,iStart)+guiStr.substr(iStart+iLen,guiStr.length()-(iStart+iLen)));                    setCaratIndex(iStart);                    guiStr = guiStr.substr(iStart,iLen);                    strTemp = Window::CEGUIStr2STDStr(guiStr);                    if(OpenClipboard(NULL))                    {                        EmptyClipboard();                        clipbuffer = GlobalAlloc(GMEM_DDESHARE, strTemp.length()+1);                        charbuf = (char*)GlobalLock(clipbuffer);                        strcpy(charbuf, strTemp.c_str());                        GlobalUnlock(clipbuffer);                        SetClipboardData(CF_TEXT,clipbuffer);                        CloseClipboard();                    }                }                break;            case Key::V://ctrl+v                if (e.sysKeys & Control)                {                    if (!OpenClipboard(NULL)) break;                    if (!IsClipboardFormatAvailable(CF_TEXT)) break;                    hMem = ::GetClipboardData(CF_TEXT);                     if (hMem != NULL)                     {                         LPTSTR lpStr = (LPTSTR)GlobalLock(hMem);                         if (lpStr != NULL)                         {                             strTemp = std::string((char*)lpStr);                            GlobalUnlock(hMem);                         }                        else strTemp="";                    }                     else strTemp="";                    CloseClipboard();                    if( strTemp.length() == 0)break;                    guiStrTemp = Window::STDStr2CEGUIStr(strTemp.c_str());                    setText(guiStr.substr(0,iStart)+guiStrTemp+guiStr.substr(iStart+iLen,guiStr.length()-(iStart+iLen)));                    setCaratIndex(iStart+guiStrTemp.length());                }                break;                // default case is now to leave event as (possibly) unhandled.            default:                return;            }            e.handled = true;        }    } 

读书人网 >网络游戏

热点推荐