I need help disabling Keyboard and Mouse input on Edit controls

This is a discussion on I need help disabling Keyboard and Mouse input on Edit controls within the Windows Programming forums, part of the Platform Specific Boards category; I have posted a question on other board asking for a way to disable Keybord and Mouse input on controls ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    42

    I need help disabling Keyboard and Mouse input on Edit controls

    I have posted a question on other board asking for a way to disable Keybord and Mouse input on controls without using EnableWindow(HWND, FALSE) because that makes the controls grayed, which makes it hard for the user to read itīs content.

    A guy answered that a good way would be to intercept the FOCUS messages and direct the focus elsewhere.

    I thought that would be a great solution, but as a beginner, i couldnt code something 100% functional.

    Hereīs what i have right now. The problem with this piece of code is kindda weird: It works only once, i mean, if you click over one of the controls, it does not receives the focus and the focus is sent to buttonstart (OK!). Then if you click again over any control, it receives the focus. My question is: Why the hell would this code work only for the first click?


    Any help would be appreciated.

    Code:
    case WM_KILLFOCUS: 
    if (((LOWORD(wParam))==IDC_CLEARBUTTON) || /* This are the controls that can receive focus */ 
    ((LOWORD(wParam))==IDC_CHECKSCROLL) || 
    ((LOWORD(wParam))==IDC_COPYBUTTON) || 
    ((LOWORD(wParam))==IDC_BUTTONSTART) || 
    ((LOWORD(wParam))==IDC_BUTTONSTOP) || 
    ((LOWORD(wParam))==IDC_BUTTONVIEWLOG) || 
    ((LOWORD(wParam))==IDC_BUTTONABOUT)) { 
    return DefWindowProc (mainWindow, messages, wParam, lParam); 
    return 0; 
    } 
    else { /* For the controls that cannot receive focus */ 
    SetFocus(buttonstart); /*Lets set the focus elsewhere */ 
    return 0; 
    }

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>My question is: Why the hell would this code work only for the first click? <<

    Bad luck.

    The WM_KILLFOCUS message's WPARAM is the handle of the window that is receiving the keyboard focus.

    LOWORD(wParam) for this msg will give you garbage.

    Try checking the wParam against the control handles or, alternatively, use something like GetDlgCtrlID to convert the window handle (WPARAM) into an int id for checking against the id's of your controls. eg
    Code:
    case WM_KILLFOCUS:
      {
      int nWndID=GetDlgCtrlID((HWND)wParam);
      /*check nWndID against control id's*/
      return 0; 
    }

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    Thanks for your reply Ken,
    I have tried to correct my code the way you wrote on your post, but the program is behaving in the exact same way Works for the first click and thats it.
    I canīt find where the error is :\

    Code:
    case WM_KILLFOCUS: 
          nWndID=GetDlgCtrlID((HWND)wParam);    
            if ((nWndID==IDC_CHECKSCROLL) ||
               (nWndID==IDC_CLEARBUTTON) ||
               (nWndID==IDC_COPYBUTTON) ||
               (nWndID==IDC_BUTTONSTART) ||
               (nWndID==IDC_BUTTONSTOP) ||
               (nWndID==IDC_BUTTONVIEWLOG) ||
               (nWndID==IDC_BUTTONABOUT)) {
              return DefWindowProc (mainWindow, messages, wParam, lParam); 
            } 
            else {                                 /* For the controls that cannot receive focus */ 
              SetFocus(buttonstart);               /* Lets set the focus elsewhere */ 
              return 0; 
            }

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    Have you tried

    ES_READONLY when creating the edit

    or after the edit created using Sendmessage() and

    EM_SETREADONLY

    or using a static control and seting the text as you go?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    42
    Finally EN_SETFOCUS solved the problem, first time i use it...

    Code:
    case WM_COMMAND: 
          
          if (((HIWORD(wParam))==EN_SETFOCUS) && (tabnumber==0) && (allcreated==1)) {
            SetFocus(NULL);
            return 0;
          }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Windows) Send keyboard and mouse to another program?
    By Chrisname in forum Windows Programming
    Replies: 4
    Last Post: 06-13-2009, 06:13 PM
  2. Detecting keyboard and mouse in linux
    By sameer.nalwade in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 03:24 AM
  3. Disabling keyboard & mouse
    By twomers in forum C++ Programming
    Replies: 5
    Last Post: 01-16-2006, 01:19 PM
  4. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM
  5. Edit controls not sending messages to parent window
    By EMiller in forum Windows Programming
    Replies: 5
    Last Post: 11-13-2001, 10:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21