Thread: Dont Kill Focus When Switching Tasks

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    193

    Dont Kill Focus When Switching Tasks

    I tried searching for an answers to my question, but I don't know what to search for. It most likely has something to do with subclassing, but I still don't know how to do this. Anyway, I want my edit controls to display the caret (where it was before the user switch tasks) after the user switches back. Like for instance, say I go to google.com, I type something in the search box, I leave the caret in the middle of my search, I switch tasks to an open program like Microsoft Word, I go back to my open browser with google.com and the caret appears in the middle of my search right where I had left it. I can't really explain what I would like very well and that's most likely why I can't find anything when I search.

    Thanks for any help!!!

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The control should 'remember' the caret position so all you should need to do is to set the focus to the edit control in question with SetFocus in response to a WM_ACTIVATE message for the main window.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    The only problem with that is that I have more than one edit control, so how would it remember which control had the focus last?

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    So how would that work?

    SetFocus(GetFocus())

    Like That?

  6. #6
    Registered User
    Join Date
    Mar 2005
    Posts
    16
    Handle the WM_ACTIVATE message, and when the wParam is WA_INACTIVE, save the active control handle (GetFocus(), that is) somewhere, and when the wParam is WA_ACTIVE or WA_CLICKACTIVE, set it back to that saved value with SetFocus().

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    Thanks for both of your help. That worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to kill a dragon with various programming languages
    By g4j31a5 in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-01-2007, 12:13 PM
  2. Thread paused when switching tasks
    By stickman in forum Windows Programming
    Replies: 4
    Last Post: 09-29-2006, 05:57 PM
  3. Focus Messages?
    By PsychoBrat in forum Windows Programming
    Replies: 5
    Last Post: 12-30-2003, 07:14 AM
  4. Focus & Always-On-Top :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 06-13-2002, 05:44 PM