Get songtitle from Winamp

Hi,
I just got the following to run, maybe someone finds it useful. All it
does is extract the songtitle that Winamp is currently playing. Note
that of course this only works in a Win32 environment. Also, the
constant “4096” and “256” are just values that seemed to work for me.
They might yet need correcting.

···

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Extract Songtitle from Winamp – 2003 by Andi S.

require “Win32API”

findWindow = Win32API.new(“user32”, “FindWindow”, [‘P’, ‘P’], ‘L’)
getWindowText = Win32API.new(“user32”, “GetWindowText”, [‘L’, ‘P’, ‘I’], ‘I’)
hWnd = findWindow.call(“Winamp v1.x”, 0)

if hWnd > 0 then
song_array = " " * 256
getWindowText.call(hWnd, song_array, 4096)
song_array.unpack(‘M’)[0].strip! =~ /^\d+. (.*) - Winamp.$/
song = $1
puts song

    else raise "Please start Winamp first!"

end

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


Bye: Andi S. mailto:nullpointer@myrealbox.com

What is an “hWnd”? That’s the weirdest variable name I’ve seen in a
while. I’m sure it makes sense in some that is just not obvious. It just
kind of looks like a random string of characters to me.

···

On Mon, Jun 16, 2003 at 12:15:43AM +0900, Andi Scharfstein wrote:

Hi,
I just got the following to run, maybe someone finds it useful. All it
does is extract the songtitle that Winamp is currently playing. Note
that of course this only works in a Win32 environment. Also, the
constant “4096” and “256” are just values that seemed to work for me.
They might yet need correcting.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Extract Songtitle from Winamp – 2003 by Andi S.

require “Win32API”

findWindow = Win32API.new(“user32”, “FindWindow”, [‘P’, ‘P’], ‘L’)
getWindowText = Win32API.new(“user32”, “GetWindowText”, [‘L’, ‘P’, ‘I’], ‘I’)
hWnd = findWindow.call(“Winamp v1.x”, 0)

if hWnd > 0 then
song_array = " " * 256
getWindowText.call(hWnd, song_array, 4096)
song_array.unpack(‘M’)[0].strip! =~ /^\d+. (.*) - Winamp.$/
song = $1
puts song

    else raise "Please start Winamp first!"

end

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


Bye: Andi S. mailto:nullpointer@myrealbox.com


Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html

Hi,

···

At Mon, 16 Jun 2003 00:15:43 +0900, Andi Scharfstein wrote:

I just got the following to run, maybe someone finds it useful. All it
does is extract the songtitle that Winamp is currently playing. Note
that of course this only works in a Win32 environment. Also, the
constant “4096” and “256” are just values that seemed to work for me.

The third to GetWindowText() isn’t the length of the second
buffer? If so, it should be definitely wrong.


Nobu Nakada

It’s a Win32API convention meaning “Window Handle”.

Chad

Daniel Carrera wrote:

···

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

What is an “hWnd”? That’s the weirdest variable name I’ve seen in a
while. I’m sure it makes sense in some that is just not obvious. It just
kind of looks like a random string of characters to me.

On Mon, Jun 16, 2003 at 12:15:43AM +0900, Andi Scharfstein wrote:

Hi,
I just got the following to run, maybe someone finds it useful. All it
does is extract the songtitle that Winamp is currently playing. Note
that of course this only works in a Win32 environment. Also, the
constant “4096” and “256” are just values that seemed to work for me.
They might yet need correcting.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Extract Songtitle from Winamp – 2003 by Andi S.

require “Win32API”

findWindow = Win32API.new(“user32”, “FindWindow”, [‘P’, ‘P’], ‘L’)
getWindowText = Win32API.new(“user32”, “GetWindowText”, [‘L’, ‘P’, ‘I’], ‘I’)
hWnd = findWindow.call(“Winamp v1.x”, 0)

if hWnd > 0 then
song_array = " " * 256
getWindowText.call(hWnd, song_array, 4096)
song_array.unpack(‘M’)[0].strip! =~ /^\d+. (.*) - Winamp.$/
song = $1
puts song

   else raise "Please start Winamp first!"

end

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


Bye: Andi S. mailto:nullpointer@myrealbox.com


Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (SunOS)

iD8DBQE+7I6snxE8DWHf+OcRAgb6AKCkuDk6vT9MQj4HQ2PjbEWr1n0bvACgh7Fk
1PY6Ey2gop0M0WvJH9lfNUY=
=JGV4
-----END PGP SIGNATURE-----

