include win32lib.ew
without warning

constant
    -- our window, menues, and buttons.
    mystyle = { WS_CAPTION, WS_SYSMENU, WS_THICKFRAME}, 
    Win1 = create(Window, "Try It !", 0, Default, Default, 300, 150, mystyle ), 
    Sample = create(Menu, "Sample", Win1, 0, 0, 0, 0, 0 ), 
    About = create(MenuItem, "About", Sample, 0, 0, 0, 0, 0 ), 
    Leave = create(MenuItem, "E&xit", Sample, 0, 0, 0, 0, 0 ), 
    Button1 = create(PushButton, "Find File", Win1, 10, 10, 50, 25, 0 ), 
    -- .. two new functions,
    zVkKeyScan = registerw32Function( user32, "VkKeyScanA", {C_INT}, C_INT ), 
    zkeybd_event = registerw32Function( user32,  "keybd_event",  {C_INT,  C_INT,  C_INT,  C_INT },  C_INT ), 

-- and two new constants.
KEYEVENTF_KEYUP = 2, 
FindFiles = #46   -- "F"

atom jk
sequence ex, ex2
ex2 = { }
ex = "findfiles.exw" -- will handle '\r'
-- turn the sequence into key scan codes.
for i=1 to length( ex ) do
  ex2 = ex2 & w32Func( zVkKeyScan, {ex[i]} )
end for
ex2 = and_bits( #FF, ex2 )

procedure find( integer self,  integer event,  sequence params )
-- open up the [Find] dialog box;
-- THIS FAILS! OBSOLETE DIALOG?
  jk = w32Func( zkeybd_event,  { VK_LWIN,  0,  0,  0 } )
  jk = w32Func( zkeybd_event,  { FindFiles,  0,  0,  0 } )
  jk = w32Func( zkeybd_event,  { VK_LWIN,  0,  KEYEVENTF_KEYUP,  0 } )
  -- and wait a second
  sleep(1 )
  for i = 1 to length( ex2 ) do
      jk = w32Func( zkeybd_event,  { ex2[i],  0,  0,  0 } )
  end for
  sleep(1 )
  -- then, hit the [Return] key...
  jk = w32Func( zkeybd_event,  { VK_RETURN,  0,  0,  0 } )
--  ? 99 -- ok
end procedure
setHandler( Button1,  w32HClick,  routine_id("find" ) )

----

procedure about( integer self,  integer event,  sequence params )
    jk = message_box("--- 'tutorial' demo,  thanks to VB",  "...another",  0 )
end procedure
setHandler( About,  w32HClick,  routine_id("about" ) )

----

procedure leave( integer self,  integer event,  sequence params )
    closeWindow(Win1 )
end procedure
setHandler( Leave,  w32HClick,  routine_id("leave" ) )

WinMain(Win1, Normal )
