Sign in to follow this  
Followers 0
katoNkatoNK

WM_COMMAND / _Singleton

30 posts in this topic

#1 ·  Posted (edited)

I'm struggling to understand how to setup a WM_COMMAND properly for simple functions, as well as getting it to respond for multiple gui's..

In effect it all works but at strange intervals..and what i would like out of it is a direct response (as if i would have put the 'Case' statements for the radio buttons in a while loop).

Here's what i've tried so far:

(as well as using 'Select' in the place of the 2nd 'Switch')

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iMsg = GUIGetMsg()
    
    Switch $hWnd
        Case $gui
            Switch $iMsg
                Case $IP_AUTO_STATUS = $GUI_CHECKED
                    ControlDisable("", "", $IP_ADDRESS)
                    ControlDisable("", "", $SUBNET_MASK)
                    ControlDisable("", "", $DEFAULT_GATEWAY)
                    ControlEnable("", "", $DNS_AUTO)
                Case $IP_USE_STATUS = $GUI_CHECKED 
                    ControlEnable("", "", $IP_ADDRESS)
                    ControlEnable("", "", $SUBNET_MASK)
                    ControlEnable("", "", $DEFAULT_GATEWAY)
                    ControlDisable("", "", $DNS_AUTO)
                    GUICtrlSetState($DNS_USE, $GUI_CHECKED)
                    ControlEnable("", "", $PREFERRED_DNS)
                    ControlEnable("", "", $ALTERNATE_DNS)
                Case $DNS_AUTO_STATUS = $GUI_CHECKED
                    ControlDisable("", "", $PREFERRED_DNS)
                    ControlDisable("", "", $ALTERNATE_DNS)
                Case $DNS_USE_STATUS = $GUI_CHECKED
                    ControlEnable("", "", $PREFERRED_DNS)
                    ControlEnable("", "", $ALTERNATE_DNS)
                Case $aIP_GET[0] > 223
                    _GUICtrlIPAddress_SetRange($IP_ADDRESS, 0, 0, 223)
                    _GUICtrlIPAddress_SetFocus($IP_ADDRESS, 0)
                    MsgBox(0, "TCP/IP Error!", "Invalid entry!" & @CRLF & "Please choose a value between 1 and 223.")
                    _GUICtrlIPAddress_SetRange($IP_ADDRESS, 0, 0, 255)
                Case $SUBNET_MASK
                    If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then
                        _GUICtrlIPAddress_Set($SUBNET_MASK, "255.0.0.0")
                    EndIf
                    If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then
                        _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.0.0")
                    EndIf
                    If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then
                        _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.255.0")
                    EndIf
                Case $aDEF_GET[0] > 223
                    _GUICtrlIPAddress_SetRange($DEFAULT_GATEWAY, 0, 0, 223)
                    _GUICtrlIPAddress_SetFocus($DEFAULT_GATEWAY, 0)
                    MsgBox(0, "TCP/IP Error!", "Invalid entry!" & @CRLF & "Please choose a value between 1 and 223.")
                    _GUICtrlIPAddress_SetRange($DEFAULT_GATEWAY, 0, 0, 255)
                Case $aPREF_DNS_GET[0] > 223
            EndSwitch
        Case ;2ng gui
            ;Similar function as above.
    EndSwitch
EndFunc

If you could add some comments as to 'why' and what for, if any extra parameters used other than the basics, it will be more than helpful :unsure:

And another small problem i can't find a solution for..

_Singleton ~ i'm trying to get it to restore the gui (minimizes to tray) if it is minimized OR bring the window to the front if it's not.

If _Singleton("LazyIP", 0) = 0 Then
    GUISetState(@SW_SHOWNORMAL)
    WinActivate($gui)
    TraySetState(2)
    ;WinSetState($gui, "", @SW_RESTORE)
    ;GUISetState(@SW_RESTORE, $gui)
    ;WinActivate($gui)
    ;TraySetState(2)
Else
    _FileGet()
EndIf
Edited by katoNkatoNK

Share this post


Link to post
Share on other sites