Hi,

song_array = " " * 256
getWindowText.call(hWnd, song_array, 4096)

Also, the constant “4096” and “256” are just values that seemed to
work for me.

The third to GetWindowText() isn’t the length of the second
buffer? If so, it should be definitely wrong.

Hence my comment… I wasn’t very clear on what it should actually be.
Maybe someone with a better knowledge of what is actually done there
can comment on that?

···


Bye: Andi S. mailto:nullpointer@myrealbox.com

Daniel Carrera wrote:

What is an “hWnd”?..it looks like a random string of characters…

It’s a Win32API convention meaning “Window Handle”.

Chad

Why don’t they call it “WindowHandle” or “window_handle”?
That would make more sense to me.


Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html

···

On Mon, Jun 16, 2003 at 12:25:22AM +0900, Chad Fowler wrote:

cBecause sthey vare dextremely pinto aHungarian nnotation.

···

On Sunday 15 June 2003 9:34 am, Daniel Carrera wrote:

Daniel Carrera wrote:

What is an “hWnd”?..it looks like a random string of
characters…

On Mon, Jun 16, 2003 at 12:25:22AM +0900, Chad Fowler wrote:

It’s a Win32API convention meaning “Window Handle”.

Chad

Why don’t they call it “WindowHandle” or “window_handle”?
That would make more sense to me.


Wesley J. Landaker - wjl@icecavern.net
OpenPGP FP: C99E DF40 54F6 B625 FD48 B509 A3DE 8D79 541F F830

I just looked up “hungarian notation” in microsoft.com. I cam accross a
tutorial about it. Here is a quote from it:

This system became widely used inside Microsoft. It came to be known as
“Hungarian notation” because the prefixes make the variable names look a
bit as though they’re written in some non-English language

That’s about the only thing I agree with in that document. My personal
opinion is that hungarian notation produces the most unreadable code
imaginable. Sure, it produces tiny variable names, but since characters
are cheap, and human mental strain expensive, I think that one should
minimize the mapping necessary between the human’s brain and the code.

The tutorial presents this as an example of the proper use of hungarian
notation:

