Jump to content

Trying to add function causing "incorrect number of parameters"


Recommended Posts

Sorry if this is something really simple, but I am almost a complete beginner with AutoIt3.

 

This works and saves the window position to an ini file with $nIniXPos and $nIniYPos

GUICreate("My GUI", 600, 400, -1, -1, Default, $nIniXPos, $nIniYPos)

 

This works and makes the GUI always on top by using $WS_EX_TOPMOST

GUICreate("My GUI", 600, 400, -1, -1, Default, $WS_EX_TOPMOST)

 

On other GUI's that I am not adding the always on top function to, they work when
adding the function to save window position, for example this works:

GuiCreate("My GUI", 600, 400, $nIniXPos, $nIniYPos)

 

Taking that function away also works:

GuiCreate("My GUI", 600, 400)

 

But if I try to use both of those functions together (always on top with save window position)
then I get "Incorrect number of parameters in function call":

GUICreate("My GUI", 600, 400, -1, -1, Default, $WS_EX_TOPMOST, $nIniXPos, $nIniYPos)

I have tried removing "-1" and the GUI doesn't display, same if "Default" is removed.
I tried swapping the functions around so $WS_EX_TOPMOST is last, to no avail.

I am stumped now, hence asking here :)
 

Link to comment
Share on other sites

That "-1, -1" is needed when I use "$WS_EX_TOPMOST" but I was just including "-1, -1" there because it still works having those there while leaving out $WS_EX_TOPMOST.

To use $WS_EX_TOPMOST it also needs -1, -1 which is three functions in itself.

I can't grasp why you can't just add more functions, it's like there's a limit?

How can I simply append another function to it and have it saving the window position while also having the GUI always on top?

Cheers.

 

Link to comment
Share on other sites

16 minutes ago, TalesFromTheScript said:

But if I try to use both of those functions together (always on top with save window position)
then I get "Incorrect number of parameters in function call":

First of all 'Welcome to the forum' :welcome:.

AutoIt has an excellent help. Have a look at it for GUICreate ,then you will surely figure out the problem yourself ;).
A little spoiler : Most functions expect parameters. At the beginning are the ones that have to be passed. After that are the so called optional parameters. These can be passed, but don't have to (then they are automatically filled with default values).

So you always have to take care to keep the prescribed order.

The following must be considered for the optional parameters :  If e.g. the second optional parameter is set, then you cannot simply omit the first one. For this parameter the keyword default often has to be used.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

I had already looked at the reference before posting here.

I have no idea how to fix it and have tried putting -1 and Default in just about every combination possible, nothing fixes it.

I tried adding one more "-1" but I can't get it to work.

GUICreate("My GUI", 600, 400, -1, -1, -1, $WS_EX_TOPMOST, $nIniXPos, $nIniYPos)

I guess I'll just have to leave out the always on top functionality and put up with it, or see if it gets answered.

Cheers.

Edited by TalesFromTheScript
Link to comment
Share on other sites

9 minutes ago, Danp2 said:

Why do you think this line "saves the window position to an ini file with $nIniXPos and $nIniYPos"?

 

It does. I just posted one line from a bigger script that also includes this before GUICreate:

Global $sMyIniLocation = "MyFolder\WinPos.ini"
Global $nIniXPos = Int(IniRead($sMyIniLocation, 'MAINWINPOS', 'XPOS', Int(@DesktopWidth/2.5)))
Global $nIniYPos = Int(IniRead($sMyIniLocation, 'MAINWINPOS', 'YPOS', Int(@DesktopHeight/2.5)))

Func _myWM_MOVE($hWnd, $nMsg, $wParam, $lParam)
    Local $aWPos = WinGetPos($hWnd)
    If IsArray($aWPos) Then
        IniWrite($sMyIniLocation, 'MAINWINPOS', 'XPOS', $aWPos[0])
        IniWrite($sMyIniLocation, 'MAINWINPOS', 'YPOS', $aWPos[1])
        $nIniXPos = $aWPos[0]
        $nIniYPos = $aWPos[1]
    EndIf
    Return
 EndFunc

 

And this after GUICreate:

GUIRegisterMsg(0x03, "_myWM_MOVE")
GUISetState()


I know the save window position part works because it's working perfectly fine in other GUI's that do not also have the always on top function added. The one GUI that does have the always on top function added, cannot have the window position function added because then all I get is an error "Incorrect number of parameters".

Either function on its own does work.

 

Edited by TalesFromTheScript
Link to comment
Share on other sites

1 hour ago, Danp2 said:

@TalesFromTheScript No, it doesn't. The code you just posted reads from and updates the INI file. You don't need (or want) those two additional parameters on your GuiCreate because it could cause unexpected behavior.

OK cheers.

I don't know how else to add them and since it works fine on other GUI's I assumed that's the way it would be done.

$nIniXPos and $nIniYPos is needed somewhere because it doesn't work if they are taken out.

Edited by TalesFromTheScript
Link to comment
Share on other sites

48 minutes ago, TalesFromTheScript said:

I don't know how else to add them and since it works fine on other GUI's I assumed that's the way it would be done.

This assumption, as @Danp2 has already tried to explain to you with great patience, is nonetheless wrong.

You pass the value $nIniXPos to parameter7=exStyle, and the value $nIniYPos to parameter8=parent.
This may fulfill the syntactical requirements of the function, but definitely not the functional ones.

Edited by Musashi
typo

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

  • Moderators

Your question has been answered several times, by people that no the language inside and out - you simply cannot seem to comprehend what they are telling you. Perhaps scripting is not for you. And since you want to take your ball and go home in a fit, this thread can be closed.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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