Jump to content

Recommended Posts

Posted (edited)

This is a complete newb question I'm sure but I could not find the anwser in the help file or searching the forums.

When, for example you are entering a new edit field GUICtrlCreateEdit you have to put the text you want and then the left and top and optionally the width and height. I cannot find out what those numbers are. Is it pixels? or a percentage? In the code I have posted I am trying to get the OK button below the edit box but I don't know what numbers to use. I think that I have the first number right (40) but again I don't know what that means, I just guessed enough times to get it where I want it and that logic doesn't apply to the ok button as I cannot get it where I need it. So in conclusion, what are the numbers that you have to enter in the left and top fields? Is it the number of pixels? If someone knows or knows where I might find this in the help file would be great as I am so close to getting what I need.

Thanks in advance.

UICreate("test")
GUISetState (@SW_SHOW)
$okbutton = GUICtrlCreateButton ("OK",40,30)
GUICtrlCreateLabel ("Enter Username",40,90)
GuiCtrlCreateEdit("", 40, 110, 150, 70)
Edited by Larry
Posted (edited)

From the help file

GUICtrlCreateEdit ( "text", left, top [, width [, height [, style [, exStyle]]]] )

Left - 40 from the left of the window

Top - 110 from the top

width - 150 wide

height - 70 from top to bottom

Next control should be more than 110 + 70 (Top + height)

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted

Is there a refrence guide for the API pixel? I don't know if there is. I guess what I'm looking for is something to tell me how many pixels=1 inch or something similar to that.

Posted (edited)

So now that I have the button out of the way I am trying to set it up so that when you click the OK button the msgbox show the value in the editbox. The code below has what I have so far and what I am thinking of adding inside the While 1 statement is this

If $msg = $okbutton then

If $userinput = "" Then MsgBox (0,"","empty")

Else MsgBox (0,"",$userinput)

I keep getting a number in the message box even before I have a chance to enter anything into the editbox.

#include <GUIConstants.au3>

GUICreate("test")
GUISetState (@SW_SHOW)
$okbutton = GUICtrlCreateButton ("OK",40,180)
GUICtrlCreateLabel ("Enter Username",40,90)
$userinput = GuiCtrlCreateEdit("", 40, 110, 150, 70)


While 1
    $msg = GUIGetMsg ()
    if $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
Edited by Larry
Posted (edited)

Thank you Polyphem, that worked. I am still having an issue though with the copying what ever is in the editbox to the clipboard. When I enter something into the box then use edit copy, then paste into notepad it is always a number not the text that I entered. I posted my code so far. Thanks again.

#include <GUIConstants.au3>

GUICreate("test")
GUISetState (@SW_SHOW)
$okbutton = GUICtrlCreateButton ("OK",40,180,50)
$cancelbutton = GUICtrlCreateButton ("Cancel",100,180,50)
GUICtrlCreateLabel ("Enter Username",40,90)
$userinput = GuiCtrlCreateEdit("", 40, 110, 150, 70)
$filemenu = GUICtrlCreateMenu ("&File")
$fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
GUICtrlSetState (-1,$GUI_DEFBUTTON)
$fileexit = GUICtrlCreateMenuitem ("Exit",$filemenu,3)
$filesave = GUICtrlCreateMenuitem ("Save",$filemenu,1)
$editmenu = GUICtrlCreateMenu ("&Edit")
$editcopy = GUICtrlCreateMenuitem ("Copy",$editmenu)


While 1
    $msg = GUIGetMsg ()
    if $msg = $GUI_EVENT_CLOSE Or $msg = $fileexit Or $msg = $cancelbutton Then ExitLoop
        If $msg = $editcopy Then
            ClipPut ($userinput)
        EndIf
    
    If $msg = $fileitem Then
        FileOpenDialog ("",@WindowsDir,"DLL (*.dll)")
    EndIf
    If $msg = $okbutton Then
        If GUICtrlRead ($userinput) = "" Then
            MsgBox (16,"","Please Enter Your Username into the Text Box")
        Else
            MsgBox (0,"",GUICtrlRead($userinput))
        EndIf
    EndIf   
    If $msg = $filesave Then
        FileSaveDialog ("Choose File",@mydocumentsdir,"All (*.*)")
        If @error Then
            MsgBox (0,"","save cancelled")
        EndIf
        
    EndIf
    WEnd
Edited by Larry
Posted (edited)

To get the content of a control always use Guictrlread(), if you just refer to $userinput you will only get the control ID. Also for username i would sugest to use an input control instead of an edit control... and please, next time use the AUTOIT tag (capital letters) instead of code tag, as these are hard to copy and paste.

#include <GUIConstants.au3>

GUICreate("test")
GUISetState (@SW_SHOW)
$okbutton = GUICtrlCreateButton ("OK",40,180,50)
$cancelbutton = GUICtrlCreateButton ("Cancel",100,180,50)
GUICtrlCreateLabel ("Enter Username",40,90)
$userinput = GUICtrlCreateInput("", 40, 110, 150, 20)
$filemenu = GUICtrlCreateMenu ("&File")
$fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
GUICtrlSetState (-1,$GUI_DEFBUTTON)
$fileexit = GUICtrlCreateMenuitem ("Exit",$filemenu,3)
$filesave = GUICtrlCreateMenuitem ("Save",$filemenu,1)
$editmenu = GUICtrlCreateMenu ("&Edit")
$editcopy = GUICtrlCreateMenuitem ("Copy",$editmenu)


While 1
    $msg = GUIGetMsg ()
    if $msg = $GUI_EVENT_CLOSE Or $msg = $fileexit Or $msg = $cancelbutton Then ExitLoop
        If $msg = $editcopy Then
            ClipPut(guictrlread($userinput))
        EndIf
    
    If $msg = $fileitem Then
        FileOpenDialog ("",@WindowsDir,"DLL (*.dll)")
    EndIf
    If $msg = $okbutton Then
        If GUICtrlRead ($userinput) = "" Then
            MsgBox (16,"","Please Enter Your Username into the Text Box")
        Else
            MsgBox (0,"",GUICtrlRead($userinput))
        EndIf
    EndIf   
    If $msg = $filesave Then
        FileSaveDialog ("Choose File",@mydocumentsdir,"All (*.*)")
        If @error Then
            MsgBox (0,"","save cancelled")
        EndIf
    EndIf
WEnd
Edited by Polyphem
This post will be edited again by Polyphem: Tomorrow, 11:55 AM
Posted

I'm afraid that I don't quit understand what you mean by next time use the AUTOIT tag (capital letters) instead of code tag. Do you mean when I post code. I am just using the insert codebox function on the right of the box then pasting my code in. Is there another way to do this? Sorry for the headache but this is the first time that I have attempted to post code in a forum.

Posted

Dont bother, didnt want to flame. Yes, when posting code replace the "code" in the brackets with "AUTOIT", then the code will be properly formatted. I dont think there is an insert function for that tag... just a hint, no offence meant.

This post will be edited again by Polyphem: Tomorrow, 11:55 AM
Posted

So now I am trying to open another au3 file from inside this GUI but again failing. When you click the help about menu I am looking for it to open another window with the about message. I have read around and think that maybe I should be creating a child GUI to this one? Or maybe just call the about.au3 like I have now? I cannot find anywhere in the help that explains how to create a child gui. So thats what I am looking for.

include <GUIConstants.au3>

GUICreate("test")
GUISetState (@SW_SHOW)
$okbutton = GUICtrlCreateButton ("OK",40,180,50)
$cancelbutton = GUICtrlCreateButton ("Cancel",100,180,50)
GUICtrlCreateLabel ("Enter Username",40,90)
$userinput = GuiCtrlCreateEdit("", 40, 110, 150, 70)
$filemenu = GUICtrlCreateMenu ("&File")
$fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
GUICtrlSetState (-1,$GUI_DEFBUTTON)
$fileexit = GUICtrlCreateMenuitem ("Exit",$filemenu,3)
$filesave = GUICtrlCreateMenuitem ("Save",$filemenu,1)
$editmenu = GUICtrlCreateMenu ("&Edit")
$editcopy = GUICtrlCreateMenuitem ("Copy",$editmenu)
$helpmenu = GUICtrlCreateMenu ("&Help")
$helpitem = GUICtrlCreateMenuitem ("About",$helpmenu)

While 1
    $msg = GUIGetMsg ()
    if $msg = $GUI_EVENT_CLOSE Or $msg = $fileexit Or $msg = $cancelbutton Then ExitLoop
        If $msg = $editcopy Then
            ClipPut (GUICtrlRead($userinput))
        EndIf
    
    If $msg = $fileitem Then
        FileOpenDialog ("",@WindowsDir,"DLL (*.dll)")
    EndIf
    If $msg = $okbutton Then
        If GUICtrlRead ($userinput) = "" Then
            MsgBox (16,"","Please Enter Your Username into the Text Box")
        Else
            MsgBox (0,"",GUICtrlRead($userinput))
        EndIf
    EndIf   
    If $msg = $filesave Then
        FileSaveDialog ("Choose File",@mydocumentsdir,"All (*.*)")
        If @error Then
            MsgBox (0,"","save cancelled")
        EndIf
    EndIf
    If $msg = $helpitem Then
        Run(@AutoItExe & ' /AutoIt3ExecuteScript about.au3',@workingdir)
    EndIf
WEnd
Posted

For @AutoItExe the help file says:

The full path and filename of the AutoIt executable currently running. For compiled scripts it is the path of the compiled script.

So its a path and not a command, the path and filename of your "test" GUI to be precise.

Also if you use the about.au3 only for the test.au3, it would be better to include it, so that when compiling, it is added to the resulting .exe. Is it located in the same directory as the test.au3? then maybe

If $msg = $helpitem Then
        include "about.au3"
    EndIf

will work.

This post will be edited again by Polyphem: Tomorrow, 11:55 AM
Posted

So I added the script you gave me and I get an error when running the script. Yes the about.su3 is in the same directory as test.au3. I added the include line and when I run the program I get "include "about.au3" ^Error error:error parsing function call"

Is this what I need to be able to open the child GUI? or is it just something that I should include in my scripts?

Posted

For @AutoItExe the help file says:

The full path and filename of the AutoIt executable currently running. For compiled scripts it is the path of the compiled script.

So its a path and not a command, the path and filename of your "test" GUI to be precise.

Also if you use the about.au3 only for the test.au3, it would be better to include it, so that when compiling, it is added to the resulting .exe. Is it located in the same directory as the test.au3? then maybe

If $msg = $helpitem Then
        include "about.au3"
    EndIf

will work.

You can't do includes by condition

Include the file, run the function on the condition.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted

So, were getting there. What you proposed worked, but, When I run the Test.au3 I get the about.au3 box instantly and when I click the ok button on testa.au3 nothing happens. I have to hit ok in the about.au3 for the whole shootn match to close. I have attached both the test.au3 and the about.au3 for review.