14 while (*pch!=0
15 wHash=(wHash<>11+*pch++;
16 cch=pch-sz;
17 pbsy=&rgbsyHash[(wHash&077777)%cwHash];
18 for (; *pbsy!=0; pbsy = &psy->bsyNext)
19 {
20 char szSy;
21 szSy= (psy=(struct SY
)&rgwDic[*pbsy])->sz;
22 pch=sz;
23 while (*pch==*szSy++)
24 {
25 if (*pch++==0)
26 return (psy);
27 }
28 }
29 cwSz=0;
30 if (cch>=2)
31 cwSz=(cch-2/sizeof(int)+1;
32 *pbsy=(int *)(psy=PsyCreate(cwSY+cwSz))-rgwDic;
33 Zero((int *)psy,cwSY);
34 bltbyte(sz, psy->sz, cch+1);
35 return(psy);
36 }

I must say, this really explains a lot about Microsoft’s programs.


Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html

···

On Mon, Jun 16, 2003 at 12:40:06AM +0900, Wesley J Landaker wrote:

On Mon, Jun 16, 2003 at 12:25:22AM +0900, Chad Fowler wrote:

It’s a Win32API convention meaning “Window Handle”.

Chad

Why don’t they call it “WindowHandle” or “window_handle”?
That would make more sense to me.

cBecause sthey vare dextremely pinto aHungarian nnotation.

You all know this already, but …

From: Daniel Carrera [mailto:dcarrera@math.umd.edu]
Sent: June 15, 2003 12:11

I just looked up “hungarian notation” in microsoft.com. I cam accross a
tutorial about it. Here is a quote from it:

This system became widely used inside Microsoft. It came to be known as
“Hungarian notation” because the prefixes make the variable
names look a
bit as though they’re written in some non-English language

“Hungarian Notation - The Good, The Bad and The Ugly”

Hungarian Notation (HN) is a naming convention invented by Charles Simonyi
from Microsoft. (He is Hungarian)

That’s about the only thing I agree with in that document. My personal
opinion is that hungarian notation produces the most unreadable code
imaginable. Sure, it produces tiny variable names, but since characters
are cheap, and human mental strain expensive, I think that one should
minimize the mapping necessary between the human’s brain and the code.

I hate HN and never use it, but it has “nothing” to do with variable names
per se. Whatever name you decide to use for the variable you just append
one letter in front of it denoting the variable type – you can use
hMyWindowHandle instead of hWnd.

Yura.

···

-----Original Message-----

Daniel Carrera wrote:

Sure, it produces tiny variable names, but since characters
are cheap, and human mental strain expensive, I think that one should
minimize the mapping necessary between the human’s brain and the code.

Don’t scoff at MS programmers because they’re using hn; pity them
because they’re not using Ruby.

Pretend you’re using a statically typed language. Now re-evaluate hn.

Not that I’m defending the notation. =) But when you’re buried
knee-deep in legacy C-code, would you rather be able to tell at a glance
that a variable is a pointer to an array of characters, or have to jump
around through the source and then back?

-Kent

···


Kent R. Spillner
“They that can give up essential liberty to obtain a little
temporary safety deserve neither liberty nor safety.”
- Benjamin Franklin

Sometimes one, sometimes many, ie. lpstrMyMessage.

It’s like anything else, you could get used to it, and your brain would
eventually not “see” the lpstr at the beginning, unless you needed to know
it was a long pointer to a string.

Also, the reason it is hWnd instead of something more verbose, is you have
to type it over and over and over when writing Windows programs

Having said all that, I much prefer The Ruby Way.

···

on 6/15/03 12:47 PM, Yura at yura@opmr.com wrote:

You all know this already, but …

-----Original Message-----
From: Daniel Carrera [mailto:dcarrera@math.umd.edu]
Sent: June 15, 2003 12:11

I just looked up “hungarian notation” in microsoft.com. I cam accross a
tutorial about it. Here is a quote from it:

This system became widely used inside Microsoft. It came to be known as
“Hungarian notation” because the prefixes make the variable
names look a
bit as though they’re written in some non-English language

(ootips) Hungarian Notation - The Good, The Bad and The Ugly
“Hungarian Notation - The Good, The Bad and The Ugly”

Hungarian Notation (HN) is a naming convention invented by Charles Simonyi
from Microsoft. (He is Hungarian)

That’s about the only thing I agree with in that document. My personal
opinion is that hungarian notation produces the most unreadable code
imaginable. Sure, it produces tiny variable names, but since characters
are cheap, and human mental strain expensive, I think that one should
minimize the mapping necessary between the human’s brain and the code.

I hate HN and never use it, but it has “nothing” to do with variable names
per se. Whatever name you decide to use for the variable you just append
one letter in front of it denoting the variable type – you can use
hMyWindowHandle instead of hWnd.

Yura.


Regards,
JJ

Finally using a Mac!

A better solution would be to avoid global variables, to avoid jumping
around, and create appropriate accessor functions.

I know I’m getting off-topic, but have you looked at the glibs? I really
like them. They really take a lot of the pain out of C programming. And
if you continue to use that kind of coding style in your programs you can
end up with some pretty nice code.

I still like Ruby better though. :slight_smile:

···

On Mon, Jun 16, 2003 at 02:20:24AM +0900, Kent R. Spillner wrote:

Pretend you’re using a statically typed language. Now re-evaluate hn.

Not that I’m defending the notation. =) But when you’re buried
knee-deep in legacy C-code, would you rather be able to tell at a glance
that a variable is a pointer to an array of characters, or have to jump
around through the source and then back?


Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html

