Re: setFocus console

new topic     » goto parent     » topic index » view thread      » older message » newer message
jmduro said...

What are you expecting exactly? A list of open windows handles with their title and the wrapped function to focus on the handle of a console window with the expected title ?

If so, then this might help:

include dll.e 
include machine.e 
include window.ew  -- Window Finding functions, Thomas Parslow (PatRat), 25/June/2001 
 
 
constant 
  USER32   = open_dll("user32.dll"), 
  dllEnumThreadWindows = define_c_func(USER32, "EnumThreadWindows", {C_INT, C_POINTER, C_ULONG}, C_INT), 
  dllGetWindowThreadProcessId = define_c_func(USER32, "GetWindowThreadProcessId", {C_LONG, C_POINTER}, C_LONG), 
  dllSetFocus = define_c_proc(USER32, "SetFocus", {C_POINTER}) 
 
sequence windowsList 
 
------------------------------------------------------------------------------ 
 
procedure setFocus(atom hwnd) 
   c_proc(dllSetFocus, {hwnd}) 
end procedure 
 
------------------------------------------------------------------------------ 
 
function findWindow(object val, integer field) 
  for i = 1 to length(windowsList) do 
    if compare(windowsList[i][field], val) = 0 then 
      return i 
    end if 
  end for 
  return 0 
end function 
 
------------------------------------------------------------------------------ 
 
function listWindows(sequence s) 
  sequence wins 
  atom     pid, thPID, buffer 
  object   caption 
  sequence winList 
 
  wins = window_GetHwnds(s) 
  winList = repeat("", length(wins)) 
  buffer = allocate(4) 
  for i = 1 to length(wins) do 
    caption = window_GetCaption( wins[i] ) 
    if not (sequence(caption) and (length(caption)>1)) then caption = "" end if 
    thPID = c_func(dllGetWindowThreadProcessId,{wins[i],buffer}) 
    pid =peek4u(buffer) 
    winList[i] = { caption, wins[i], pid, thPID } 
  end for 
  free(buffer) 
  return winList 
end function  -- addWindows 
 
------------------------------------------------------------------------------ 
 
  sequence winList 
 
  winList = listWindows("Command Window*") 
  for x = 1 to length(winList) do 
    windowsList = append(windowsList, 
                       {winList[x][1],  -- Window title 
                        winList[x][2],  -- Window Handle (hWnd) 
                        winList[x][3],  -- process ID 
                        winList[x][4],  -- thread ID 
                        0, "", 0}) 
  end for 
 
-- add function to select your console window handle from windowsList 
-- according to its title then call setFocus 

Jean-Marc

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

Search



Quick Links

User menu

Not signed in.

Misc Menu