Jump to content

Embed 2 Window Controls


DaveRedford
 Share

Recommended Posts

Hi, I'm wondering if anybody can help me. I need to make a tabbed menu system which, on one tab, will show two embedded windows (one of My Documents the other of My Computer). The point is so that users of limited PC knowledge can drag files from their My Documents to a USB stick. I'm struggling to even get two windows working, let alone the drag and drop element.

The code is attached (the FilesTab() function is just me trying to work out where a user has clicked...)

Any help, even with just getting the dual window to work (forgetting the drag and drop) would be a start.

Thanks for anything you can advise.

Cheers,

Dave.

#NoTrayIcon
#include <IE.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#Include <WinAPI.au3>

_IEErrorHandlerRegister ()

GUICreate("CWP Patient Access PC",@DesktopWidth, @DesktopHeight,0,0,BitOR($WS_EX_CLIENTEDGE, $WS_CLIPCHILDREN))
;$background = GUICtrlCreatePic(".\cwp_back.bmp", 15, 35, @DesktopWidth-40, @DesktopHeight-90)
GUISetFont(9, 300)

$tab=GUICtrlCreateTab (10,10, @DesktopWidth-30,@DesktopHeight-60)

;tab Home
$tab0=GUICtrlCreateTabitem ("Home")
$btn_Logout = GUICtrlCreateButton("Log Out", 50, 50, 60, 60, $BS_ICON)
 _GUICtrlButton_SetImage($btn_Logout, "shell32.dll", 21, True)

;tab Applications
$tab1=GUICtrlCreateTabitem ( "Applications")
$btnWord = GUICtrlCreateButton("Word", 50, 50, 60, 60)

;tab Files
$tab2=GUICtrlCreateTabitem ("Files")
$oMyDocs = _IECreateEmbedded ()
$GUIDocs = GUICtrlCreateObj($oMyDocs, 40, 40, @DesktopWidth-80, 250)
GUICtrlSetState(-1,$GUI_SHOW)
GUISetState ()
_IENavigate ($oMyDocs, "C:\")

$oMyComp = _IECreateEmbedded ()
$GUIComp = GUICtrlCreateObj($oMyComp, 40, 400, @DesktopWidth-80, 250)
GUICtrlSetState(-1,$GUI_SHOW)
GUISetState ()
_IENavigate ($oMyComp, "C:\Windows")


While 1
    $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $btnWord
                Run('C:\Program Files\Microsoft Office\Office14\WINWORD.EXE')    ; Will Run/Open Word 10
            Case $msg = $btn_Logout
                ExitLoop
            Case $msg = $tab
                If GUICtrlRead($tab) = 2 Then FilesTab()
        EndSelect
Wend

func FilesTab()

    $msg = GUICtrlRead($oMyDocs)
     MsgBox(0, 'Where?', $msg)
    $msg = GUICtrlRead($oMyComp)
     MsgBox(0, 'Where?', $msg)

endfunc

$oMyDocs = 0 ;Free the control
$oMyComp = 0
Exit
Link to comment
Share on other sites

Progress has been made today. The script will allow dual windows with dragging and dropping between them. The problem now is that the windows don't refresh properly. I've had to add code that will check for a mouse click in the window and then refresh the opposite window. It works great, but only the second time you double click. There are manual refresh buttons to prove to myself that it should work and an overall reset button to refresh all windows. In the end there will be navigation buttons, but not until I can fix the refresh problem (with all your help of course....) :)

Thanks.

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>

;used in the capture of mouse/key press
$dll = DllOpen("user32.dll")

global $objMyComp=ObjCreate("shell.explorer.2")
global $objMyDocs=ObjCreate("shell.explorer.2")

$main=GUICreate("Patient Access PC",@DesktopWidth-100, @DesktopHeight-100)
$btn_Logout = GUICtrlCreateButton("Log Out", 50, 50, 60, 30)
$btn_rfsh_MyComp = GUICtrlCreateButton("Refresh", 150, 150, 60, 30)
$btn_rfsh_MyDocs = GUICtrlCreateButton("Refresh", 850, 150, 60, 30)
$btn_rst_MyDocs = GUICtrlCreateButton("Reset", 150,100,60,30)

$IEbed=GUICtrlCreateobj ($objMyDocs,10,10, @DesktopWidth-30,@DesktopHeight-60)
$IEbed2=GUICtrlCreateobj ($objMyComp,10,10, @DesktopWidth-30,@DesktopHeight-60)

