Jump to content

Recommended Posts

Posted

Hello All,

I think I am a little in over my head, but I also think that if I can understand Functions and calling Functions, I will be able to do what I desire: I have a piece of software on my Laptop which synchronizes files between my Laptop (XP Home) and Desktop (Vista Ultimate 32-bit). Because of the new file system in Vista (as well as documents on various hard drives on the Desktop), I have several network shares which need to be mapped before the synchronizing can occur.

I created with Koda a GUI offering me the opportunity to choose among five (5) network shares using checkboxes, but I cannot get the functions for the checkboxes working. In fact, I cannot seem to adapt the "OK" button (which should start the mapping) and "Cancel" button (which should cancel and close the GUI). I am a novice, so this may be beyond me, but I am not sure.

I include a copy of the code as well as an upload of the code.

I am mainly looking to find information so that I can learn a sufficient amount to finish my task, but any type of help would be wonderful.

Thank you for any help you can provide,

edsager

CODE
#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

#Region ### START Koda GUI section ### Form=form2.kxfdocuments\sync files\scripting\autoit\form2.kxf

$Form1_1 = GUICreate("Choose network map...", 661, 441, 204, 157, BitOR($WS_MINIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))

GUISetIcon("D:03.ico")

GUISetFont(11, 400, 0, "Verdana")

GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_1Close")

GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1_1Minimize")

GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1_1Maximize")

GUISetOnEvent($GUI_EVENT_RESTORE, "Form1_1Restore")

$grpChoices = GUICtrlCreateGroup("Mapping choices: ", 5, 5, 650, 360)

GUICtrlSetFont(-1, 16, 400, 0, "Verdana")

$ckbxFlash = GUICtrlCreateCheckbox("Edward\Flash Projects", 395, 155, 225, 30)

GUICtrlSetFont(-1, 12, 800, 0, "Verdana")

GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKVCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)

GUICtrlSetOnEvent(-1, "ckbxFlashClick")

$ckbxDocs = GUICtrlCreateCheckbox("Edward\Documents", 235, 65, 200, 30)

GUICtrlSetFont(-1, 12, 800, 0, "Verdana")

GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKVCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)

GUICtrlSetOnEvent(-1, "ckbxDocsClick")

$ckbxSoft = GUICtrlCreateCheckbox("Edward\EdsSoftware", 50, 155, 215, 30)

GUICtrlSetFont(-1, 12, 800, 0, "Verdana")

GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKVCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)

GUICtrlSetOnEvent(-1, "ckbxSoftClick")

$ckbxPics = GUICtrlCreateCheckbox("Edward\Pictures", 50, 245, 175, 30)

GUICtrlSetFont(-1, 12, 800, 0, "Verdana")

GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKVCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)

GUICtrlSetOnEvent(-1, "ckbxPicsClick")

$ckbxDownloads = GUICtrlCreateCheckbox("Edward\Downloads", 395, 245, 195, 30)

GUICtrlSetFont(-1, 12, 800, 0, "Verdana")

GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKVCENTER+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)

GUICtrlSetOnEvent(-1, "ckbxDownloadsClick")

$iconDocs = GUICtrlCreateIcon("C:\WINDOWS\system32\shell32.dll", -127, 315, 95, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP))

GUICtrlSetOnEvent(-1, "ckbxDocsClick")

$iconSoft = GUICtrlCreateIcon("C:\WINDOWS\system32\shell32.dll", -5, 137, 185, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP))

GUICtrlSetOnEvent(-1, "ckbxSoftClick")

$iconFlash = GUICtrlCreateIcon("C:\Program Files\Adobe\Adobe Flash CS3\Flash.exe", -6, 495, 185, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP))

GUICtrlSetOnEvent(-1, "ckbxFlashClick")

$iconDownloads = GUICtrlCreateIcon("C:\WINDOWS\system32\shell32.dll", -89, 495, 275, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP))

GUICtrlSetOnEvent(-1, "ckbxDownloadsClick")

$iconPics = GUICtrlCreateIcon("C:\WINDOWS\system32\shell32.dll", -128, 137, 275, 32, 32, BitOR($SS_NOTIFY,$WS_GROUP))

GUICtrlSetOnEvent(-1, "ckbxPicsClick")

GUICtrlCreateGroup("", -99, -99, 1, 1)

$btnOK = GUICtrlCreateButton("&OK", 110, 380, 135, 45, 0)

GUICtrlSetFont(-1, 10, 400, 0, "Verdana")

GUICtrlSetOnEvent(-1, "btnOKClick")

$btnCancel = GUICtrlCreateButton("&Cancel", 415, 380, 135, 45, 0)

GUICtrlSetFont(-1, 10, 400, 0, "Verdana")

GUICtrlSetOnEvent(-1, "btnCancelClick")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1

Sleep(100)

WEnd