I'm struggling to understand how to setup a WM_COMMAND properly for simple functions, as well as getting it to respond for multiple gui's..

In effect it all works but at strange intervals..and what i would like out of it is a direct response (as if i would have put the 'Case' statements for the radio buttons in a while loop).

Here's what i've tried so far:

(as well as using 'Select' in the place of the 2nd 'Switch')

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iMsg = GUIGetMsg()
    
    Switch $hWnd
        Case $gui
            Switch $iMsg
                Case $IP_AUTO_STATUS = $GUI_CHECKED
                    ControlDisable("", "", $IP_ADDRESS)
                    ControlDisable("", "", $SUBNET_MASK)
                    ControlDisable("", "", $DEFAULT_GATEWAY)
                    ControlEnable("", "", $DNS_AUTO)
                Case $IP_USE_STATUS = $GUI_CHECKED 
                    ControlEnable("", "", $IP_ADDRESS)
                    ControlEnable("", "", $SUBNET_MASK)
                    ControlEnable("", "", $DEFAULT_GATEWAY)
                    ControlDisable("", "", $DNS_AUTO)
                    GUICtrlSetState($DNS_USE, $GUI_CHECKED)
                    ControlEnable("", "", $PREFERRED_DNS)
                    ControlEnable("", "", $ALTERNATE_DNS)
                Case $DNS_AUTO_STATUS = $GUI_CHECKED
                    ControlDisable("", "", $PREFERRED_DNS)
                    ControlDisable("", "", $ALTERNATE_DNS)
                Case $DNS_USE_STATUS = $GUI_CHECKED
                    ControlEnable("", "", $PREFERRED_DNS)
                    ControlEnable("", "", $ALTERNATE_DNS)
                Case $aIP_GET[0] > 223
                    _GUICtrlIPAddress_SetRange($IP_ADDRESS, 0, 0, 223)
                    _GUICtrlIPAddress_SetFocus($IP_ADDRESS, 0)
                    MsgBox(0, "TCP/IP Error!", "Invalid entry!" & @CRLF & "Please choose a value between 1 and 223.")
                    _GUICtrlIPAddress_SetRange($IP_ADDRESS, 0, 0, 255)
                Case $SUBNET_MASK
                    If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then
                        _GUICtrlIPAddress_Set($SUBNET_MASK, "255.0.0.0")
                    EndIf
                    If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then
                        _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.0.0")
                    EndIf
                    If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then
                        _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.255.0")
                    EndIf
                Case $aDEF_GET[0] > 223
                    _GUICtrlIPAddress_SetRange($DEFAULT_GATEWAY, 0, 0, 223)
                    _GUICtrlIPAddress_SetFocus($DEFAULT_GATEWAY, 0)
                    MsgBox(0, "TCP/IP Error!", "Invalid entry!" & @CRLF & "Please choose a value between 1 and 223.")
                    _GUICtrlIPAddress_SetRange($DEFAULT_GATEWAY, 0, 0, 255)
                Case $aPREF_DNS_GET[0] > 223
            EndSwitch
        Case ;2ng gui
            ;Similar function as above.
    EndSwitch
EndFunc

If you could add some comments as to 'why' and what for, if any extra parameters used other than the basics, it will be more than helpful :unsure:

And another small problem i can't find a solution for..

_Singleton ~ i'm trying to get it to restore the gui (minimizes to tray) if it is minimized OR bring the window to the front if it's not.

If _Singleton("LazyIP", 0) = 0 Then
    GUISetState(@SW_SHOWNORMAL)
    WinActivate($gui)
    TraySetState(2)
    ;WinSetState($gui, "", @SW_RESTORE)
    ;GUISetState(@SW_RESTORE, $gui)
    ;WinActivate($gui)
    ;TraySetState(2)
Else
    _FileGet()
EndIf

First Q

I don't like the look of

Local $iMsg = GUIGetMsg()

in your message handler, I would think it was better to have

Local $Msg = _WinAPI_LoWord($iwParam)

Second Q

If _Singleton("LazyIP", 0) = 0 Then