My memory (and my memory goes back a long way :slight_smile: is that Hungarian
notation was invented back when C compilers didn’t do a great job of
diagnosing type mis-matches and there were no such things as function
prototypes. In addition to embedding the type of the variable in the
name, it gives the programmer a way to do “type algebra,” i.e.
it helps you to remember that dereferencing a pFoo yields a Foo.

The reason it’s called “Hungarian” notation is that it was invented by
Charles Symonyi, long-time Microsoft senior programmer, who was born in
Budapest.

I once invented a coding standard called Pottsylvanian Notation. All the
variables had to be named as if Boris and Natasha were coding, so you have
variables like “moose” and “squirrel”.

···

On Mon, 16 Jun 2003 01:47:07 +0900, Yura wrote:

You all know this already, but …

-----Original Message-----
From: Daniel Carrera [mailto:dcarrera@math.umd.edu] Sent: June 15, 2003
12:11

I just looked up “hungarian notation” in microsoft.com. I cam accross a
tutorial about it. Here is a quote from it:

This system became widely used inside Microsoft. It came to be known
as “Hungarian notation” because the prefixes make the variable
names look a
bit as though they’re written in some non-English language

(ootips) Hungarian Notation - The Good, The Bad and The Ugly “Hungarian Notation - The Good,
The Bad and The Ugly” …
Hungarian Notation (HN) is a naming convention invented by Charles Simonyi
from Microsoft. (He is Hungarian)

That’s about the only thing I agree with in that document. My personal
opinion is that hungarian notation produces the most unreadable code
imaginable. Sure, it produces tiny variable names, but since characters
are cheap, and human mental strain expensive, I think that one should
minimize the mapping necessary between the human’s brain and the code.

I hate HN and never use it, but it has “nothing” to do with variable names
per se. Whatever name you decide to use for the variable you just append
one letter in front of it denoting the variable type – you can use
hMyWindowHandle instead of hWnd.

Yura.

Daniel Carrera wrote:

Sure, it produces tiny variable names, but since characters
are cheap, and human mental strain expensive, I think that one should
minimize the mapping necessary between the human’s brain and the code.

Don’t scoff at MS programmers because they’re using hn; pity them
because they’re not using Ruby.

Yep, it’s the FNG again - what threw me more than anything was
the Ruby convention of scope prefixes
(@@ for a static variable, @ for an instance, capital letter
for a class, etc)

Peole who lives in kettles shouldn’t throw pots at black greenhouses :slight_smile:

···


Learning French is trivial: the word for horse is cheval, and
everything else follows in the same way.
– Alan J. Perlis
Rasputin :: Jack of All Trades - Master of Nuns

Also, the reason it is hWnd instead of something more verbose, is you have
to type it over and over and over when writing Windows programs

I guess that it might be an indiosyncratic term that a Windows programmer
would “just know”. The rest of the programming world also has those:

“tmp” is always a temporary variable.
i,j are always integer indices.

Having said all that, I much prefer The Ruby Way.

Definitelly. I still really dislike the Hungarian notation. I can think
of examples where it would really take away legibility. Specially with
Ruby.

···

On Mon, Jun 16, 2003 at 01:57:50AM +0900, John Johnson wrote:


Daniel Carrera | OpenPGP fingerprint:
Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88
UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html

Hi,

Also, the reason it is hWnd instead of something more verbose, is you have
to type it over and over and over when writing Windows programs
Having said all that, I much prefer The Ruby Way.

I somehow feel the need to justify myself :slight_smile: There was no conscious
decision on my part to use this particular notation, I merely copied
it from http://groups.google.com/groups?hl=de&lr=&ie=UTF-8&oe=utf-8&selm=20030509163416.9255.qmail%40web12306.mail.yahoo.com
and put it in my script without questioning it. I did not intend to
express any belief in which notation is better (personally, I do stuff
like my_variable most of the time).

···


Bye: Andi S. mailto:nullpointer@myrealbox.com

You’re putting the horse before the cart here - that phrase “legacy C
code” should strike fear into your heart, because things like “accessor
functions” were either unheard of, or considered a waste of precious
instructions. In environments where you specifically order your
if/else clauses for efficiency, making an accessor for an otherwise
global variable is an undreamt-of luxury. In short, readability was
not a priority. In that situation, hn was a costless improvement to
code readability.

So whither then, OO? The code that resulted from the previous attitude
was the major factor in promoting OO in industry, not because it’s
inherently better, but because OO allows sort of a continuous spaghetti
effect of replacing legacy code. The new code doesn’t even have to be
better (or even really “new” apart from the interface), because its
deleterious effects are better contained. This lets unexperienced
people (of which there are many many more than very experienced people)
maintain and update software that would otherwise be too complicated.
I know it’s not what’s in the OO marketing brochures, it’s just what it
looked like from my perspective.

matt smillie.

···

On Sunday, June 15, 2003, at 06:26 pm, Daniel Carrera wrote:

On Mon, Jun 16, 2003 at 02:20:24AM +0900, Kent R. Spillner wrote:

Pretend you’re using a statically typed language. Now re-evaluate hn.

Not that I’m defending the notation. =) But when you’re buried
knee-deep in legacy C-code, would you rather be able to tell at a
glance
that a variable is a pointer to an array of characters, or have to
jump
around through the source and then back?

A better solution would be to avoid global variables, to avoid jumping
around, and create appropriate accessor functions.

