Better Win32Edit::setReadOnly implementation, Win32Edit::setReadOnly problem fix.
Better Win32Edit::setReadOnly implementation, Win32Edit::setReadOnly problem fix.
| maze |
Mar 12 2007, 12:34 AM
Post
#1
|
|
Member ![]() ![]() Group: Members Posts: 25 Joined: 11-March 07 From: Riga, Latvia Member No.: 674 |
I use compilator MSVC6 and OS Windows 2000.
First of all I have tried to write fix for Win32Edit::setReadOnly because, when in code calls of Win32Edit::setReadOnly are repeated, then error of "Access Violation" occured because richEditCallback_ value after delete was not set to NULL. So after first fix method look like this: CODE void Win32Edit::setReadOnly( const bool& readonly ) { if( NULL != richEditCallback_ ) { SendMessage( hwnd_, EM_SETOLECALLBACK, 0, (LPARAM)0 ); delete richEditCallback_; richEditCallback_ = NULL; } if( readonly ) { richEditCallback_ = new Win32RichEditOleCallback(); SendMessage( hwnd_, EM_SETOLECALLBACK, 0, (LPARAM)richEditCallback_ ); } } But this does not resolved all problems. Next problem: when I repeatedly called this method, exception from Win32 RichEdit was throwed. So I started to read MSDN about using of RichEdit. In page http://msdn2.microsoft.com/en-us/library/ms652181.aspx I found solution or it is looked like solution because this does not worked. As I founded later, meaning of params was wrong: E.g. In truth lParam Specifies the operation, which can be one of these values, not vice versa, when wParam Specifies the operation. So final solution looks something like this: CODE #define WM_USER 0x0400 #define EM_GETOPTIONS (WM_USER + 78) #define EM_SETOPTIONS (WM_USER + 77) #define ECO_READONLY 0x00000800 #define ECOOP_SET 0x0001 void Win32Edit::setReadOnly( const bool& readonly ) { LRESULT options = SendMessage( hwnd_, EM_GETOPTIONS, 0, 0 ); bool xorIt = !readOnly; if( !readOnly_ ) { xorIt = (options & ECO_READONLY) == ECO_READONLY; } if( xorIt ) { options ^= ECO_READONLY; } else { options |= ECO_READONLY; } SendMessage( hwnd_, EM_SETOPTIONS, options, ECOOP_SET ); } |
maze Better Win32Edit::setReadOnly implementation Mar 12 2007, 12:34 AM
ddiego Thanks for this!
You can either submit a patch... Mar 13 2007, 05:15 PM![]() ![]() ![]() |
| Lo-fi Version | : 18th May 2013 - 05:48 PM |