should be

If _Singleton("LazyIP", 1) = 0 Then


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi, Thanks for the help

And ye i was also sketchy about using that $iMsg :unsure:

I couldn't find any extra info on using the other paramters.

I've only gotten to the _Singleton so far and with the following:

If _Singleton("LazyIP", 1) = 0 Then
    Config()
Else
    _FileGet()
EndIf

It does exactly what i want (restores the gui completely), but it launches another 'script' entirely - and i can't get anything to work as in my first posts example, even after the change to:

If _Singleton("LazyIP", 1) = 0 Then

Edit: just tried the 'WM_COMMAND' solution

After changing the handler to:

Local $gMsg = _WinAPI_LoWord($iwParam)

none of the 'Case' statements respond :>

Edited by katoNkatoNK

Share this post


Link to post
Share on other sites

Please could someone help with this, i've tried all of what i know and can't get it right.

Share this post


Link to post
Share on other sites

Please could someone help with this, i've tried all of what i know and can't get it right.

Sorry if my suggestions so far haven't helped. It might be because I don't really know enough about what you are trying to do..

Let's try one problem at a time so that I don't get confused. The _Singleton one is probably easiest so I'll try that first.

You either need

to show me some small sample script which demonstartes your problem

or

explain to me in simple steps what action happens that means you to want to use singleton and what the 2 functions do that you showed (Config and _FileGet)


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Sure :unsure:

_singleton:

If _Singleton("LazyIP", 1) = 0 Then
    TraySetState(2)
    GUISetState(@SW_SHOW, $gui)
Else
    _FileGet()
EndIf

Heres what i'm trying to do:

1. If an instance is already running - then restore the gui completely (it minimizes to the tray so i tried the same functions for when u click on the tray icon to restore) ~ I tried 'Config()' in place of the two 'SetStates' but then it would just 're-open' the gui and end up being two configs open..

2. If an instance isn't already running - then move onto function _FileGet() ~ checks to see if the config's resource file exists ; This works with my previous try and your solution i guess it doesn't cause any problems here.

(The two 'SetStates' in the sample code is what I use to restore the gui from the tray.)

I hope that's clear enough

Edited by katoNkatoNK

Share this post


Link to post
Share on other sites

Sure :unsure:

_singleton:

If _Singleton("LazyIP", 1) = 0 Then
    TraySetState(2)
    GUISetState(@SW_SHOW, $gui)
Else
    _FileGet()
EndIf

Heres what i'm trying to do:

1. If an instance is already running - then restore the gui completely (it minimizes to the tray so i tried the same functions for when u click on the tray icon to restore) ~ I tried 'Config()' in place of the two 'SetStates' but then it would just 're-open' the gui and end up being two configs open..

2. If an instance isn't already running - then move onto function _FileGet() ~ checks to see if the config's resource file exists ; This works with my previous try and your solution i guess it doesn't cause any problems here.

(The two 'SetStates' in the sample code is what I use to restore the gui from the tray.)

I hope that's clear enough

It's not at all clear to me.

You have some script running.

Something happens and you minimize it to the tray.

Then, independently of the script, something else happens (You try to run another instance?) and when that something else happens you run the piece of code that checks if the script is already running. If it is running then you restore the script and actiovate it so the operator sees it. But if it's not running then it calls this function _FileGet which is where I get lost.

This is how I would expect _singleton to be used in case it's relevant to your situation.

;at the top of your script before anything is created
;check to see if instance exists
if _Singleton("LazyIP",1) = 0 then;we must not run a second instance
 ;do something to reactive, show the gui
  exit
endif

;no need for else
;so now we continue with the script and create whatever.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Ye you're on the right track :unsure:

Ok, then i guess we can do without the else statement..

Here's my two minimize/restore actions: (both in same gui/function)

Case $GUI_EVENT_MINIMIZE
                GUISetState(@SW_HIDE)
                TraySetState()

Case $TRAY_EVENT_PRIMARYUP
                GUISetState(@SW_SHOWNORMAL)
                WinActivate($gui)
                TraySetState(2)