My memory (and my memory goes back a long way :slight_smile: is that Hungarian
notation was invented back when C compilers didn’t do a great job of
diagnosing type mis-matches and there were no such things as function
prototypes. In addition to embedding the type of the variable in the
name, it gives the programmer a way to do “type algebra,” i.e.
it helps you to remember that dereferencing a pFoo yields a Foo.

I think this is very true–some (hopefully small) amount of
Hungarian-like notation can be useful in situations where it is
critical to know the type of a symbol, but it’s ambiguous or leads to
namespace collisions otherwise. One example of this is VHDL – ports,
signals, and variables share the same namespace, but are not
syntactically identical–i.e. you can’t have a port and a signal both
called “DataOut” even though you really want to.

However, it makes sense only to embed the minimum amount of
information necessary. Having something like “DataOut” and “DataOut_o”
is usually sufficient, albeit even that is barely palpable to me. I
ever see VHDL code with a signal called ssulv31dt0uDataOut, somebody is
going to get schwacked! :wink:

Likewise, I think having “pFoo” isn’t necessary the most evil thing
ever, especially if there is some other “Foo” that you’re referring to,
but having, for example, “lpvfiidFoo” (long pointer to a void function
that takes two integers and a double) starts getting ridiculous very
quickly.

Interestingly enough, Ruby itself actually has something similar to
Hungarian notation–but here it’s not about TYPE, but about SCOPE.

local_variable
Constant
$global
@member
@@class_member

Contrast this to perl, which is more-or-less type based:

$scalar
@list

Anyway, interesting to think about. =)

I once invented a coding standard called Pottsylvanian Notation. All
the variables had to be named as if Boris and Natasha were coding, so
you have variables like “moose” and “squirrel”.

Unless of course it’s a function that pulls rabits out of a hat, in
which case you have to have variables like “hey” and “rocky”. :wink:

···

On Sunday 15 June 2003 11:28 am, Tim Hunter wrote:


Wesley J. Landaker - wjl@icecavern.net
OpenPGP FP: C99E DF40 54F6 B625 FD48 B509 A3DE 8D79 541F F830

One of my nice little ‘aha’ moments was when I realised that classnames
weren’t specialcased with capital letters; constants were. The class
names derived from their being constant objects of class Class.

martin

···

Rasputin rasputin@idoru.mine.nu wrote:

Yep, it’s the FNG again - what threw me more than anything was
the Ruby convention of scope prefixes
(@@ for a static variable, @ for an instance, capital letter
for a class, etc)

HN tends to lead to bad OO design.

Sometimes one, sometimes many, ie. lpstrMyMessage.

MyMessage should offer a service, not a type. If it can be printed or
displayed, it should offer those services. Or - if really needed - provide
something like asString() or a string op (well, in C++ of course).

Cheers
Franz

“John Johnson” jj5412@earthlink.net schrieb im Newsbeitrag
news:BB121DC5.4EA4%jj5412@earthlink.net…

You all know this already, but …

From: Daniel Carrera [mailto:dcarrera@math.umd.edu]
Sent: June 15, 2003 12:11

I just looked up “hungarian notation” in microsoft.com. I cam accross
a
tutorial about it. Here is a quote from it:

This system became widely used inside Microsoft. It came to be known as
“Hungarian notation” because the prefixes make the variable
names look a
bit as though they’re written in some non-English language

(ootips) Hungarian Notation - The Good, The Bad and The Ugly
“Hungarian Notation - The Good, The Bad and The Ugly”

Hungarian Notation (HN) is a naming convention invented by Charles
Simonyi
from Microsoft. (He is Hungarian)

That’s about the only thing I agree with in that document. My personal
opinion is that hungarian notation produces the most unreadable code
imaginable. Sure, it produces tiny variable names, but since
characters
are cheap, and human mental strain expensive, I think that one should
minimize the mapping necessary between the human’s brain and the code.

I hate HN and never use it, but it has “nothing” to do with variable
names
per se. Whatever name you decide to use for the variable you just
append

···

on 6/15/03 12:47 PM, Yura at yura@opmr.com wrote:

-----Original Message-----
one letter in front of it denoting the variable type – you can use
hMyWindowHandle instead of hWnd.

Yura.

Sometimes one, sometimes many, ie. lpstrMyMessage.

It’s like anything else, you could get used to it, and your brain would
eventually not “see” the lpstr at the beginning, unless you needed to know
it was a long pointer to a string.

Also, the reason it is hWnd instead of something more verbose, is you have
to type it over and over and over when writing Windows programs

Having said all that, I much prefer The Ruby Way.


Regards,
JJ

Finally using a Mac!