Hi,
I have just been testing, and it works, that you can open a File Explorer window, press Winkey + Cursor Left,
and it pushes that window to the left
Open another File Explorer window, press Winkey + Cursor Right, and that window goes to the right
Great - just what I want in one of my programs!
I know how to open the Explorer windows, but how do I send the appropriate keystrokes to each of the windows?
Thanks in advance,
Brian
See if this link helps... http://www.ionicwind.com/forums/index.php?topic=4815.0
I have used this to send text to the notepad.
SUB AddToNotepad(string mtxt)
int Success
IDispatch objShell = CreateComObject("WScript.Shell")
Success = objShell.AppActivate("Untitled - Notepad")
Sleep(250)
IF Success
objShell.Sendkeys (mtxt+CHR$(13))
ENDIF
objShell->Release()
RETURN 0
ENDSUB
Later,
Clint
Clint,
I think I have seen that code before, but I need the handle of the File Explorer window
just opened, so I can send Winkey+CursorLeft to it (VK_LWIN is 0x5B, I think)
And as there is no caption, I can't use FindWindow
Brian
There is an API called "GetForegroundWindow()". Maybe that would work? It returns the handle to that window.
Later,
Clint
Hi,
If you run this code, it sends the correct codes (VK_LWIN + Cursor Left) but only moves to the left
the IWB window, and not the File Explorer window
Any ideas?
Brian
autodefine "off"
$include "windowssdk.inc"
WINDOW win
CONST VK_LWIN=0x5B
OpenWindow win,0,0,640,480,@MinBox,0,"Two File Explorer Windows",&winProc
WaitUntil IsWindowClosed win
End
Sub winProc(),int
Select @Message
Case @IDCreate
CenterWindow win
SYSTEM "explorer.exe","c:\\Windows"
UINT exp1=FindWindow(NULL,"explorer.exe")
INT keyState[255]
IF GetKeyboardState(keyState)<>0
' Simulate a key press
keybd_event(VK_LWIN,0x5B,0,0)
keybd_event(0x25,0,0,0)
' Simulate a key release
keybd_event(0x25,0,KEYEVENTF_KEYUP,0)
keybd_event(VK_LWIN,0x5B,KEYEVENTF_KEYUP,0)
ENDIF
setcaption win,str$(exp1)
Case @IDCloseWindow
CloseWindow win
EndSelect
return 0
EndSub
Try this...
autodefine "off"
$include "windowssdk.inc"
WINDOW win
CONST VK_LWIN=0x5B
OpenWindow win,0,0,640,480,@MinBox,0,"Two File Explorer Windows",&winProc
WaitUntil IsWindowClosed win
End
Sub winProc(),int
Select @Message
Case @IDCreate
CenterWindow win
SYSTEM "explorer.exe","c:\\Windows"
Sleep(1000)
UINT exp1=GetForegroundWindow()
INT keyState[255]
IF GetKeyboardState(keyState)<>0
' Simulate a key press
keybd_event(VK_LWIN,0x5B,0,0)
keybd_event(0x25,0,0,0)
' Simulate a key release
keybd_event(0x25,0,KEYEVENTF_KEYUP,0)
keybd_event(VK_LWIN,0x5B,KEYEVENTF_KEYUP,0)
ENDIF
setcaption win,str$(exp1)
Case @IDCloseWindow
CloseWindow win
EndSelect
return 0
EndSub
Later,
Clint
The only difference between Clint's and Brian's code, is the Sleep(1000) Clint has put in there.
And Clint's version works fine as intended here.
But if the the lines getting the Foreground Window handle (UINT exp1=GetForegroundWindow()) and the call to setcaption further down (setcaption win,str$(exp1)) are deleted, the "original" caption text is kept.
Otherwise the program window caption will contain the value of the ForegroundWindow handle.
This way opening Windows File Explorer is much easier to code than the methods I have used in the past.
So thanks for the tip guys! :D
Regards,
Egil.
Clint: The Sleep(1000) certainly did the trick - well done!
Egil: I only had the GetForegroundWindow and SetCaption calls in to make sure I had
actually got a handle value greater zero
Now this cleaned up code is REALLY what I wanted it to do in the first place - open two File Explorer
windows and place them side by side, to make copying files from selected directories easier:
autodefine "off"
$include "windowssdk.inc"
CONST VK_LWIN=0x5B
CONST VK_LEFT=0x25
CONST VK_RIGHT=0x27
WINDOW win
INT keyState[255]
OPENWINDOW win,0,0,640,480,@MINBOX,0,"Two File Explorer Windows",&main
WAITUNTIL IsWindowClosed(win)
END
SUB main(),INT
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW win
'Open a File Explorer window and move to the left of the screen
SYSTEM "explorer.exe","c:\\Windows"
Sleep(1000)
IF GetKeyboardState(keyState)<>0
'Simulate pressing Windows key plus Cursor Left
keybd_event(VK_LWIN,VK_LWIN,0,0)
keybd_event(VK_LEFT,0,0,0)
' Simulate release of Windows Key plus Cursor Left
keybd_event(VK_LEFT,0,KEYEVENTF_KEYUP,0)
keybd_event(VK_LWIN,VK_LWIN,KEYEVENTF_KEYUP,0)
ENDIF
'Open a second File Explorer window and move to the right of the screen
SYSTEM "explorer.exe","c:\\Windows"
Sleep(1000)
IF GetKeyboardState(keyState)<>0
'Simulate pressing Windows key plus Cursor Left
keybd_event(VK_LWIN,VK_LWIN,0,0)
keybd_event(VK_RIGHT,0,0,0)
' Simulate release of Windows Key plus Cursor Left
keybd_event(VK_RIGHT,0,KEYEVENTF_KEYUP,0)
keybd_event(VK_LWIN,VK_LWIN,KEYEVENTF_KEYUP,0)
ENDIF
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
ENDSELECT
RETURN 0
ENDSUB
Thanks for your help and interest,
Brian
I had similiar problems sending keys strokes to open a menu item or something. The sleep(1000) waits 1 sec to allow time for the program to load. You may be able to make that even sleep(750) or sleep(500) to speed things up a little. I have also used a simple WHILE/ENDWHILE loop to check to see when the window finished opening like so .....
ShellExec(GETSTARTPATH+"mailsend.exe",param,2) 'program to send email
WHILE (FindWindow(0,GETSTARTPATH+"mailsend.exe")=0) 'wait till it opens
WAIT 1
ENDWHILE
Later,
Clint