Old 20th December 2001, 08:05   #1
Smile2Me
Guest
 
Posts: n/a
SendMessage

dear all,

I want to do the following:

Matlab is some sort of command-prompt mathematics program and I want to install a plugin into this program. This can only be done by Matlab itself, so you should type the command and Enter and then it's installed.
Is it possible to automate this using SendMessage? And if so, can anyone give me a link to a site where I can find more codes for possible messages the the matlabwindow, because I'm not experienced in c-programming...

thx a lot all, greetz, Hendri.
  Reply With Quote
Old 20th December 2001, 19:43   #2
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Did you try to use:
X:\whatever\matlab\matlab.exe < installplugin.txt

when installplugin.txt is the commands you need to enter to matlab?
kichik is offline   Reply With Quote
Old 21st December 2001, 08:54   #3
Smile2Me
Guest
 
Posts: n/a
thx, i tried, but it didn't work...
but maybe there are other possibilities for the command line, so thx for your idea, greetz,

Hendri,
  Reply With Quote
Old 21st December 2001, 12:59   #4
Smile2Me
Guest
 
Posts: n/a
well, matlab does not support command-line arguments at startup, so if anyone knows a way how to use SendMessage for this problem, this would bevery helpfull.

Thx, greetz, Hendri.
  Reply With Quote
Old 21st December 2001, 13:15   #5
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Oops... If you DID read this message before I changed it, please ignore it. It was a mistake.

And now that I think about it, you just can't do it with SendMessage. SendMessage only works on windows, and if you say that Matlab is command prompt program then you just can't do it.

Here is a quote from MSDN:
Quote:
The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message.
Sorry...
kichik is offline   Reply With Quote
Old 21st December 2001, 16:44   #6
Smile2Me
Guest
 
Posts: n/a
Unhappy

kichik, thx for your reply...
I realize that it's indeed not possible with SendMessage. I will take a look at the website of Matlab. Maybe they can give me a hint on how to interact with Matlab....

Thx anyway, greetz, Hendri.
  Reply With Quote
Old 21st December 2001, 21:51   #7
eccles
NSIS Dev
 
eccles's Avatar
 
Join Date: Sep 2001
Location: Leicester, UK
Posts: 193
Mmm, but a command prompt is just another window, so it should be possible.

Try this..
code:
Name "Test"
OutFile "test.exe"

; Send a simple command to a Command Prompt window (works in Win2K)
Section
FindWindow $R0 "" "Command Prompt"
; or, more generic -
; FindWindow $R0 "ConsoleWindowClass"
IntCmp $R0 0 NoWindow
MessageBox MB_ICONINFORMATION|MB_OK "Window found ($R0)"
Push $R0
Push "dir$\r"
Call SendChars
Return
NoWindow:
MessageBox MB_ICONEXCLAMATION|MB_OK "No window found!"
SectionEnd

; SendChars:
; Send a stream of WM_CHAR messages to a window to simulate user input
; Usage:
; Push <window-handle>
; Push <message>
; Call SendChars
Function SendChars
Exch $R0 ; Get string
Exch
Exch $R1 ; Get hwnd
Push $R2
Push $R3
StrCpy $R2 0 ; Char index
loop:
StrCpy $R3 $R0 1 $R2 ; Get next char
StrCmp $R3 "" done
Push $R3
Call CharToAscii ; Convert it to ASCII
Pop $R3
SendMessage $R1 258 $R3 0 ; Send a WM_CHAR message
IntOp $R2 $R2 + 1
Goto loop
done:
Pop $R3
Pop $R2
Pop $R1
Pop $R0
FunctionEnd

; CharToAscii:
; Convert a character to it's ascii code
; Usage:
; Push <character>
; Call CharToAscii
; Pop <ascii-code>
;
; Surely there must be a simpler way of doing this!
; Am I missing something obvious??
Function CharToAscii
Exch $R0 ; Get character
Push $R1
Push $R2
StrCpy $R1 255 ; ASCII code test counter
loop:
IntFmt $R2 "%c" $R1 ; Convert current test counter to it's char
StrCmp $R2 $R0 done ; Have we found it yet? (note - not case sensitive)
IntOp $R1 $R1 - 1 ; Next code
IntCmp $R1 0 "" "" loop
done:
Pop $R2
Exch
Pop $R0
Exch $R1
FunctionEnd

--
Dave.
eccles is offline   Reply With Quote
Old 21st December 2001, 22:09   #8
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Nice!

I haven't though about it like this. Good work
Will it work on full screened command prompts?
kichik is offline   Reply With Quote
Old 21st December 2001, 22:29   #9
eccles
NSIS Dev
 
