How do I set an icon when using 'newlisp link.lsp'

Q&A's, tips, howto's
Locked
HJH
Posts: 21
Joined: Tue May 31, 2005 2:21 pm
Location: Europe

How do I set an icon when using 'newlisp link.lsp'

Post by HJH »

Hello

I successfully used on a command prompt

Code: Select all

newlisp link.lisp
(see http://www.newlisp.org/downloads/newlis ... ml#linking to create a 211kB-non-GUI-MSWindows executable with a newLisp script I wrote.

It is fantastic how easy it is, to create small handy stand-alone Windows apps doing a particular task. (And the installation then is just copy/paste an exe).

My question: Is it possible to add an icon file myIcon.ICO during the linking process?

If I construct several of these programs that would be useful to be able to distinguish them by the icon.

--HJH

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

I think newlisp.exe has no icon-resource.
You may try the run wrapper from Peter:

http://www.turtle.dds.nl/run/index.html

You can compile this wrapper with your own icon or use a tool like resource-hacker to change it.
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

The question starts me thinking for a solution:

I tried to add a resource to newLISP.exe with

http://www.users.on.net/johnson/resourcehacker/

and get a new exe with icon. It still works as before with link.lsp
and show the icon in the command-window and the task-bar.

So exactly what you want. So we can make nice small tool with their own icon. Of cource still a command-line interface!
Hans-Peter

HJH
Posts: 21
Joined: Tue May 31, 2005 2:21 pm
Location: Europe

Post by HJH »

HPW wrote:...It still works as before with link.lsp
and show the icon in the command-window and the task-bar.

So exactly what you want.
Yes, indeed. I use this approach now. I just do a backup copy of the original 'newlisp.exe' to have it handy for the next time. Thank you for this recommendation!

HPW wrote:So we can make nice small tool with their own icon. Of cource still a command-line interface!
Yes, but often command line tools are just good enough; I collect a couple of file, do some minor processing and write out a result file and a log file. Just the things script languages are meant for.

Of course it would be nice to give the user a visual feedback as well by showing a standard Windows message box ("Success" or "Failure, see log file").

Alex has a nice example using a Win32 function call from

Code: Select all

(import "kernel32.DLL" "GetStdHandle") 
See entry http://www.alh.net/newlisp/phpbb/viewtopic.php?t=688

So it seems it would not be too difficult to call other Win32 functions.

Has somebody the calling sequence just ready? (copy / paste)?

--HJH

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

How about:

Code: Select all

 (import "user32.dll" "MessageBoxA")

(MessageBoxA 0 "Content" "Caption" 0)
(MessageBoxA 0 "Content" "Caption" 1)
(MessageBoxA 0 "Content" "Caption" 2)
etc.

Hans-Peter

HJH
Posts: 21
Joined: Tue May 31, 2005 2:21 pm
Location: Europe

Post by HJH »

It works fine in the 1.4MB newlisp-tk.exe but not in the 210kB newlisp.exe

--HJH

HJH
Posts: 21
Joined: Tue May 31, 2005 2:21 pm
Location: Europe

Post by HJH »

Why does

Code: Select all

(import "user32.dll" "MessageBoxA") 

(MessageBoxA 0 "Content" "Caption" 0) 
not work in newlisp.exe (210kB exe)?

--HJH

Sammo
Posts: 180
Joined: Sat Dec 06, 2003 6:11 pm
Location: Loveland, Colorado USA

Post by Sammo »

Hmmm...

With my 186.5KB newlisp.exe ("newLISP v.8.6.0 on Win32 MinGW") running on win2K sp4, the code example works perfectly.

Code: Select all

(import "user32.dll" "MessageBoxA") 
(MessageBoxA 0 "Content" "Caption" 0) 
pops up a modal box in the middle of the screen with caption "Caption", content "Content", and an OK button.

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Same observation as Sammo here.
Works for me with all 3 version of current newlisp: TK, EXE and DLL

I also tested with the icon resource version.

File-sizes:
Standard-EXE 8.6.0 MINGW: 190976 Bytes
ICON-EXE 8.6.0 MINGW: 192000 Bytes

Code: Select all

newLISP v.8.6.0 on Win32 MinGW, execute 'newlisp -h' for more info.
> (import "user32.dll" "MessageBoxA")
MessageBoxA <77D504EA>
> (MessageBoxA 0 "Content" "Caption" 0)
1
One observation: Called the first time the messagebox gets behind the console window and is only visible on the task bar.
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

>> It works fine in the 1.4MB newlisp-tk.exe but not in the 210kB newlisp.exe

the 1.4MB newlisp-tk.exe is just the Tcl/Tk frontend to the smaller newlisp.exe. So when you run newlisp-tk.exe, it launches newlisp.exe and communicated with it via TCP/IP. If it works using newlisp-tk.exe is also must work with newlisp.exe by definition.

Lutz

HJH
Posts: 21
Joined: Tue May 31, 2005 2:21 pm
Location: Europe

Post by HJH »

Yes, thank you all for your answers.

In fact the dialog is produced, but it does not show up. The only thing that something happens is a new entry in the taskbar where people do not normally check regularily for new things. So from a usability point of view it is useless.

But let's not use more time with this issue. I just write a text log file as feedback and (exit) newlisp. If I want to do a GUI app I'll stick to the 1.2MB newlisp-tk-combination.

--HJH

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Adding this to init.lsp

Code: Select all

(define (mymsgbox cont capt)
	(if (not MessageBoxA)
		(import "user32.dll" "MessageBoxA"))
	(MessageBoxA 0 cont capt 0))
seems to solve the display problem on the first call of:
(mymsgbox "Content" "Caption")
Hans-Peter

Locked