Func btnCancelClick()

While 1

$btnCancel = GUIGetMsg()

If $btnCancel = $GUI_EVENT_CLOSE Then ExitLoop

Wend

EndFunc

Func btnOKClick()

EndFunc

Func ckbxDocsClick()

; Disconnect

DriveMapDel("Z:")

; Map Z drive

DriveMapAdd("Z:", "\\Edward\Users\Edward P. Sager\Documents")

EndFunc

Func ckbxDownloadsClick()

; Disconnect

DriveMapDel("S:")

; Map S drive

DriveMapAdd("S:", "\\Edward\Downloads")

EndFunc

Func ckbxFlashClick()

; Disconnect

DriveMapDel("X:")

; Map X drive

DriveMapAdd("X:", "\\Edward\Flash Projects")

EndFunc

Func ckbxPicsClick()

; Disconnect

DriveMapDel("W:")

; Map W drive

DriveMapAdd("W:", "\\Edward\Users\Edward P. Sager\Pictures")

EndFunc

Func ckbxSoftClick()

; Disconnect

DriveMapDel("Y:")

; Map Y drive

DriveMapAdd("Y:", "\\Edward\EdsSoftware")

EndFunc

Func Form1_1Close()

EndFunc

Func Form1_1Maximize()

EndFunc

Func Form1_1Minimize()

EndFunc

Func Form1_1Restore()

EndFunc

GUI_3.au3

Posted

Ok, your main problem is that you are using GuiGetMsg() when your GUI is using the GuiOnEventMode option.

If the GUIOnEventMode option is set to 1 then the return from GUIGetMsg is always 0 and the @error is set to 1.

Your GUI won't close, because the function that is called when the Close event happens does nothing!

GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_1Close")

Func Form1_1Close()

EndFunc  ;==>Form1_1Close

These are not necessary:

GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1_1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1_1Maximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1_1Restore")

because you are not using the GUIEventOptions option

If the option GUIEventOptions is set to 1 the minimize, restore and maximize button will not do any action on the window just a simple notification.

Your Koda generated the code in the GUIOnEventMode. If you want to use a loop and get the events using GuiGetMsg() then open Koda's configuration menu (Ctrl+k), go to code generator and uncheck the option "Generate OnEvent code"

