Use windows message to change text in CEdit with timeout control
2008-07-30 22:34
609 查看
When using socket class, usually you have to send your data received from remote peer to upper CDialog class, the basic ways are:
1, pass the windows handle (this or m_hWnd)to socket class object’s component data in construct function.
2, get the main window handle, use the function AfxGetApp()->m_pMainWnd;
3, use a globe buffer to contain data.
And there is an easy way pass data to upper class, just use the CEdit pointer.
The code is as follows: and we added time control.
It works the same as:
1, pass the windows handle (this or m_hWnd)to socket class object’s component data in construct function.
2, get the main window handle, use the function AfxGetApp()->m_pMainWnd;
3, use a globe buffer to contain data.
And there is an easy way pass data to upper class, just use the CEdit pointer.
The code is as follows: and we added time control.
HWND hWnd = NULL; //the CEdit component window handle if (NULL == m_pMsgCtrl) return false; if (NULL = (hWnd = m_pMsgCtrl->GetSafeHwnd())//CEdit *m_pMsgCtrl; return false; DWORD dwResult = 0; // the same as returned value of SendMessage // get the length of text in CEdit // 1000L stands for 1 second, up to 15 seconds if (SendMessageTimeout(hWnd, WM_GETTEXTLENGTH, 0, 0, SMTO_NORMAL, 1000L, &dwResult) != 0) { int nLen = (int) dwResult; // set the place to insert new string, just select the text. if (SendMessageTimeout(hWnd, EM_SETSEL, nLen, nLen, SMTO_NORMAL, 1000L, &dwResult) != 0) { // send new string if (SendMessageTimeout(hWnd, EM_REPLACESEL, FALSE, (LPARAM)strText, SMTO_NORMAL, 1000L, &dwResult) != 0) { } } } |
if (::IsWindow( m_pMsgCtrl->GetSafeHwnd() )) { int nLen = m_pMsgCtrl->GetWindowTextLength(); m_pMsgCtrl->SetSel(nLen, nLen); m_pMsgCtrl->ReplaceSel( strText ); } |
相关文章推荐
- How To Use Git Source Control with Xcode in iOS 6
- An easy way to change colour in text control
- using sqlite in windows phone 7/successful to deal with the problem in wp to use like select chinese character
- HOWTO: How to Use PeekMessage() Correctly in Windows
- HOWTO: How to Use PeekMessage() Correctly in Windows
- How to Use PeekMessage() Correctly in Windows
- HOWTO: How to Use PeekMessage() Correctly in Windows
- Know How And When To Use System.Message_Level To Control Messages In Oracle Forms
- How to Use Linux Commands in Windows with Cygwin
- How To Use Git Source Control with Xcode in iOS 7
- How to Use MFC Tab Control in Developing VC++ Applications
- JS. How to replace html element with another element/text, represented in string?
- How to change the language of oracle sqlplus from chinese to english in windows(如何将oracle sql plus中的中文变成英文版)
- IDEA错误:Failed to start end point associated with ProtocolHandler [http-nio-9999] java.net.BindException: Address already in use: bind
- How to use bitBucket with EGit in Eclipse,如何在Eclipse中使用bitbucket远程仓库
- Use expect command to interact with mysql in linux system
- How to use a TControlCanvas in a component
- how to use a SQLite database in a standalone program with an HTML interface and VBScript as the programming language
- PDFToText with ITextSharp--Extract text from PDF in C# (100% .NET)(推荐)
- FIX: Error message when you try to install a large Windows Installer package or a large Windows Installer patch package in Windows Server 2003 or in Windows XP: "Error 1718. File was rejected by digital signature policy"