Sign in to follow this  
Followers 0
shanet

:@ Figuring out the WinHandle...

16 posts in this topic

#1 ·  Posted (edited)

Hi everyone,

I'm sure you get heaps of questions on winhandles on these forums, but I am having problems.

I have a traymenuitem that is supposed to open the main GUI but cant get it to work?

If you tell me what information you need, I will let you know A.S.A.P!!!

Thanks everyone,

shanet

EDIT: If its possible, I would like it to be absolutely transparent and set the winhandle to a variable? Thanks

Edited by shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hello shanet,

First, Welcome to the AutoIt Forums :x

I know you just want to jump right into it, but this is one of those things in life that pay off more by doing the studying first. It will save you time, and us as well. Spend some time reading the 'Help File' and taking part in some tutorials. There are many tutorials on You Tube along with a Tutorial built in AutoIt in Example section of the Forums called: 'AutoIt 1-2-3'

This Forum was designed to help fellow coders that encounter problems with their code. Asking for someone to write your code, will not get many good responses.

Once you have tried writing your own script, and your still having problems with it, Then create a post explaining in detail what your trying to achieve with your script, what errors/problems your having, and include your script in [autoit ] or [code ] tags, or at least an example of it. You will find that members will be more motivated to help those that show they are attempting to learn the language.

Realm

PS. If you give us the information on what results you expect, what errors your getting, and ultimately the code or an example of it, We will help A.S.A.P, or when someone with experience/knowledge of your needs comes online. You very much left your post very open-ended, with a thousand posibilites of your needs, and multitudes more of possibilities to find a solution.

Edit: Try reading up in the Help file upon these functions:

WinGetHandle()

WinSetTrans()

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Hello shanet,

First, Welcome to the AutoIt Forums :x

I know you just want to jump right into it, but this is one of those things in life that pay off more by doing the studying first. It will save you time, and us as well. Spend some time reading the 'Help File' and taking part in some tutorials. There are many tutorials on You Tube along with a Tutorial built in AutoIt in Example section of the Forums called: 'AutoIt 1-2-3'

This Forum was designed to help fellow coders that encounter problems with their code. Asking for someone to write your code, will not get many good responses.

Once you have tried writing your own script, and your still having problems with it, Then create a post explaining in detail what your trying to achieve with your script, what errors/problems your having, and include your script in [autoit ] or [code ] tags, or at least an example of it. You will find that members will be more motivated to help those that show they are attempting to learn the language.

Realm

PS. If you give us the information on what results you expect, what errors your getting, and ultimately the code or an example of it, We will help A.S.A.P, or when someone with experience/knowledge of your needs comes online. You very much left your post very open-ended, with a thousand posibilites of your needs, and multitudes more of possibilities to find a solution.

Edit: Try reading up in the Help file upon these functions:

WinGetHandle()

WinSetTrans()

Thankyou Realm,

I have been doing quite a lot of googling and sitting in the help files as well as trying codes and entering codes and hoping to god it would help me, however I did not find what you have told me about. I do not expect people to write the code for me, rather to help me in the creation of my own, that's why I said if anyone asks for more info I would gladly give it to them.

I believe I also said I needed help with actually doing the code not just figuring out errors - the reason I did not give errors is because there was no code related to winhandles to error.

However thankyou for the lovely welcome, I shall have a look at the WinGetHandle() function and will reply again if I have any troubles.

shanet