So with/without the 'Else' in _Singleton the problem lies with getting the gui to restore activated, i've tried quite a few combinations of WinActivate/WinSetState/GuiSetState with various @macro's without any solution (to 'reverse' the 'Case $GUI_EVENT_MINIMIZE').

Edited by katoNkatoNK

Share this post


Link to post
Share on other sites

Ye you're on the right track :unsure:

Ok, then i guess we can do without the else statement..

Here's my two minimize/restore actions: (both in same gui/function)

Case $GUI_EVENT_MINIMIZE
                GUISetState(@SW_HIDE)
                TraySetState()

Case $TRAY_EVENT_PRIMARYUP
                GUISetState(@SW_SHOWNORMAL)
                WinActivate($gui)
                TraySetState(2)

So with/without the 'Else' in _Singleton the problem lies with getting the gui to restore activated, i've tried quite a few combinations of WinActivate/WinSetState/GuiSetState with various @macro's without any solution (to 'reverse' the 'Case $GUI_EVENT_MINIMIZE').

Does this example help?

$g = GUICreate("nothing much here")
GUISetState()

Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown.

$restore = TrayCreateItem("restore")
$DONE = TrayCreateItem("EXIT")
TraySetIcon("warning")
TraySetToolTip("Some example")

TraySetState(2) ; hide the tray icon

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = $restore
            ConsoleWrite("restore" & @CRLF)
            ConsoleWrite( hex(WinGetState($g, ""))& @CRLF)
            If BitAND(WinGetState($g, ""), 16) Then
                WinSetState($g, "", @SW_RESTORE)
                winsetstate($g,"", @SW_ENABLE)
            EndIf
        Case $msg = $DONE
            Exit
    EndSelect

    $msg2 = GUIGetMsg()
    Switch $msg2
        Case 0
        Case -3
            Exit
        Case -4
            TraySetState();show the tray icon
        Case Else
            ConsoleWrite($msg2 & @CRLF)
    EndSwitch
WEnd

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

No sorry

I guess you did misunderstand, I posted those two pieces of script because i thought maybe the _singleton's solution, depended on how the gui was controlled. If i'm correct you posted an example of how to use the tray and _singleton?, unless i really missed something :unsure:

can _Singleton even restore a minimized gui?

Share this post


Link to post
Share on other sites

No sorry

I guess you did misunderstand, I posted those two pieces of script because i thought maybe the _singleton's solution, depended on how the gui was controlled. If i'm correct you posted an example of how to use the tray and _singleton?, unless i really missed something :unsure:

can _Singleton even restore a minimized gui?

My example wasn't meant to be anything to do with trays or singletons, it was just showing how to restore a gui, but probably it was a bad example because it wasn't retsoring a gui in another script.

You have a script running and it gets minimized. Then another instance of a script is started. The second instance needs to realize there is already an instance running and if so then restore the first one and then exit. To be able to restore the first one it must know something to be able to identify the gui which has to be restored. So does the gui have some unique title? if so then you just need to use

WinSetState($Title,"",@SW_RESTORE) etc, but you can't use

GUISetState(@SW_SHOWNORMAL)

because that will only act on the last gui referred to in the current script and not the gui in the instance which is already running.

If you can't tell what the title is then we need to use another way.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Mm, doesn't seem like _Singleton can restore a minimized gui.. I tried this, using 'Window Info tool' to double check the title of the script.

If _Singleton("LazyIP", 1) = 0 Then WinSetState("LazyIP", "", @SW_RESTORE)

It opens a new gui but also restores the minimized gui which was already open - but also minimized to the taskbar, strange?..

Share this post


Link to post
Share on other sites

Mm, doesn't seem like _Singleton can restore a minimized gui.. I tried this, using 'Window Info tool' to double check the title of the script.

If _Singleton("LazyIP", 1) = 0 Then WinSetState("LazyIP", "", @SW_RESTORE)

It opens a new gui but also restores the minimized gui which was already open - but also minimized to the taskbar, strange?..

