Re: Focus problem in win32 program

new topic     » goto parent     » topic index » view thread      » older message » newer message

OK, I've read some more win32lib docs and found getFocus(). Using that I've modified my message boxes to show which ID has focus at the time of the message box.

Starting out all key strokes and mouse clicks showed ID 3 with the focus. When I clicked on the button it changed to ID 15. I tried to modify my windows paint routine (something I felt was likely to get called) such that if it noticed that the focus ID changed from its initial value it would use setFocus to change it back. This has not helped except that I can see the focusID has changed after I click on the button.

Again, any suggestions welcomed.

Here is my modified example code:

include Win32Lib.ew 
 without warning 
 
atom     winWidth,             winHeight              
         winWidth    = 800     winHeight      = 600    
sequence winSettings 
	 winSettings = {} 
atom	result 
	result = 0 
integer focusID 
        focusID = 0 
 
constant X = 2 
constant Y = 1 
 
constant Win =   
    create( Window, "Focus Problem Example", 0, Default, Default, winWidth, winHeight, 0 ), 
 
-- The menus 
    FileMenu  = create( Menu,     "&File",           Win,      0, 0, 0, 0, 0 ), 
    MenuOpen  = create( MenuItem, "&Load (^L)",      FileMenu, 0, 0, 0, 0, 0 ), 
    myButton   = create(PushButton,"Button",    Win,582,0,75,28,0 ) 
 
procedure Paint( integer iD_,integer evenT_,sequence paramS_ ) 
 
  integer localFocusID 
 
  if focusID = 0 then 
    -- the initial condition 
    focusID = getFocus() 
  end if 
  
  winSettings = getSize( Win ) 
  winHeight = winSettings[4] - winSettings[2] 
  winWidth  = winSettings[3] - winSettings[1] 
   
    localFocusID = getFocus() 
    if localFocusID != focusID then 
      setFocus(focusID) 
    end if 
 
end procedure 
 
setHandler( Win , w32HPaint, {-1, routine_id("Paint")}) 
 
---------------------------------------- 
 
procedure onClick_myButton( integer iD_,integer evenT_,sequence paramS_ ) 
 
      integer localFocusID 
 
      localFocusID = getFocus() 
      result = message_box( sprintf("You clicked my button! ID %d has focus.",{localFocusID}), 
                        "onClick_myButton", 0 ) 
 
end procedure 
 
setHandler( myButton , w32HClick, {-1, routine_id( "onClick_myButton" )}) 
 
---------------------------------------- 
 
procedure winMouse( integer iD_,integer evenT_,sequence paramS_ ) 
 
    integer event, x, y, shift 
    event = paramS_[1] 
    x     = paramS_[2] 
    y     = paramS_[3] 
    shift = paramS_[4] 
    integer localFocusID 
 
    localFocusID = getFocus() 
    if event=LeftDown then 
      result = message_box( sprintf("You left-clicked at (%d,%d)! ID %d has focus.",{x,y,localFocusID}), 
                        "winMouse", 0 ) 
 
    elsif event=RightDown then 
      result = message_box( sprintf("You right-clicked at (%d,%d)!",{x,y}), 
                        "winMouse", 0 ) 
 
    end if 
 
    localFocusID = getFocus() 
    if localFocusID != focusID then 
      setFocus(focusID) 
    end if 
 
end procedure 
    
setHandler( Win , w32HMouse, {-1, routine_id( "winMouse" )}) 
 
----------------------------------------------------------------------------- 
 
procedure keyPressProcessing( integer iD_,integer evenT_,sequence paramS_ ) 
 
  integer keyCode 
  integer shift 
  integer localFocusID 
   
  keyCode = paramS_[1] 
  shift   = paramS_[2] 
 
  localFocusID = getFocus() 
  result=message_box(sprintf("You typed key %d while shift was %d! id %d has focus", 
			     {keyCode,shift,localFocusID}), 
                        "keyPressProcessing", 0 ) 
end procedure 
 
setHandler( Win , w32HKeyPress, {-1, routine_id( "keyPressProcessing" )}) 
 
------------------------------------------- 
 
WinMain( Win, Normal ) 
 
 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu