Jump to content
Sign in to follow this  
thor918

gui window - auth login

Recommended Posts

thor918

hi. this is probably easy to solve, but how do you have a gui promting the user for information, and when the function gets the info, remove the gui and continue script.

I have managed to work some code out, but it dosen't work as I want it just yet....

$auth = _authlogin($username)
                    if $auth <> 0 Then
                        MsgBox(64, "Password entered", $auth[1])
                    EndIf

func _authlogin($username)
    Dim $resultArray[2]
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Ressurs authentisering",260, 125, -1, -1, BitOR($WS_DLGFRAME,$WS_CLIPSIBLINGS))
    $brukernavn = GUICtrlCreateInput($username, 88, 8, 161, 21)
    $passord = GUICtrlCreateInput("", 88, 32, 161, 21,0x0020)
    $ok = GUICtrlCreateButton("OK", 48, 72, 75, 25, 0)
    $Avbryt = GUICtrlCreateButton("Avbryt", 144, 72, 75, 25, 0)
    $Label1 = GUICtrlCreateLabel("Brukernavn", 8, 8, 59, 17)
    $Label2 = GUICtrlCreateLabel("Passord", 8, 40, 42, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE,$Avbryt
                GUIDelete() 
                return 0
            Case $ok
                $resultArray[0] = GUICtrlRead($brukernavn)
                $resultArray[1] = GUICtrlRead($passord) 
                GUIDelete()             
                return $resultArray
        EndSwitch
        If _IsPressed('0D') Then
            Switch ControlGetFocus($Form1)
                Case 'Edit1','Edit2'
                    $resultArray[0] = GUICtrlRead($brukernavn)
                    $resultArray[1] = GUICtrlRead($passord) 
                    GUIDelete() 
                    return $resultArray
            EndSwitch
        EndIf
    WEnd
EndFunc

thanks

Share this post


Link to post
Share on other sites
Zedna

Code looks good.

What's the problem exactly?

Do you have First main GUI or your main script is nonGUI? If yes (GUI) then you must use GUIGetMsg() with advanced parameter.

Post also code for main script...

EDIT:

Look here and here

Edited by Zedna

Share this post


Link to post
Share on other sites
thor918

I'm using a msn style popup, and it seems that if I remove that include it works

http://www.autoitscript.com/forum/index.ph...3&hl=GioVit

the problem is that when I push buttons in the authdialog, nothing happens. but if the guimessage include is removed. a messagebox appears whith the entered password..

doh!

it seems the guimessage have "Opt("GuiOnEventMode",1)"

witch seems to be the cause.. any solution?

#include <guimessage.au3>
#include <include/GUIConstants.au3>

; Script Start - Add your code below here
$username = "thor"
$auth = _authlogin($username)
if $auth <> 0 Then
    MsgBox(64, "Password entered", $auth[1])
EndIf

func _authlogin($username)
    Dim $resultArray[2]
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Ressurs authentisering",260, 125, -1, -1, BitOR($WS_DLGFRAME,$WS_CLIPSIBLINGS))
    $brukernavn = GUICtrlCreateInput($username, 88, 8, 161, 21)
    $passord = GUICtrlCreateInput("", 88, 32, 161, 21,0x0020)
    $ok = GUICtrlCreateButton("OK", 48, 72, 75, 25, 0)
    $Avbryt = GUICtrlCreateButton("Avbryt", 144, 72, 75, 25, 0)
    $Label1 = GUICtrlCreateLabel("Brukernavn", 8, 8, 59, 17)
    $Label2 = GUICtrlCreateLabel("Passord", 8, 40, 42, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE,$Avbryt
                GUIDelete() 
                return 0
            Case $ok
                $resultArray[0] = GUICtrlRead($brukernavn)
                $resultArray[1] = GUICtrlRead($passord) 
                GUIDelete()             
                return $resultArray
        EndSwitch
        If _IsPressed('0D') Then
            Switch ControlGetFocus($Form1)
                Case 'Edit1','Edit2'
                    $resultArray[0] = GUICtrlRead($brukernavn)
                    $resultArray[1] = GUICtrlRead($passord) 
                    GUIDelete() 
                    return $resultArray
            EndSwitch
        EndIf
    WEnd
EndFunc
Edited by thor918

Share this post


Link to post
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
Sign in to follow this  

×