eccles's Avatar
 
Join Date: Sep 2001
Location: Leicester, UK
Posts: 193
Just tried - yep, seems to

Hopefully this Matlab app has a unique, consistent, window title (as ConsoleWindowClass on its own could find anything!)

--
Dave.
eccles is offline   Reply With Quote
Old 22nd December 2001, 06:44   #10
Smile2Me
Guest
 
Posts: n/a
Dave,

thx a lot for your reply, but it doesn't work yet...

The problem is, that my program is compatible to two Matlab versions: 5 and 6. 5 only has a window called "Matlab command window" and the program should be able to find this window, but i couldn't test this because I do not have Matlab 5. Matlab 6 has a child (see the picture). The child has a name "Command window" and the test.nsi is not able to find this window. (it can find the main Matlab though...)

Can you help me out here?

thx, Hendri.
Attached Images
File Type: jpg matlab.jpg (67.9 KB, 219 views)
  Reply With Quote
Old 22nd December 2001, 07:09   #11
Smile2Me
Guest
 
Posts: n/a
hi dave,

I found out (at least I think), that Matlab is not really a command prompt program, but it only looks like that. This is because above functions work really well for the DOS-window, but cannot add anything to a Matlab window. Please, take a look at the picture i posted earlier, maybe this might give you a clue how to do this...

Thx a lot, Hendri.
  Reply With Quote
Old 22nd December 2001, 13:31   #12
eccles
NSIS Dev
 
eccles's Avatar
 
Join Date: Sep 2001
Location: Leicester, UK
Posts: 193
Ok, I see what you mean.

Try this, if it doesn't work then maybe there's another window between the main window and the Command Window, but this has no name (that you can see) so you'd have to find out the window class name. To do that I use a tool which comes with Visual Studio, but I'm sure there must be freeware utilities that can do that too...
code:
Section
; Look for Matlab 5 window
FindWindow $R0 "" "Matlab command window"
IntCmp $R0 0 "" FoundWindow FoundWindow
; Look for Matlab 6 window (main window)
FindWindow $R0 "" "MATLAB"
IntCmp $R0 0 NoWindow
; Now look for the command window (child window) inside it
FindWindow $R0 "" "Command Window" $R0
IntCmp $R0 0 NoWindow
FoundWindow:
MessageBox MB_ICONINFORMATION|MB_OK "Window found ($R0)"
Push $R0
Push "dir$\r"
Call SendChars
Return
NoWindow:
MessageBox MB_ICONEXCLAMATION|MB_OK "No window found!"
SectionEnd

Good luck! And Happy Christmas to all...

--
Dave.
eccles is offline   Reply With Quote
Old 23rd December 2001, 00:42   #13
Smile2Me
Guest
 
Posts: n/a
Dave,

thx a lot for your reply and the code, but it's still not able to find the Matlab command window using Matlab 6. In Matlab 5 it finds the window, but does not add anything behind the command prompt...

So I guess Matlab uses some strange unknown construction for it's windows...

And I guess that I will have to think about another solution on how to do the thing i mentioned above. Or construct erverything in a completely other way...

I also posted this thread at www.mathworks.com (Matlab web-site) but they didn't even give a response....

So thx a lot all (especially Dave!!!), if you know another way of doing this, please let me know, thx, greetz,

Hendri.
  Reply With Quote
Old 24th December 2001, 11:43   #14
petersa
Senior Member
 
petersa's Avatar
 
Join Date: Apr 2001
Location: Melbourne, Australia
Posts: 207
You might be interested in downloading AutoIt. It allows you to write small scripts that activate windows, send keystrokes, mouse clicks, all sorts of stuff, and it allows you to compile your scripts into small EXE files.

My favourite utility before I discovered NSIS!

Sure, it's not the most practical solution, but it's better than nothing.

Feel free to PM me if you need help writing a script for it.
petersa is offline   Reply With Quote
Old 24th December 2001, 13:39   #15
Smile2Me
Guest
 
Posts: n/a
Petersa,

thx for your reply, I just downloaded the program and I will certainly try it.

Have a nice christmas time, greetz,
Hendri.
  Reply With Quote
Old 25th December 2001, 23:44   #16
Smile2Me
Guest
 
Posts: n/a
Petersa,

