saivert
21st June 2005 23:01 UTC
MSN Messenger and NSIS (Now Playing)
I'm working on a NSIS script that uses the System plug-in in order to set the Now Playing item in MSN Messenger.
Here is the script, but something is wrong. CAn someone point it out for me?
Function Page1Leave
ReadIniStr $R0 "$PLUGINSDIR\msnmsgr-nowplaying.ini" "Settings" "State"
StrCmp $R0 0 next
Abort
next:
ReadIniStr $R1 "$PLUGINSDIR\msnmsgr-nowplaying.ini" "Field 1" "State"
StrCpy $TITLE $R1
StrCpy $ARTIST "Saivert"
StrCpy $ALBUM "The last one"
StrCpy $R4 'Music\01\0{0} - {1}\0 $ARTIST \0 $TITLE \0 $ALBUM \0WMContentID'
StrLen $R5 $R4
IntOp $R5 $R5 * 2
System::Alloc /NOUNLOAD 256
Pop $R6
System::Call /NOUNLOAD "*$R6(&w128 R4.)"
System::Call /NOUNLOAD "*(i 0x547, i R5, i R1) i .R2"
FindWindow $R3 "MsnMsgrUIManager"
SendMessage $R3 ${WM_COPYDATA} $HWNDPARENT $R2
System::Free /NOUNLOAD $R2
System::Free $R6
; Write to IO ini file
WriteIniStr "$PLUGINSDIR\msnmsgr-nowplaying.ini" "Field 3" "Text" $R4
SendMessage $HWNDPARENT 0x408 0 0 ; Reload page
Abort
FunctionEnd
The code is a fragment of the entire script. I'm using an InstallOptions page to present a text field where one can enter a title, the ARTIST and ALBUM is variables declared with
Var and set to static values using
StrCpy. When user clicks the next button, the function above gets called, and it just executes the commands past
next label and then keeps the page by using an undocumented message to reload the page. This is so I can write to the IO ini file and have the new data reloaded by InstallOptions.
saivert
30th June 2005 17:56 UTC
I guess none of you are interested in this. It didn't take long before this post ended up on page three. So here is an update anyway:
I have rewritten the code to use wsprintfW as in ShaneH's code over at MsnFanatics.com, but it's still not working.
I saw some VB code there that used a structure to hold the title, artist and album info (pluss WMCOntentID) but later code just uses a string with literal "\0" sequences in it.
The code so far:
Function Page1Leave
ReadIniStr $R0 "$PLUGINSDIR\msnmsgr-nowplaying.ini" "Settings" "State"
StrCmp $R0 0 next
StrCmp $R0 5 clear
clear:
FindWindow $R0 "#32770" "" $HWNDPARENT 0
GetDlgItem $R0 $R0 1203
SendMessage $R0 0xC 0 "STR:"
Abort
next:
ReadIniStr $R0 "$PLUGINSDIR\msnmsgr-nowplaying.ini" "Field 4" "State"
System::Alloc 1024
Pop $R1
; Set up string to send the MSN Messenger
; A backslash at the end of line means span next line.
; I needed to do this in order to keep the layout on
; the forum neat.
System::Call 'user32::wsprintfW(i R1, w s, i 1, w "{0} - {1}", w R0,\
w "Artist", w "Album", w "WMContentID") i..?c'\
"\\0Music\\0%d\\0%s\\0%s\\0%s\\0%s\\0%s\\0"
System::Call "kernel32::lstrlenW(i R1) i.R2"
IntOp $R2 $R2 * 2
System::Call "*(i 0x547, i R2, i R1) i .R3"
StrCpy $R4 0
nextwnd:
FindWindow $R5 "MsnMsgrUIManager" "" 0 $R4
StrCpy $R4 $R5
SendMessage $R5 ${WM_COPYDATA} $HWNDPARENT $R3 /TIMEOUT=1000
StrCmp $R5 0 +1 nextwnd
System::Free $R3
; get the complete string
System::Call "*$R1(&w1024 .R6)"
System::Free $R1
; Write to IO ini file
;WriteIniStr "$PLUGINSDIR\msnmsgr-nowplaying.ini" "Field 7" "State" $R6
;SendMessage $HWNDPARENT 0x408 0 0 ; Reload page
; we just set the text
FindWindow $R0 "#32770" "" $HWNDPARENT 0
GetDlgItem $R0 $R0 1206
SendMessage $R0 0xC 0 "STR:$R6"
Abort
FunctionEnd
You can download the latest 7z archive with all the files here:
msnmsgr-nowplaying.7z (34kB)