1
votes

I have an edit text control which i want to subclass to allow lowercase characters when the SHIFT key is pressed because the control is allowed to accept only uppercase characters by default.

So my problem is how to change the typing mode in the control from lower to uppercase.

I'm using WIN32, i succeeded to catch the WM_CHAR event : WNDPROC ancienneEditProc; LRESULT CALLBACK EditTextProc(HWND hwnd, UINT mssg, WPARAM wParam, LPARAM lParam) { switch(mssg) {
case WM_CHAR: { char character[2]; character[0] = (char)wParam; character[1] = 0; if(HIWORD(GetKeyState(VK_SHIFT))) { AnsiLower(character); } wParam = character[0]; } break; } return CallWindowProc(ancienneEditProc, hwnd, mssg, wParam, lParam); } But the problem is how i can update the edit text control to accept lowercase after catching the WM_CHAR.

1

1 Answers

0
votes

I assume you are using win32 or MFC text edit. Just catch WM_CHAR event.

On MFC, use a message map :

in your .h

class YourEdit public CEdit
{
    afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
    DECLARE_MESSAGE_MAP()
};

in your .cpp

BEGIN_MESSAGE_MAP(YourEdit, CEdit)
    ON_WM_CHAR()
END_MESSAGE_MAP()

YourEdit::::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
    nchar = toupper(nchar);
    CWnd::OnChar(nChar,nRepCnt,nFlags);
}

see : http://msdn.microsoft.com/en-us/library/3zzfkd75%28v=vs.71%29.aspx