We are going round in circles. I assume the new gui is because you haven't exited your script if another instance is already running.

Why haven't you written

If _Singleton("LazyIP", 1) = 0 Then
   WinSetState("LazyIP", "", @SW_RESTORE)
   exit;<--------------------------stop the second instance running as established in previous posts.
endif

I don't understand why you say _Singleton can't restore a minimized gui when you then show some code which you say restores the previously minimzed gui.

Here is an example which does what I think you want to do

#include <misc.au3>

If _Singleton("hgtfredsws_underoveranything", 1) = 0 Then
    MsgBox(262144, "already", "one running")
    WinSetState("nothing much here", "", @SW_RESTORE)
    WinSetState("nothing much here", "", @SW_ENABLE)
    Exit
EndIf


$g = GUICreate("nothing much here")
GUISetState()


While 1
    $msg2 = GUIGetMsg()
    Switch $msg2
        Case -3
            Exit
    EndSwitch
WEnd

Complie that, run it, minimize the gui then run another instance. let me know what happens. If it doesn't work for you then I will beleive prediction that the world is going to end today.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Ohk, my apologies

I had completely overlooked using 'Exit' :unsure:

If _Singleton("LazyIP", 1) = 0 Then
    WinSetState("LazyIP", "", @SW_RESTORE)
    WinActivate("LazyIP")
    Exit
EndIf

It's working now :>