[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

OK, I have got a hand on my handles (that wasn't meant to be a joke) with the following code:

Func _Create()

Local $msg, $winhandle

Dim $Create[3]

; $winhandle = WinGetHandle("classname=Your Background Task Manager")

$winhandle = GUICreate("Create Task", 400, 400)

$Create["OK"] = GUICtrlCreateButton("OK", 320, 320, 60, 40)

$Create["Cancel"] = GUICtrlCreateButton("Cancel", 20, 320, 60, 40)

GUISetState()

Do

$msg = GUIGetMsg()

MsgBox(0, "WinHandle", $winhandle) ;Returns the Winhandle in a msgbox

if $msg = $Create["OK"] Then

Sleep(1000)

GUIDelete($winhandle)

Elseif $msg = $Create["Cancel"] Then

GUIDelete($winhandle)

EndIf

Until 1=1

EndFunc

Therefore, would I be right in concluding that its the GUIDelete function not working?


[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

shanet,

A lot of us here love to help, but it would be a lot easier if you would explain in detail what it is that your attempting to achieve, then for me to guess and have a dozen posts of me trying to guess a number between 1 and a 100. If you show what code you have thus far, and describe what it is your attempting to do, and what you need help with. I am sure someone will be happy to help you.

Sorry if you took it that my post was implying that you were asking for someone to write your code. that post is a template where I just change the introduction name, and the PS message. So please I was not attempting to Imply anything, I am just used to alot of first time members, asking for code rather than help. What I was more implying was the last paragraph, where it describes how to get help here, by showing an example and giving more information.

From your original post, All I understand is that your trying to open a GUI from a traymenu. So, Information needed to better help would be:

1. Is the GUI an application you wrote, If so, is it in the same script as where the traymenu is?

2. How are you attempting call the GUI from the traymenu?

3. Ultimately If you have some code, why not show it, or at least an example of it? Seeing Code in most cases, makes it easier on us to help you find the proper solution, rather than a guess of 1 solution out of dozens.

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

shanet,

I don't understand your Do...Until Loop since 1=1, it will only run once. so I changed it to a While Loop which is more standard for GUI's. 2nd, I am only assuming here, but you want it to close after Cancel is pressed, so I added a ExitLoop, which will exit the WhileLoop.

Also you are using Arrays in a way that I don't understand. You created space for an array with Dim $Create[3]. However, $Create["OK"] is not a proper array argument. I changed those values to proper array values.

Is there a reason you need to assign those controls to an array? If not, I would suggest just assigning them to a variable like $create_ok and $create_cancel

either way, see if this works better for you:

_Create()

Func _Create()

    Local $msg, $winhandle
    Dim $Create[3]

    ;   $winhandle = WinGetHandle("classname=Your Background Task Manager")

    $winhandle = GUICreate("Create Task", 400, 400)
    $Create[0] = GUICtrlCreateButton("OK", 320, 320, 60, 40)
    $Create[1] = GUICtrlCreateButton("Cancel", 20, 320, 60, 40)

    GUISetState()

    While 1

        $msg = GUIGetMsg()
;~      MsgBox(0, "WinHandle", $winhandle)   ;Returns the Winhandle in a msgbox
        If $msg = $Create[0] Then
            Sleep(1000)
            GUIDelete($winhandle)
        EndIf
        If $msg = $Create[1] Then
            GUIDelete($winhandle)
            ExitLoop
        EndIf

    WEnd

EndFunc ;==>Create

Exit

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Sorry if you took it that my post was implying that you were asking for someone to write your code. that post is a template where I just change the introduction name, and the PS message. So please I was not attempting to Imply anything, I am just used to alot of first time members, asking for code rather than help.

Dont worry, no harm done :x

From your original post, All I understand is that your trying to open a GUI from a traymenu. So, Information needed to better help would be:

1. Is the GUI an application you wrote, If so, is it in the same script as where the traymenu is?

2. How are you attempting call the GUI from the traymenu?

3. Ultimately If you have some code, why not show it, or at least an example of it? Seeing Code in most cases, makes it easier on us to help you find the proper solution, rather than a guess of 1 solution out of dozens.

Realm

ok. To answer question 1: Yes, I have completely coded myself thus far.

2: I will include code.

3: Here it is: (variables and array declarations have been removed here... oops!)

Opt("TrayMenuMode" ,1)

Global $silenttray, $mainhandle, $traymsg, $msg, $silent, $traymenu, $terminate
Global $silentmode = 0
Dim $tray[4]

$tray["open"] = TrayCreateItem("Open Program Interface")
TrayItemSetState($tray["open"], $TRAY_UNCHECKED)                  ;It keeps checking itself, I am trying to stop that as well :(


$mainhandle = GUICreate("My Application", 400, 250)
GUISetBkColor( 0xFFFFEE )

$main[1] = GUICtrlCreateButton("First Button", 70, 90, 110, 40)
$main[2] = GUICtrlCreateButton("Second Button", 230, 90, 110, 40)


GUISetState()

Do

    $traymsg = TrayGetMsg()

    if $traymsg = $tray["open"] Then
        GUISetState(@SW_SHOW, $mainhandle)
    EndIf

    $msg = GUIGetMsg()

    if $msg = $GUI_EVENT_CLOSE or $msg = $file["exit"] Then
        GUISetState(@SW_HIDE)
    EndIf
Until $traymsg = $terminate

That should include all that you need?

And Thanks heaps for your help this far.

Edited by shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

shanet,

Read 2 posts above, our posts became crossed

Realm :x

Edit: I don't think I answered your original question, however I did not see any code for a traymenu with your previous example. I see it in your latest example, which I am looking at now

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Thanks Realm,

I just got that two minutes ago, implemented it and it works perfectly. Thankyou for that.

So what do you think about the other code?


[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

shanet,

again, I seen alot of problems with improper arrays which I fixed for you. and again I did'nt understand the Do...Until $traymsg = $terminate loop, so I changed it to a While loop for my testing purposes. Hope this gives you a more clear approach to arrays. Also you were missing some header file calls which I added at the top.

Works for me, let me know if your having any problems with it:

#Include <Constants.au3>
#include <GUIConstants.au3>


Opt("TrayMenuMode" ,1)
Local $tray[1], $main[3]

$tray[0] = TrayCreateItem("Open Program Interface")
TrayItemSetState($tray, $TRAY_UNCHECKED)                  ;It keeps checking itself, I am trying to stop that as well :(


$mainhandle = GUICreate("My Application", 400, 250)
GUISetBkColor( 0xFFFFEE )

$main[1] = GUICtrlCreateButton("First Button", 70, 90, 110, 40)
$main[2] = GUICtrlCreateButton("Second Button", 230, 90, 110, 40)


GUISetState()

While 1

    $traymsg = TrayGetMsg()

    if $traymsg = $tray[0] Then
        GUISetState(@SW_SHOW, $mainhandle)
    EndIf

    $msg = GUIGetMsg()

    if $msg = $GUI_EVENT_CLOSE Then; or $msg = $file["exit"] Then   <<<change $file to a proper array or variable
        GUISetState(@SW_HIDE)
        ExitLoop
    EndIf
WEnd
Exit

Realm


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

shanet,

again, I seen alot of problems with improper arrays which I fixed for you. and again I did'nt understand the Do...Until $traymsg = $terminate loop, so I changed it to a While loop for my testing purposes.

I was on a laptop is my only excuse, I didnt cut and paste properly - I did rather quickly, lazy me... sorry!

Hope this gives you a more clear approach to arrays.

I do understand arrays, however obviously not completely. I thought they were required to be a dim?

Also you were missing some header file calls which I added at the top.

Yes, again lazy lazy me :x

Thanks for this. Hopefully this works now.

shanet


[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I do understand arrays, however obviously not completely. I thought they were required to be a dim?

You can declare an array in Dim, Local, Global, Const. I quit using Dim along time ago, I mainly use Local and Global, and the occasional Const for its purpose. I have found no difference between Dim and Local, I am sure someone will come along and tell us the difference. However to change the size of an array can only be done with an array that has already been declared in one way or another, and can only be done with ReDim.

However, I was pointing more to $array['word'], I have never seen this done in AutoIt, and I could be wrong, but I do believe that is improper and what was breaking most of your script. Using Numerals rather than 'word' is what is common and accepted.

If you want to assign those controls in a way that identifies them with the word then using a variable will suffice such as:

$create_ok

$create_cancel

$createOK

$createCancel

$button_Create_OK

and so on.

Realm

Edit: Fixed typos

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

I just had a look at your code, and compared it to mine - I understand the while loop now!! Thankyou so much!

So I looked at your code and managed to implement it into mine and it all WORKS!

Thankyou so much again! You have been a wonderful help.

Can I pick your brains for one more thing please? I will go ahead anyway:

With the tray menu, when you click a button it automatically checks it. As you can see in the code I provided, I am trying to make it so you can never check the item, however to no effect. Could you please provide your assistance once more on that?

Thanks heaps!

shanet


[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

shanet,

I have not heavily indulged into traymenus enough to know all the possible ways to achieve this, However, this should do the trick until someone comes up with a better solution.

I moved the TrayItemSetState() line inside the loop where it would be checked. and it works for me.

#Include <Constants.au3>
#include <GUIConstants.au3>


Opt("TrayMenuMode" ,1)
Local $tray[1], $main[3]

$tray[0] = TrayCreateItem("Open Program Interface")



$mainhandle = GUICreate("My Application", 400, 250)
GUISetBkColor( 0xFFFFEE )

$main[1] = GUICtrlCreateButton("First Button", 70, 90, 110, 40)
$main[2] = GUICtrlCreateButton("Second Button", 230, 90, 110, 40)


GUISetState()

While 1

    $traymsg = TrayGetMsg()

    if $traymsg = $tray[0] Then
        GUISetState(@SW_SHOW, $mainhandle)
        TrayItemSetState($tray[0], $TRAY_UNCHECKED)                  ;It keeps checking itself, I am trying to stop that as well :(
    EndIf

    $msg = GUIGetMsg()

    if $msg = $GUI_EVENT_CLOSE Then; or $msg = $file["exit"] Then   <<<change $file to a proper array or variable
        GUISetState(@SW_HIDE)
        ExitLoop
    EndIf
WEnd
Exit

Realm

Edit:

Btw. Your Welcome, and thanks for taking the time to show an example, I better understood your problem once I seen it :x

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Btw. Your Welcome, and thanks for taking the time to show an example, I better understood your problem once I seen it :x

Made me smile :P

That works 110%

Thanks for your help.

10 stars out of five for effort! Also thanks for putting up with me to begin with.

I hope thats it now. Thankyou.

Soon I hope to be helping people on a level of knowledge as high as yours on the subject.

Cya!

shanet


[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

My pleasure, I had the time Posted Image


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

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  
Followers 0