StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Lua Scripts
 General Action Scripts
 Help with Winamp WM_COMMAND messages
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kyprios1

11 Posts

Posted - 06/06/2012 :  07:33:36  Show Profile  Reply with Quote
Hi, first of all I want to say thank you for the time you've put in this project.
I've been testing S+ over the last few days and I'm contemplaiting doing the switch from SI.

However I'm stuck with porting some actions.
Specifically some SendMessage commands from Winamp.

A WM_COMMAND with a wParam of 40048 translates to Next Track command ( more here: tinyurl.com/d85kz68 ).

I tried
  • acSendMessage("Winamp v1.x", WM_COMMAND, 4008, 0)

  • local hWnd = acFindWindowByTitleRegex("Winamp.*")
    acSendMessage(hWnd, WM_COMMAND, 40048, 0)

  • local hWnd = acGetForegroundWindow()
    acSendMessage(hWnd, WM_COMMAND, 40048, 0)
but failed miserably.

Can someone show me how do I do it?

Edited by - kyprios1 on 06/06/2012 07:37:31

Rob

USA
2516 Posts

Posted - 06/06/2012 :  08:46:29  Show Profile  Visit Rob's Homepage  Reply with Quote
(moved to General Action Scripts)

Hi!

First of all, WM_COMMAND isn't a defined variable anywhere within the Lua engine, so acSendMessage will fall back to sending a 0 in place of it. Next, I would change your find window qualifier a little so you don't catch something like a browser window that has "Winamp" in the title, although acFindWindowByTitleRegex("Winamp.*") would only match windows that began with "Winamp", but Winamp almost never has that title configuration, you'd need to use ".*Winamp.* to find a window with "Winamp" anywhere in the title. Again, I'd recommend using the regex pattern below as it would be much more reliable.

Downloaded Winamp and tested the following script myself, should work for you as well.

local WM_COMMAND = 0x111
local hWnd = acFindWindowByTitleRegex(".* - Winamp.*")
acSendMessage(hWnd, WM_COMMAND, 40048, 0)

Of course, you don't really have to declare WM_COMMAND, it is simply 273, or 0x111 in hex..nor does hWnd technically need to be defined separately (I just do it for readability); so the whole script can just be one line (tested that one as well):

acSendMessage(acFindWindowByTitleRegex(".* - Winamp.*"), 273, 40048, 0)


Go to Top of Page

Rob

USA
2516 Posts

Posted - 06/06/2012 :  11:26:26  Show Profile  Visit Rob's Homepage  Reply with Quote
Actually, the best way to do this is via acFindWindow.. HOWEVER, prior to 1.9.3 (which I just released) back to the point where I added action parameter checking for stability purposes, S+ would not allow passing in a nil for class or title without reassigning the value to an empty string "". This results in the Windows API call (which S+ does internally) to FindWindow receiving an empty string for one of the parameters, so searching for window by class name alone, which is what you really should do here, wouldn't be possible.

The following script is what you should use (only will work properly with S+ 1.9.3 or higher):

acSendMessage(acFindWindow("Winamp v1.x",nil), 273, 40048, 0)
Go to Top of Page

kyprios1

11 Posts

Posted - 06/06/2012 :  16:10:45  Show Profile  Reply with Quote
This is brilliant, thanks!

acFindWindow no longer requiring both classname AND title is great news, this requirement was quite restrictive.

When you get the chance, please update the Functions thread to reflect that change: http://www.strokesplus.com/forum/topic.asp?TOPIC_ID=5

Edited by - kyprios1 on 06/06/2012 16:20:01
Go to Top of Page

Rob

USA
2516 Posts

Posted - 06/06/2012 :  16:13:10  Show Profile  Visit Rob's Homepage  Reply with Quote
Right, but nil must be passed in place of the blank parameter.
Go to Top of Page

Rob

USA
2516 Posts

Posted - 06/06/2012 :  16:23:02  Show Profile  Visit Rob's Homepage  Reply with Quote
Updated!

In the online help file as well. Will include the updated help and action help file along with the 1.9.4 release, whenever that may be.
Go to Top of Page

kyprios1

11 Posts

Posted - 06/06/2012 :  16:46:22  Show Profile  Reply with Quote
Are you sure your name isn't Flash Gordon? Your responses are lightning fast
Go to Top of Page

Rob

USA
2516 Posts

Posted - 06/06/2012 :  17:23:51  Show Profile  Visit Rob's Homepage  Reply with Quote
I may not get around to major features or enhancements that often nowadays, but there's no reason I can't just respond to a question right away or fix bugs when they pop up (like acFindWindow, that wasn't intended to be that way..even though I wrote the help file as such =) ).

The reason I wrote S+ was because StrokeIt was so poorly maintained and left up to the power users to help others; so I will never ignore S+ users, even if it's to say "tough shit, I don't feel like adding feature X", I'll at least let you know immediately and provide an explanation (or excuse)!
Go to Top of Page

imafishimafish

USA
19 Posts

Posted - 06/07/2012 :  19:30:08  Show Profile  Reply with Quote
quote:
Originally posted by Rob

Right, but nil must be passed in place of the blank parameter.


FYI, if you leave off a parameter, Lua passes nil for it by default. So
acFindWindow("Winamp v1.x",nil) can just be
acFindWindow("Winamp v1.x")
Go to Top of Page

Rob

USA
2516 Posts

Posted - 06/07/2012 :  19:48:34  Show Profile  Visit Rob's Homepage  Reply with Quote
Yea, I was just trying not to confuse people with which parameter, the order, etc. :-P
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000