#include <GUIConstants.au3>
#include "about.au3"
GUICreate("test")
GUISetState (@SW_SHOW)
$okbutton = GUICtrlCreateButton ("OK",40,180,50)
$cancelbutton = GUICtrlCreateButton ("Cancel",100,180,50)
GUICtrlCreateLabel ("Enter Username",40,90)
$userinput = GuiCtrlCreateEdit("", 40, 110, 150, 70)
$filemenu = GUICtrlCreateMenu ("&File")
$fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
GUICtrlSetState (-1,$GUI_DEFBUTTON)
$fileexit = GUICtrlCreateMenuitem ("Exit",$filemenu,3)
$filesave = GUICtrlCreateMenuitem ("Save",$filemenu,1)
$editmenu = GUICtrlCreateMenu ("&Edit")
$editcopy = GUICtrlCreateMenuitem ("Copy",$editmenu)
$helpmenu = GUICtrlCreateMenu ("&Help")
$helpitem = GUICtrlCreateMenuitem ("About",$helpmenu)
$shortcut = GUICtrlCreateButton ("Make A Shortcut",40,300)
$remshortcut = GUICtrlCreateButton ("Remove Shortcut",140,300)
While 1
    $msg = GUIGetMsg ()
    if $msg = $GUI_EVENT_CLOSE Or $msg = $fileexit Or $msg = $cancelbutton Then ExitLoop
        If $msg = $editcopy Then
            ClipPut (GUICtrlRead($userinput))
        EndIf
    
    If $msg = $fileitem Then
        FileOpenDialog ("",@WindowsDir,"DLL (*.dll)")
    EndIf
    If $msg = $okbutton Then
        If GUICtrlRead ($userinput) = "" Then
            MsgBox (16,"","The text box cannot be empty")
        Else
            MsgBox (0,"",GUICtrlRead($userinput))
        EndIf
    EndIf   
    If $msg = $filesave Then
        FileSaveDialog ("Choose File",@mydocumentsdir,"All (*.*)")
        If @error Then
            MsgBox (0,"","save cancelled")
        EndIf
    EndIf
    If $msg = $helpitem Then
        show_about()
    EndIf
    If $msg = $shortcut Then
        FileCreateShortcut (@WindowsDir & "\system32\sol.exe",@DesktopDir & "\Solitare.lnk")
        MsgBox (64,"","There is now a solitare shortcut on your desktop")
    EndIf
    If $msg = $remshortcut Then
        If FileExists (@desktopdir & "\Solitare.lnk") Then
            FileDelete (@desktopdir & "\Solitare.lnk")
        Else
            MsgBox (64,"","Shortcut does not exist.  You might want to hit the button next to you first.")
        EndIf
    EndIf
WEndoÝ÷ Ø    Ýiº.µ«·jëh×6#include <GUIConstants.au3>
Func show_about()
    
EndFunc

GUICreate("About",300,200)
GUISetState (@SW_SHOW)
$okbutton = GUICtrlCreateButton ("OK",100,160,100)
GUICtrlCreateLabel("This script was created by the hard work of me and",40,20)
GUICtrlCreateLabel("the wonderful programming language AutoIt.",40,40)



While 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE OR $msg = $okbutton Then 
        ExitLoop
    EndIf
WEnd
Posted

about.au3

Func show_about()

$aboutgui = GUICreate("About",300,200)
GUISetState (@SW_SHOW)
$okbutton = GUICtrlCreateButton ("OK",100,160,100)
GUICtrlCreateLabel("This script was created by the hard work of me and",40,20)
GUICtrlCreateLabel("the wonderful programming language AutoIt.",40,40)



While 1
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE OR $msg = $okbutton Then
        GUIDelete($aboutgui)
        ExitLoop
    EndIf
WEnd

EndFunc
This post will be edited again by Polyphem: Tomorrow, 11:55 AM
Posted

That got it. Woo-hoo. Now as usual, this fix causes another issue. After I hit the about button the about.au3 opens and I can click OK to close it but then no buttons or functions work in the main test.au3 window after the about.au3 closes. It just sits there and I can click the buttons and enter things into the text box but none of the controls work?

I pasted both the test and the about for review.