With $objMyComp
.Navigate("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
.left=800
.top=200
.height=400
.width=400
.menubar=0
.toolbar=0
.statusBar=0
.visible=1
EndWith

With $objMyDocs
.Navigate("::{450D8FBA-AD25-11D0-98A8-0800361B1103}")
.left=100
.top=200
.height=400
.width=400
.menubar=0
.toolbar=0
.statusBar=0
.visible=1
EndWith

GUISetState()

;A nice way to wait for windows to load
ProgressOn("Creating Window", "Window Creation", "0 percent")
For $i = 10 to 100 step 10
    sleep(30)
    ProgressSet( $i, $i & " percent")
Next
ProgressSet(100 , "Done", "Complete")
sleep(500)
ProgressOff()

While 1

    $loc=mousegetpos()

    ;if click in window 1 then refresh window 2
    if $loc[0]>100 and $loc[0] <500 then ;get x width between 100 and 500
        if $loc[1]>200 and $loc[1] < 600 then ;get y pos between 200 and 600
            if _ispressed(01,$dll) Then
                $objMyComp.refresh
            EndIf
        EndIf
    EndIf

    ;if click in window 2 then refresh window 1
    if $loc[0]>800 and $loc[0] <1200 then ;get x width between 800 and 1200
        if $loc[1]>200 and $loc[1] < 600 then ;get y pos between 200 and 600
            if _ispressed(01,$dll) Then
                $objMyDocs.refresh
            EndIf
        EndIf
    EndIf

    ;check gui for selections
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        case $msg = $btn_rfsh_MyComp
            $objMyDocs.refresh
        case $msg = $btn_rfsh_MyDocs
            $objMyComp.refresh
        case $msg = $btn_rst_MyDocs
            $objMyComp.navigate("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
            $objMyDocs.navigate("::{450D8FBA-AD25-11D0-98A8-0800361B1103}")
            ProgressOn("Rest", "Reseting Windows", "0 percent")
            For $i = 10 to 100 step 10
                sleep(30)
                ProgressSet( $i, $i & " percent")
            Next
            ProgressSet(100 , "Done", "Complete")
            sleep(500)
            ProgressOff()
        Case $msg = $btn_Logout
            ExitLoop
EndSelect
WEnd

DllClose($dll)
$main = 0
GUIDelete ()
Exit
Link to comment
Share on other sites

Moving on. Refresh issue now solved - had to add an extra navigation before the main loop started. It seems that the embedded windows didn't know their own location from the ".navigate" during the setup. When I added the "Nice way for windows to load" section before main loop it fixed the refresh issue.

Since reading all the help files on COM objects discovered a wealth of options for manipulating the embedded windows so added labels beneath each screen to disply current navigation. (This was what allowed me to solve the refresh issue as both locations showed up as blank when first run until I added fix above)

Added back/forward buttons for each screen with error checking. Will eventually change these to icons and fix it incase the error message appears behind the main screen. (As this is supposed to be a limited use console type menu for basic users I can't have them switch screens so the message box behind the main screen would effectivly stop the whole thing working!)

I kind of imagine this kind of thing would be handy in schools where you only wnat users to have limited access to things. I'm using it in a hospital for patients. When it's finished I'll publish the reg edits, etc along with it that lock down access to internal drives and other things so users only see what you want them to.

If this is helping anybody then let me know. It get's lonely out here in AutoIT land......

Cheers,

Dave.

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>

;used in the capture of mouse/key press
$dll = DllOpen("user32.dll")

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler

global $objMyComp=ObjCreate("shell.explorer.2")
global $objMyDocs=ObjCreate("shell.explorer.2")
global $MyCompURL=""
global $MyDocsURL=""

$main=GUICreate("Patient Access PC",@DesktopWidth-100, @DesktopHeight-100)
$btn_Logout = GUICtrlCreateButton("Log Out", 50, 50, 60, 30)
$btn_rfsh_MyComp = GUICtrlCreateButton("Refresh", 150, 150, 60, 30)
$btn_rfsh_MyDocs = GUICtrlCreateButton("Refresh", 850, 150, 60, 30)
$btn_rst_MyDocs = GUICtrlCreateButton("Reset", 150,100,60,30)
$btn_back_MyDocs = GUICtrlCreateButton("Back", 350,100,60,30)
$btn_fwd_MyDocs = GUICtrlCreateButton("Forward", 350,150,60,30)
$btn_back_MyComp = GUICtrlCreateButton("Back", 1050,100,60,30)
$btn_fwd_MyComp = GUICtrlCreateButton("Forward", 1050,150,60,30)
$lbl_MyComp_URL = GUICtrlCreateLabel("Location:",820,640,350,20)
$lbl_MyDocs_URL = GUICtrlCreateLabel("Location:",120,640,350,20)

$IEbed=GUICtrlCreateobj ($objMyDocs,10,10, @DesktopWidth-30,@DesktopHeight-60)
$IEbed2=GUICtrlCreateobj ($objMyComp,10,10, @DesktopWidth-30,@DesktopHeight-60)

With $objMyComp
.Navigate("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
.left=800
.top=200
.height=400
.width=400
.menubar=0
.toolbar=0
.statusBar=0
.visible=1
EndWith

With $objMyDocs
.Navigate("::{450D8FBA-AD25-11D0-98A8-0800361B1103}")
.left=100
.top=200
.height=400
.width=400
.menubar=0
.toolbar=0
.statusBar=0
.visible=1
EndWith

GUISetState()

;A nice way to wait for windows to load
$objMyComp.navigate("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
$objMyDocs.navigate("::{450D8FBA-AD25-11D0-98A8-0800361B1103}")
ProgressOn("Creating Window", "Window Creation", "0 percent")
For $i = 10 to 100 step 10
    sleep(30)
    ProgressSet( $i, $i & " percent")
Next
ProgressSet(100 , "Done", "Complete")
sleep(500)
ProgressOff()




While 1

    $loc=mousegetpos()

    ;if click in window 1 then refresh window 2
    if $loc[0]>100 and $loc[0] <500 then ;get x width between 100 and 500
        if $loc[1]>200 and $loc[1] < 600 then ;get y pos between 200 and 600
            if _ispressed(01,$dll) Then
                call ("CleanURL")
            EndIf
        EndIf
    EndIf

    ;if click in window 2 then refresh window 1
    if $loc[0]>800 and $loc[0] <1200 then ;get x width between 800 and 1200
        if $loc[1]>200 and $loc[1] < 600 then ;get y pos between 200 and 600
            if _ispressed(01,$dll) Then
                call ("CleanURL")
            EndIf
        EndIf
    EndIf

    ;check gui for selections
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        case $msg = $btn_rfsh_MyComp
            $objMyDocs.refresh
        case $msg = $btn_rfsh_MyDocs
            $objMyComp.refresh
        case $msg = $btn_rst_MyDocs
            $objMyComp.navigate("::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
            $objMyDocs.navigate("::{450D8FBA-AD25-11D0-98A8-0800361B1103}")
            ProgressOn("Rest", "Reseting Windows", "0 percent")
            For $i = 10 to 100 step 10
                sleep(30)
                ProgressSet( $i, $i & " percent")
            Next
            ProgressSet(100 , "Done", "Complete")
            sleep(500)
            ProgressOff()
            call("CleanURL")
        Case $msg = $btn_Logout
            ExitLoop
        case $msg = $btn_back_MyDocs
            $objMyDocs.goback
            call ("CleanURL")
        case $msg = $btn_fwd_MyDocs
            $objMyDocs.goforward
            call ("CleanURL")
        case $msg = $btn_back_MyComp
            $objMyComp.goback
            call ("CleanURL")
        case $msg = $btn_fwd_MyComp
            $objMyComp.goforward
            call ("CleanURL")
EndSelect
WEnd

;Clean the URL
Func CleanURL ()
;Clean My Computer
$MyCompURL = StringReplace($objMyComp.LocationURL,"file:///","")
$MyCompURL = StringReplace($MyCompURL,"/","\")
$MyCompURL = StringReplace($MyCompURL,"%20"," ")

guictrlsetdata($lbl_MyComp_URL, "Location:"& $MyCompURL)

;Clean My Docs
$MyDocsURL = StringReplace($objMyDocs.LocationURL,"file:///","")
$MyDocsURL = StringReplace($MyDocsURL,"/","\")
$MyDocsURL = StringReplace($MyDocsURL,"%20"," ")
$MyDocsURL = StringReplace($MyDocsURL,"C:\Documents and Settings\" & @USERNAME & "\","")

guictrlsetdata($lbl_MyDocs_URL, "Location:"& $MyDocsURL)

$objMyComp.refresh
$objMyDocs.refresh
EndFunc

; This is my custom error handler
Func MyErrFunc()
   $HexNumber=hex($oMyError.number,8)
   if $HexNumber = "80020009" then msgbox(0,"Error","You cannot go do that at this time")
   $g_eventerror = 1 ; something to check for when this function returns
Endfunc


DllClose($dll)
$main = 0
GUIDelete ()
Exit
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...