Jump to content

Simple DllCall Question


Sunaj
 Share

Recommended Posts

Hi, trying to get the following code to work as expected, I just cannot seem to get the final parameter to work - no matter what I do the browser (IE) seem to start up on top?! I have looked at w0uter's _INetBrowse but is has the same problem for me. Reason why I use the DllCall instead of normal Run is that the code I'm writing needs to be able to adapt to different browsers installed on different computers.

$s_URL = "http://www.autoitscript.com/"
DllCall("shell32.dll", "long", "ShellExecute", "hwnd", 0, "string", 'open',"string", $s_URL, "string", '', "string", @WorkingDir, "long", @SW_MINIMIZE)
Link to comment
Share on other sites

  • Developers

You are not starting a program, but a file..

That means that :

nShowCmd

[in] Flags that specify how an application is to be displayed when it is opened. If lpFile specifies a document file, the flag is simply passed to the associated application. It is up to the application to decide how to handle it.

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Link to comment
Share on other sites

You are not starting a program, but a file..

Actually, he is opening a web site, not a file. ShellExecute will use the extension of whatever is passed to it and determine the correct program to use to open it.

Looking at the ShellExecute API:

SW_MINIMIZE - Minimizes the specified window and activates the next top-level window in the Z order.

SW_SHOWMINIMIZED - Activates the window and displays it as a minimized window.

Have you tried passing SW_SHOWMINIMIZED instead of SW_MINIMIZE?

I'm more used to using ShellExecuteEX, so you might want to take a look at that API call too.

Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Hi PaulIA & this-is-me, hmm, yea, I tried all the various parameters incl. SW_SHOWMINIMIZED, still no party.. Anyways, I'll give ShellExecuteEX a look if I cannot get the new beta ShellExecute function that this-is-me mentioned to work! Guess this feature would be neat for many AutoIt developers btw..

Actually, he is opening a web site, not a file. ShellExecute will use the extension of whatever is passed to it and determine the correct program to use to open it.

Looking at the ShellExecute API:

Have you tried passing SW_SHOWMINIMIZED instead of SW_MINIMIZE?

I'm more used to using ShellExecuteEX, so you might want to take a look at that API call too.

Edited by Sunaj
Link to comment
Share on other sites

Well, the new beta ShellExecute reacts exactly as a manual DllCall.. meaning this does not fix it.. starting to think that manual detection of browser from a registry key will yield better results. Anyone?

Hi PaulIA & this-is-me, hmm, yea, I tried all the various parameters incl. SW_SHOWMINIMIZED, still no party.. Anyways, I'll give ShellExecuteEX a look if I cannot get the new beta ShellExecute function that this-is-me mentioned to work! Guess this feature would be neat for many AutoIt developers btw..

Link to comment
Share on other sites

This works

_ShellExecute('iexplore', 'http://www.autoitscript.com/', '', 'open', @SW_MINIMIZE)

Func _ShellExecute($filename, $parameters = '', $workingdir = '', $verb = 'open', $showflag = @SW_SHOWNORMAL)
    $aRet = DllCall("shell32.dll", "long", "ShellExecute", _
            "hwnd", 0, _
            "string", $verb, _
            "string", $filename, _
            "string", $parameters, _
            "string", $workingdir, _
            "int", $showflag)
    Return SetError(@error, 0, '')
EndFunc

as it starts minimized but it is ignoring parameters passed.

Link to comment
Share on other sites

@MHz, you must have an older version of the beta or an older version of Internet Explorer than I have because with beta v3.2.1.8 and Internet Explorer 7, It does indeed accept the command line parameters.

However, you did not read the request from the OP, because he wanted code that would "needs to be able to adapt to different browsers installed on different computers". This is not the type of code you provided, therefore your code is erroneous.

EDIT: @Sunaj, the only time the code did not indeed open the browser not minimized on my computer was when the browser was not already open, due to a setting in Internet Explorer that opens any new website in an existing Internet Explorer window.

Edited by this-is-me
Who else would I be?
Link to comment
Share on other sites

@MHz, you must have an older version of the beta or an older version of Internet Explorer than I have because with beta v3.2.1.8 and Internet Explorer 7, It does indeed accept the command line parameters.

However, you did not read the request from the OP, because he wanted code that would "needs to be able to adapt to different browsers installed on different computers". This is not the type of code you provided, therefore your code is erroneous.

You are several beta versions into the future and have no chance of minimizing a website, but you can minimize an application. And do note IE mentioned in the 1st post.

AutoIt 3.2.1.10 here and parameters are not accepted by ShellExecute().

Edit:

Added mention of ShellExecute().

Edited by MHz
Link to comment
Share on other sites

@MHz, the OP does mention IE as an example, however, he goes on to explain:

Reason why I use the DllCall instead of normal Run is that the code I'm writing needs to be able to adapt to different browsers installed on different computers.

I also do not understand your statement "have no chance of minimizing a website". This is not what we are talking about at all. We are speaking about launching the default browser in a minimized state.

As for differences in scripting, If you look at the helpfile for ShellExecute, it does specify that you need not input a verb to allow it to work correctly. In the beta, I can use the following code and it works flawlessly:

ShellExecute('http://www.autoitscript.com/', '', '', '', @SW_MINIMIZE)

Let me be rightly understood, I am not trying to pick a fight, I simply am trying to iron out the differences in our attempts to answer the OP's question.

Who else would I be?
Link to comment
Share on other sites

@this-is-me, @MHz, thanks for your help on this one (late reply due to me not having access to comp. during this weekend). Unfortunately this-is-me is right in pointing out that the script (despite working great) provided by MHz does not solve my problem.. Also, this code by this-is-me seems to be IE7 only which does not really fit the bill either (at least not till everyone has upgraded.. which I guess will take about a decade).

(also, it does not matter whether IE6/Firefox is open or not - still pops up in front of everything else)

So.. wrote the following registry polling script to allow for app control AND different browsers.. the regexp (which btw took me... time... to get right) is necessary because Firefox writes its default reg-entry in a different way than IE.

Code :whistle:

$string = RegRead ( "HKEY_CLASSES_ROOT\HTTP\shell\open\command", "" )
$pattern = '(?i).(\:)(.*)exe' ; dont know how to get smily off here...
$result = StringRegExp($string, $pattern,2)
If @error Then
  MsgBox(48, 'Error', "Default browser not set")
EndIf
$DefaultBrowser = $result[0]
Run($DefaultBrowser & " " & "http://www.autoitscript.com/", "", @SW_MINIMIZE)

Still, despite having gained control over IE6/7 it seems that Firefox(1.5.0.7) completely ignores all the @SW's - it even ignores its opening parameters when changing a normal desktop link to "Run: Minimized" so I guess it does not accept any kind of opening window control at all!!

....

@MHz, the OP does mention IE as an example, however, he goes on to explain:

....

Edited by Sunaj
Link to comment
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
 Share

  • Recently Browsing   0 members

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