I tried AutoIt, but I couldn't get it to work. Even the example program's (after translating the neccessary command's to Dutch ) didn't work (eg: adding lines to notepad). I also tried to apply this to Matlab but did also not work unfortunately....

I've given up, I think...

Thx all anyway. I will be considering your inputs, maybe, I can get some of it to work later on.

THX, greetz, Hendri.
  Reply With Quote
Old 26th December 2001, 14:31   #17
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Well, as I see it all you need to do is to discover Matlab command window class name. After you do that Dave's code will work.

To discover the class name of the command window use Microsoft Spy++ (included with Visual C++) or Spy (included with Microsoft SDK). I am sure there is a freeware that displays this kind of information for all windows somewhere out there but I don't know it. Don't give up, search for it if you don't have Visual C++ or you don't want to download Microsoft SDK.

KiCHiK
kichik is offline   Reply With Quote
Old 26th December 2001, 14:42   #18
Smile2Me
Guest
 
Posts: n/a
kichik, thx for your idea!
I'll start a search for Spy for I do not have C++

If you know some page, please tell me...

Thx a lot, greetz, Hendri.
  Reply With Quote
Old 26th December 2001, 15:29   #19
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
I have found just the prog for you. It tells you the class name of the window you are pointing with the mouse. It doesn't shows all messages sent to all windows like Spy++ but it should do the trick.

WinSpy

Enjoy!
kichik is offline   Reply With Quote
Old 26th December 2001, 15:48   #20
Smile2Me
Guest
 
Posts: n/a
Kichik,

thx for this URL, it indeed is the program I was looking for. So I found out that Matlab 6 has a SunAwtFrame class window with Caption "Matlab", my installer found the window (!!!) but it's not able to send some characters to it... (I use SendChars posted as a reply to my first thread)... Do you know what's missing now ???

Thx, greetz, Hendri.
  Reply With Quote
Old 26th December 2001, 15:52   #21
Smile2Me
Guest
 
Posts: n/a
Well I mean, (i hope this was clear...) that nothing happens to the window, no characters appear in the window, nothing is being executed...

thx, Hendri.
  Reply With Quote
Old 26th December 2001, 16:26   #22
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Attached is Spy from Microsoft Platform SDK (it's a free download but a long one with all the other stuff).

In the Spy menu click on Select window and select the window needed from Matlab. Then click Start!, type something in Matlab and notice what messages it gets.

You should use the exact same messages in your NSIS script.

If you get too many messages start filtering them with Options->Messages.
Attached Files
File Type: zip spy.zip (23.7 KB, 172 views)

Last edited by kichik; 26th December 2001 at 17:35.
kichik is offline   Reply With Quote
Old 26th December 2001, 17:26   #23
Smile2Me
Guest
 
Posts: n/a
"Cannot load HOOK.DLL" is the message I get when clicking 'Start!'

Can you also post this dll (and maybe other files the spy uses???)

Thx a lot, greetz, Hendri.
  Reply With Quote
Old 26th December 2001, 17:39   #24
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Oops...

Well I have reupped it in the same reply (2 up) with hook.dll. I also checked that it doesn't need anything else but hook.dll.

KiCHiK
kichik is offline   Reply With Quote
Old 26th December 2001, 22:16   #25
Smile2Me
Guest
 
Posts: n/a
thx kichik,

i already gave it a try using notepad but i got indeed a lot of messages from one window. I will try to sort this out using the options menu...

Thanks a lot, greetz, Hendri.
  Reply With Quote
Old 29th December 2001, 19:56   #26
eccles
NSIS Dev
 
eccles's Avatar
 
Join Date: Sep 2001
Location: Leicester, UK
Posts: 193
Hi Hendri,

How's it going, working yet?

If not, maybe what Matlab's after are messages to fool it into thinking it has keyboard focus...
code:
Function SendChars
Exch $R0 ; Get string
Exch
Exch $R1 ; Get hwnd
Push $R2
Push $R3
SendMessage $R1 ${WM_SETFOCUS} 0 0
StrCpy $R2 0 ; Char index
loop:
StrCpy $R3 $R0 1 $R2 ; Get next char
StrCmp $R3 "" done
Push $R3
Call CharToAscii ; Convert it to ASCII
Pop $R3
SendMessage $R1 ${WM_CHAR} $R3 0
IntOp $R2 $R2 + 1
Goto loop
done:
SendMessage $R1 ${WM_KILLFOCUS} 0 0
Pop $R3
Pop $R2
Pop $R1
Pop $R0
FunctionEnd

btw, see KiCHik's Windows Messages thread for the header file for the !defines used. Very handy!

Other than that, I'm not sure what else to suggest Maybe experiment with other windows messages, described at MSDN.

Good luck!
Dave.
eccles is offline   Reply With Quote
Old 29th December 2001, 20:15   #27
Smile2Me
Guest
 
Posts: n/a
Hi Dave,

thx i'll try. I indeed downloaded Kichik's package. I also used some spy to determine what messages to send to Matlab. But I do not understand this output. I press for example 'd' and one time the spy tells me that this is in fact produced by the messages key_down, char and key_up and another time it's produced by char, char and key_up...

So I can't figure out what to send...

But I tried to send 'dir\n' using SendChar and using the first construction (key_down, char, key_up) for each character and Matlab interpreted these messages as:
49[Enter]

So, again really stuck. Is this a strange thing of Matlab, you think, or am I just doing the wrong thing????

Thx in advance, i didn't try above yet, i'll do it right away, thx,

greetz, Hendri.
  Reply With Quote
Old 29th December 2001, 20:35   #28
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
From MSDN:

Quote:
The WM_CHAR message is posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function. WM_CHAR contains the character code of the key that was pressed.
Correct me if I am wrong but this means that you don't need to send WM_KEYDOWN and WM_KEYUP. All that it does is to send to the window WM_CHAR so you can skip it and just send WM_CHAR.

And if you already got it to send 49[Enter] keep trying, you are on the right track .

KiCHiK

PS
I am glad you like my header file
kichik is offline   Reply With Quote
Old 30th December 2001, 18:09   #29
Smile2Me
Guest
 
Posts: n/a
Kichik,

I think i should use Key_down and up...
I first tried without, but that resulted in just no response from Matlab, so i think i should use it...

Indeed i'm on the right track, i hope, so i'll keep trying, maybe someone has another idea what's going on with Matlab, because in a simple Dos-Window, there is no problem with just sending WM_CHAR...

Thx, greetz, Hendri.
  Reply With Quote
Old 30th December 2001, 18:12   #30
Smile2Me
Guest
 
Posts: n/a
Bye the way, trying to send 'dir\n' resulted in '49[Enter]' so on the right track... I don't know. There seems to be something wrong...

Hendri.
  Reply With Quote
Old 30th December 2001, 20:54   #31
futuris
Junior Member
 
Join Date: Dec 2001
Posts: 13
Exclamation Possible source of problem!

> Matlab 6 has a SunAwtFrame class window with Caption "Matlab"

"SunAwtFrame" means that MatLab written in Java! It means, that it will not (most likely) react to Windows messages.
futuris is offline   Reply With Quote
Old 31st December 2001, 12:08   #32
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
Smile2Me, have you tried sending the lParam and wParam as shown on Spy?

And does [Enter] means a line break or does it actually show [Enter]?
kichik is offline   Reply With Quote
Old 1st January 2002, 21:07   #33
Smile2Me
Guest
 
Posts: n/a
Kichik,

[Enter] means a line break indeed, but also that the command entered will be executed. In Matlab 49[Enter] means that it will assign the value 49 to the variable 'ans'...

But I think I replicated the messages given by Spy completely, but I'll check on this again, thx...

Happy NewYear to you all!!!

Greetz, Hendri.
  Reply With Quote
Old 1st January 2002, 21:33   #34
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
I still think you are on the right track.

As you can see by the "table" below the values you sent with WM_KEYUP/DOWN/CHAR were just shifted some to the digits zone. The difference between d and i is the same as 4 and 9. All we are missing now is the r

code:

4 5678 9
d efgh i



Did you try to use spy to see what messages are being sent from the installer and then compare them to the messages you sent manually?

KiCHiK
kichik is offline   Reply With Quote
Old 2nd January 2002, 13:35   #35
Smile2Me
Guest
 
Posts: n/a
Kichik,

bright point!!!
I'll check the function CharToAscii as it seems that there is something wrong there...

Yeah, i spied the messages from installler to Matlab and everything looked ok to me... (just the messages i send where reported, nothing strange...)

But i also discovered some functions in Matlab to do the job i posted this thread for (in the end, I wanted to protect my M-files (just textfiles with commands) from being viewed or changed). Matlab offers a service for that. So finding some dll's of Matlab give me the opportunity to code my files...

So the goal is achieved!!!

But i'll keep trying to get the messages to work because i think i'll need it later on for other installer features...

So at this point thx all for the helping replies!!!

Kichik, i'll work on it, and i'll post my result here!!!

THX ALL, greetz, Hendri.
  Reply With Quote
Old 14th January 2002, 17:07   #36
Smile2Me
Guest
 
Posts: n/a
Some old topic information:

I gave up, but did the thing in another way, as you might have read...

But I've got a new question on SendMessage.

Please help me at:
http://forums.winamp.com/showthread....threadid=71924

Thx all, greetz, Hendri.
  Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump