Announcement

Collapse
No announcement yet.

Killing Focus

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Killing Focus

    I have subclassed an EDIT window. I want to be able to close that window
    [list=a][*] when used hits RETURN key or[*] when user clicks on some other window (EDIT window looses focus).[/list=a]

    The program will do some processing and hide EDIT window after that.

    I have tried following

    Code:
    FUNCTION SubClassProc(hWnd AS LONG, wMsg AS LONG, ...)
    
        SELECT CASE wMsg
    
    	....
    
    	CASE %WM_KEYUP
    	    IF wParam=13 THEN
    		ShowWindow hWnd, %SW_HIDE
    		CALL aSub
    	    END IF
    
    	CASE %WM_KILLFOCUS
    	    ShowWindow hWnd, %SW_HIDE
    	    CALL aSub
    
    	...
    
        END SELECT
    
    END FUNCTION
    The problem is that %WM_KILLFOCUS message is also sent by ShowWindow call when processing WM_KEYUP message. Result is that aSub is called twice. How can I prevent this? Am I missing something trivial here?

    TIA

    Lasse Rantanen
    [email protected]

  • #2
    So.. don't call it from the key_up message??


    ------------------
    [email protected]
    hellobasic

    Comment


    • #3
      Usually this recursive behaviour is suppressed by using a static variable

      Code:
      FUNCTION SubClassProc(hWnd AS LONG, wMsg AS LONG, ...)
      
      Static Busy As Long
      
          SELECT CASE wMsg
      
      	....
      
      	CASE %WM_KEYUP
      	    IF wParam=13 THEN
      
      If Busy Then Exit Function
      Busy = -1
      
      		ShowWindow hWnd, %SW_HIDE
      
      		CALL aSub
      
      Busy = 0
      
      	    END IF
      
      	CASE %WM_KILLFOCUS
      
      If Busy Then Exit Function
      Busy = -1
      
      	    ShowWindow hWnd, %SW_HIDE
      
      	    CALL aSub
      Busy = 0
      
      
      	...
      
          END SELECT
      
      END FUNCTION
      Something like that..


      ------------------
      [email protected]
      hellobasic

      Comment


      • #4
        Thanks Edwin,

        I knew it had to be something very simple..As you said in your first reply, don't call it in WM_KEYUP event.
        It's funny how one can get confused. That answer was there already in the question, as your reply shows.

        Lasse Rantanen
        [email protected]

        Comment

        Working...
        X