Here. I commented the lines that were unnecessary and tidied it up a bit.

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=form2.kxfdocuments\sync files\scripting\autoit\form2.kxf
$Form1_1 = GUICreate("Choose network map...", 661, 441, 204, 157, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
GUISetIcon("D:03.ico")
GUISetFont(11, 400, 0, "Verdana")
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1_1Close")
;~ GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1_1Minimize")
;~ GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1_1Maximize")
;~ GUISetOnEvent($GUI_EVENT_RESTORE, "Form1_1Restore")
$grpChoices = GUICtrlCreateGroup("Mapping choices: ", 5, 5, 650, 360)
GUICtrlSetFont(-1, 16, 400, 0, "Verdana")
$ckbxFlash = GUICtrlCreateCheckbox("Edward\Flash Projects", 395, 155, 225, 30)
GUICtrlSetFont(-1, 12, 800, 0, "Verdana")
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER + $GUI_DOCKVCENTER + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetOnEvent(-1, "ckbxFlashClick")
$ckbxDocs = GUICtrlCreateCheckbox("Edward\Documents", 235, 65, 200, 30)
GUICtrlSetFont(-1, 12, 800, 0, "Verdana")
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER + $GUI_DOCKVCENTER + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetOnEvent(-1, "ckbxDocsClick")
$ckbxSoft = GUICtrlCreateCheckbox("Edward\EdsSoftware", 50, 155, 215, 30)
GUICtrlSetFont(-1, 12, 800, 0, "Verdana")
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER + $GUI_DOCKVCENTER + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetOnEvent(-1, "ckbxSoftClick")
$ckbxPics = GUICtrlCreateCheckbox("Edward\Pictures", 50, 245, 175, 30)
GUICtrlSetFont(-1, 12, 800, 0, "Verdana")
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER + $GUI_DOCKVCENTER + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetOnEvent(-1, "ckbxPicsClick")
$ckbxDownloads = GUICtrlCreateCheckbox("Edward\Downloads", 395, 245, 195, 30)
GUICtrlSetFont(-1, 12, 800, 0, "Verdana")
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER + $GUI_DOCKVCENTER + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlSetOnEvent(-1, "ckbxDownloadsClick")
$iconDocs = GUICtrlCreateIcon("C:\WINDOWS\system32\shell32.dll", -127, 315, 95, 32, 32, BitOR($SS_NOTIFY, $WS_GROUP))
GUICtrlSetOnEvent(-1, "ckbxDocsClick")
$iconSoft = GUICtrlCreateIcon("C:\WINDOWS\system32\shell32.dll", -5, 137, 185, 32, 32, BitOR($SS_NOTIFY, $WS_GROUP))
GUICtrlSetOnEvent(-1, "ckbxSoftClick")
$iconFlash = GUICtrlCreateIcon("C:\Program Files\Adobe\Adobe Flash CS3\Flash.exe", -6, 495, 185, 32, 32, BitOR($SS_NOTIFY, $WS_GROUP))
GUICtrlSetOnEvent(-1, "ckbxFlashClick")
$iconDownloads = GUICtrlCreateIcon("C:\WINDOWS\system32\shell32.dll", -89, 495, 275, 32, 32, BitOR($SS_NOTIFY, $WS_GROUP))
GUICtrlSetOnEvent(-1, "ckbxDownloadsClick")
$iconPics = GUICtrlCreateIcon("C:\WINDOWS\system32\shell32.dll", -128, 137, 275, 32, 32, BitOR($SS_NOTIFY, $WS_GROUP))
GUICtrlSetOnEvent(-1, "ckbxPicsClick")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$btnOK = GUICtrlCreateButton("&OK", 110, 380, 135, 45, 0)
GUICtrlSetFont(-1, 10, 400, 0, "Verdana")
GUICtrlSetOnEvent(-1, "btnOKClick")
$btnCancel = GUICtrlCreateButton("&Cancel", 415, 380, 135, 45, 0)
GUICtrlSetFont(-1, 10, 400, 0, "Verdana")
GUICtrlSetOnEvent(-1, "btnCancelClick")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func btnCancelClick()
    Exit;Exit the script when cancel is pressed.
;~  While 1
;~      $btnCancel = GUIGetMsg()
;~      If $btnCancel = $GUI_EVENT_CLOSE Then ExitLoop
;~  WEnd
EndFunc   ;==>btnCancelClick

Func btnOKClick()
    ;I don't know what you'd want to do here, since the mapping seems to be done
    ;When you click on a checkbox...
EndFunc   ;==>btnOKClick

Func ckbxDocsClick()
    ; Disconnect
    DriveMapDel("Z:")
    ; Map Z drive
    DriveMapAdd("Z:", "\\Edward\Users\Edward P. Sager\Documents")
EndFunc   ;==>ckbxDocsClick

Func ckbxDownloadsClick()
    ; Disconnect
    DriveMapDel("S:")
    ; Map S drive
    DriveMapAdd("S:", "\\Edward\Downloads")
EndFunc   ;==>ckbxDownloadsClick

Func ckbxFlashClick()
    ; Disconnect
    DriveMapDel("X:")
    ; Map X drive
    DriveMapAdd("X:", "\\Edward\Flash Projects")
EndFunc   ;==>ckbxFlashClick

Func ckbxPicsClick()
    ; Disconnect
    DriveMapDel("W:")
    ; Map W drive
    DriveMapAdd("W:", "\\Edward\Users\Edward P. Sager\Pictures")
EndFunc   ;==>ckbxPicsClick

Func ckbxSoftClick()
    ; Disconnect
    DriveMapDel("Y:")
    ; Map Y drive
    DriveMapAdd("Y:", "\\Edward\EdsSoftware")
EndFunc   ;==>ckbxSoftClick

Func Form1_1Close()
    Exit;Exit the script when the [x] button is pressed.
EndFunc   ;==>Form1_1Close
;~ Func Form1_1Maximize()

;~ EndFunc   ;==>Form1_1Maximize
;~ Func Form1_1Minimize()

;~ EndFunc   ;==>Form1_1Minimize
;~ Func Form1_1Restore()

;~ EndFunc   ;==>Form1_1Restore
Posted

Nahuel,

Thank you very much. I was confused by the extra lines in the original Koda code. Also, what you altered not only help me understand what I was doing, but also made the script work as I desired.

As for:

CODE
Func btnOKClick()

;I don't know what you'd want to do here, since the mapping seems to be done

;When you click on a checkbox...

EndFunc ;==>btnOKClick

I wanted to have the network shares mapped after clicking the "OK" button. So, I figured I would have to change the GUICtrlSetOnEvent of the checkboxes to something like "SpecialEvents," as shown in the AutoIt example titled, "GUICtrlSetOnEvent." Instead, I got rid of the "OK" button and changed the "Cancel" button to read "Complete."

Again, thank you,

edsager

  • 1 year later...
Posted

Love the idea behind the script/gui, and am working it out now. However I get an error when I try to compile it to test.

for every $WS_..." variable it tells me:

GUI_3.au3(5,93) : WARNING: $WS_MINIMIZEBOX: possibly used before declaration.

I haven't changed the script one bit so not sure what's happening. Do I need to recreate the form myself in koda or?

Posted

Add

#include <WindowsConstants.au3>
at the top of your script

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
  • Recently Browsing   0 members

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