#NoTrayIcon
#include <GUIConstants.au3>
#include "about.au3"
GUICreate("test")
GUISetState (@SW_SHOW)
$okbutton = GUICtrlCreateButton ("OK",40,180,50)
$cancelbutton = GUICtrlCreateButton ("Cancel",100,180,50)
GUICtrlCreateLabel ("Enter Username",40,90)
$userinput = GuiCtrlCreateEdit("", 40, 110, 150, 70)
$filemenu = GUICtrlCreateMenu ("&File")
$fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
GUICtrlSetState (-1,$GUI_DEFBUTTON)
$fileexit = GUICtrlCreateMenuitem ("Exit",$filemenu,3)
$filesave = GUICtrlCreateMenuitem ("Save",$filemenu,1)
$editmenu = GUICtrlCreateMenu ("&Edit")
$editcopy = GUICtrlCreateMenuitem ("Copy",$editmenu)
$helpmenu = GUICtrlCreateMenu ("&Help")
$helpitem = GUICtrlCreateMenuitem ("About",$helpmenu)
$shortcut = GUICtrlCreateButton ("Make A Shortcut",40,300)
$remshortcut = GUICtrlCreateButton ("Remove Shortcut",140,300)
While 1
    $msg = GUIGetMsg ()
    if $msg = $GUI_EVENT_CLOSE Or $msg = $fileexit Or $msg = $cancelbutton Then ExitLoop
        If $msg = $editcopy Then
            ClipPut (GUICtrlRead($userinput))
        EndIf
    
    If $msg = $fileitem Then
        FileOpenDialog ("",@WindowsDir,"DLL (*.dll)")
    EndIf
    If $msg = $okbutton Then
        If GUICtrlRead ($userinput) = "" Then
            MsgBox (16,"","The text box cannot be empty")
        Else
            MsgBox (0,"",GUICtrlRead($userinput))
        EndIf
    EndIf   
    If $msg = $filesave Then
        FileSaveDialog ("Choose File",@mydocumentsdir,"All (*.*)")
        If @error Then
            MsgBox (0,"","save cancelled")
        EndIf
    EndIf
    If $msg = $helpitem Then
        show_about()
    EndIf
    If $msg = $shortcut Then
        FileCreateShortcut (@WindowsDir & "\system32\sol.exe",@DesktopDir & "\Solitare.lnk")
        MsgBox (64,"","There is now a solitare shortcut on your desktop")
    EndIf
    If $msg = $remshortcut Then
        If FileExists (@desktopdir & "\Solitare.lnk") Then
            FileDelete (@desktopdir & "\Solitare.lnk")
        Else
            MsgBox (64,"","Shortcut does not exist.  You might want to hit the button next to you first.")
        EndIf
    EndIf
WEndoÝ÷ Ù«­¢+Ø¥¹±Õ±ÐíU%
½¹ÍѹÑ̹ÔÌÐì)չ͡½Ý}½ÕÐ ¤($(()U%
ÉÑ ÅÕ½Ðí½ÕÐÅÕ½Ðì°ÌÀÀ°ÈÀÀ¤)U%MÑMÑÑ¡M]}M!=¤(ÀÌØí½­ÕÑѽ¸ôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½Ðí=,ÅÕ½Ðì°ÄÀÀ°ÄØÀ°ÄÀÀ¤)U%
Ñɱ
ÉÑ1° ÅÕ½ÐíQ¡¥ÌÍÉ¥ÁÐÝÌÉÑäÑ¡¡Éݽɬ½µ¹ÅÕ½Ðì°ÐÀ°ÈÀ¤)U%
Ñɱ
ÉÑ1° ÅÕ½Ðíѡݽ¹ÉÕ°Áɽɵµ¥¹±¹ÕÕѽ%иÅÕ½Ðì°ÐÀ°ÐÀ¤((()]¡¥±Ä($ÀÌØíµÍôU%Ñ5Í ¤(%¥ÀÌØíµÍôÀÌØíU%}Y9Q}
1=M=HÀÌØíµÍôÀÌØí½­ÕÑѽ¸Q¡¸($%U%±Ñ ÅÕ½Ðí½ÕÐÅÕ½Ðì¤(%¹%)]¹()¹Õ¹
Posted

OK I just had a brain storm for a program that I would like to make. We have a bunch of users here that we need to put behind our corporate firewall. Instead of me walking around to all the machines and doing this I thought that I would do up a GUI scipt for it. So what I am looking for is a way to test the destination machine to see if it is even on first, then somehow query the names of the network connections (i.e. local area connection 1) and return that to a variable that I can call later. Then I need to somehow be able to send the netsh command from XP to the destination computer in order to changes its gateway on the specified network adapter. I will try most of this but right off the bat I need to know if auoit it has some sort of window function that will allow me to see the result of variable. For instance, the user enteres a computer name and the script queries the network adapter names then displays those names into something like a dropdown box so that later when you are ready to change the computers gateway you can choose the computers NIC card from the drop down list. Make sense?

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...