(I take it that there isn't an alternative to 'TraySetState(2)'? seeing as 'GUISetState()' cannot be used..)

Edited by katoNkatoNK

Share this post


Link to post
Share on other sites

Ohk, my apologies

I had completely overlooked using 'Exit' :unsure:

If _Singleton("LazyIP", 1) = 0 Then
    WinSetState("LazyIP", "", @SW_RESTORE)
    WinActivate("LazyIP")
    Exit
EndIf

It's working now :>

(I take it that there isn't an alternative to 'TraySetState(2)'? seeing as 'GUISetState()' cannot be used..)

Probably a few ways but I would use a message. If a script starts and finds that a previous script is running then it sends a message to that script and quits. The first instance can then do whatever you want when it gets the message.

#include <misc.au3>
#include <sendmessage.au3>
#include <winapi.au3>

$RecoverGui = _WinAPI_RegisterWindowMessage("MySpecialRecoverThing");get an unallocated message number, or get the number previously allocated to that string by a previous instance

If _Singleton("hgtfredsws_underoveranything", 1) = 0 Then
    ;MsgBox(262144, "already", "one running")
    $hw = WinGetHandle("nothing much here")
    If @error = 0 Then
        _SendMessage($hw, $RecoverGui, 1);tell the first script to wake up
    EndIf

    Exit
EndIf

traysetstate(2)

$g = GUICreate("nothing much here")
GUISetState()

GUIRegisterMsg($RecoverGui, "Mywakeup")

While 1
    $msg2 = GUIGetMsg()
    Switch $msg2
        Case -3
            Exit
        case -4
            traysetstate()
    EndSwitch
WEnd


Func Mywakeup($hG, $iMsg, $wPar, $lPar)

    If $wPar = 1 Then; we have been told to restore
        GUISetState(@SW_RESTORE, $g);now you can use your GuiSetState
      traysetstate(2);                                  and you can use your TraySetState
    EndIf
EndFunc   ;==>Mywakeup

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Thanks for the straight forward example script martin!

.. while i was at it i gave 'WM_COMMAND' for my initial question, another try but can't seem to figure it out.

I might just end up using a command Select/Switch statement unless it's better to use a 'wm_command' for the script in my first post..

Select
    Case $aIP_GET[0] > 223 AND $aIP_GET[0] = 127
        _GUICtrlIPAddress_SetRange($IP_ADDRESS, 0, 0, 223)
        _GUICtrlIPAddress_SetFocus($IP_ADDRESS, 0)
        MsgBox(0, "TCP/IP Error!", "Invalid entry!" & @CRLF & "Please choose a value between 1 and 223.")
        _GUICtrlIPAddress_SetRange($IP_ADDRESS, 0, 0, 255)
EndSelect

(Here's a problem i came across tho..if I put this Select statement in the 'While 1' loop, without the '_SetRange' functions, after the 'Case' is triggered the msgbox just continues to show..)

Edited by katoNkatoNK

Share this post


Link to post
Share on other sites

Could i get some help on this wm_command piece i tried?

I'm trying to get an ip field(subnet mask) automatically set with an ip depend on another ip field(ip address), i can get it working but my try will automatically fill subnet mask with the value - as soon as ip address is in the set range but it should only fill once subnet mask is focused..

;Attempt 1:
Global $gCMD = _WinAPI_RegisterWindowMessage("LazyIP"), $msg
;..
_SendMessage($wH, $gCMD, 1)
;..
GUIRegisterMsg($gCMD, "WM_COMMAND")
;..
Func WM_COMMAND($hG, $iMsg, $wPar, $lPar)
    If $wPar = 1 Then
        GUISetState()
        TraySetState(2)
    EndIf
    Local $chk = BitAND($wParam, 0x0000FFFF)
    Switch $chk
        Case $SUBNET_MASK
            If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then
                _GUICtrlIPAddress_Set($SUBNET_MASK, "255.0.0.0")
            EndIf
            If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then
                _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.0.0")
            EndIf
            If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then
                _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.255.0")
            EndIf
    EndSwitch
EndFunc

;Attempt 2:
Switch ControlGetFocus($gui)
    Case $SUBNET_MASK
        If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then
            _GUICtrlIPAddress_Set($SUBNET_MASK, "255.0.0.0")
        EndIf
        If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then
            _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.0.0")
        EndIf
        If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then
            _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.255.0")
        EndIf
EndSwitch

any help please :huh2:

Share this post


Link to post
Share on other sites

Could i get some help on this wm_command piece i tried?

I'm trying to get an ip field(subnet mask) automatically set with an ip depend on another ip field(ip address), i can get it working but my try will automatically fill subnet mask with the value - as soon as ip address is in the set range but it should only fill once subnet mask is focused..

;Attempt 1:
Global $gCMD = _WinAPI_RegisterWindowMessage("LazyIP"), $msg
;..
_SendMessage($wH, $gCMD, 1)
;..
GUIRegisterMsg($gCMD, "WM_COMMAND")
;..
Func WM_COMMAND($hG, $iMsg, $wPar, $lPar)
    If $wPar = 1 Then
        GUISetState()
        TraySetState(2)
    EndIf
    Local $chk = BitAND($wParam, 0x0000FFFF)
    Switch $chk
        Case $SUBNET_MASK
            If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then
                _GUICtrlIPAddress_Set($SUBNET_MASK, "255.0.0.0")
            EndIf
            If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then
                _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.0.0")
            EndIf
            If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then
                _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.255.0")
            EndIf
    EndSwitch
EndFunc

;Attempt 2:
Switch ControlGetFocus($gui)
    Case $SUBNET_MASK
        If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then
            _GUICtrlIPAddress_Set($SUBNET_MASK, "255.0.0.0")
        EndIf
        If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then
            _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.0.0")
        EndIf
        If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then
            _GUICtrlIPAddress_Set($SUBNET_MASK, "255.255.255.0")
        EndIf
EndSwitch

any help please :huh2:

It's not at all clear to me what you're trying to do and what your problem is. I need to have things spelt out in very simple ways I'm afraid. some code which we could run to show the problem would help. If the 2 ip fields are in th esame gui then I don't think a message is needed.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

ye, the two ip fields on are the same gui, i was just adding it to the solution u helped me with because i read somewhere u can hav only one handler per message.

As soon as $subnetmask is focused it gets filled with an ip depending on what $ipaddress is. The select statement below is the closest i've gotten it to working, but fills fills $subnetmask even when not focused.

#include <GuiIPAddress.au3>
#include <GUIConstantsEx.au3>

Global $gui
Global $ipaddress
Global $subnetmask

$gui = GUICreate("test", 300, 300, -1, -1)

$ipaddress = _GUICtrlIPAddress_Create($gui, 25, 40, 200, 20)
$subnetmask = _GUICtrlIPAddress_Create($gui, 25, 80, 200, 20)

GUISetState()
While 1
    Global $msg = GUIGetMSg()
    Global $aIP_GET = _GUICtrlIPAddress_GetArray($ipaddress)
    
    Select                          ;Fills subnet mask as soon as 'ip address field one ~ $aIP_GET[0]' comes within one of the ranges in the 'If..Then' statements below.
        Case $SUBNETMASK
            If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then
                _GUICtrlIPAddress_Set($SUBNETMASK, "255.0.0.0")
            EndIf
            If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then
                _GUICtrlIPAddress_Set($SUBNETMASK, "255.255.0.0")
            EndIf
            If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then
                _GUICtrlIPAddress_Set($SUBNETMASK, "255.255.255.0")
            EndIf
    EndSelect
    
    ;~
    ;Switch ControlGetFocus($gui)           ;doesn't work..
    ;   Case $SUBNETMASK
    ;       If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then
    ;           _GUICtrlIPAddress_Set($SUBNETMASK, "255.0.0.0")
    ;       EndIf
    ;       If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then
    ;           _GUICtrlIPAddress_Set($SUBNETMASK, "255.255.0.0")
    ;       EndIf
    ;       If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then
    ;           _GUICtrlIPAddress_Set($SUBNETMASK, "255.255.255.0")
    ;       EndIf
    ;EndSwitch
    
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by katoNkatoNK

Share this post


Link to post
Share on other sites

ye, the two ip fields on are the same gui, i was just adding it to the solution u helped me with because i read somewhere u can hav only one handler per message.

As soon as $subnetmask is focused it gets filled with an ip depending on what $ipaddress is. The select statement below is the closest i've gotten it to working, but fills fills $subnetmask even when not focused.

#include <GuiIPAddress.au3>
#include <GUIConstantsEx.au3>

Global $gui
Global $ipaddress
Global $subnetmask

$gui = GUICreate("test", 300, 300, -1, -1)

$ipaddress = _GUICtrlIPAddress_Create($gui, 25, 40, 200, 20)
$subnetmask = _GUICtrlIPAddress_Create($gui, 25, 80, 200, 20)

GUISetState()
While 1
    Global $msg = GUIGetMSg()
    Global $aIP_GET = _GUICtrlIPAddress_GetArray($ipaddress)
    
    Select                          ;Fills subnet mask as soon as 'ip address field one ~ $aIP_GET[0]' comes within one of the ranges in the 'If..Then' statements below.
        Case $SUBNETMASK
            If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then
                _GUICtrlIPAddress_Set($SUBNETMASK, "255.0.0.0")
            EndIf
            If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then
                _GUICtrlIPAddress_Set($SUBNETMASK, "255.255.0.0")
            EndIf
            If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then
                _GUICtrlIPAddress_Set($SUBNETMASK, "255.255.255.0")
            EndIf
    EndSelect
    
    ;~
    ;Switch ControlGetFocus($gui)           ;doesn't work..
    ;   Case $SUBNETMASK
    ;       If $aIP_GET[0] <= 126 AND $aIP_GET[0] >= 1 Then
    ;           _GUICtrlIPAddress_Set($SUBNETMASK, "255.0.0.0")
    ;       EndIf
    ;       If $aIP_GET[0] <= 191 AND $aIP_GET[0] >= 128 Then
    ;           _GUICtrlIPAddress_Set($SUBNETMASK, "255.255.0.0")
    ;       EndIf
    ;       If $aIP_GET[0] <= 223 AND $aIP_GET[0] >= 192 Then
    ;           _GUICtrlIPAddress_Set($SUBNETMASK, "255.255.255.0")
    ;       EndIf
    ;EndSwitch
    
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

OK, but I'm very slow at this. You have two ip fields. When 1 is focused you type an address into it. Do you want that address to appear in the second IP control as it's typed into the first., or do you want something else?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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