Παρασκευή 15 Οκτωβρίου 2021

Example MyApp - Make a Proper Icon

 Lets make a simple Application, using M2000. We want our app, named MyApp in a folder with a MyApp.exe and some files. All files in this folder can processed by Inno Setup, or we can simple zip in a compressed zip file. Our app not need installation to run.

We open M2000 and do this:

edit app (press enter, then copy the code, then press escape)

myico
cls,0
Print "This is a simple APP"
Show
title "This is myApp"
Input "Your name:", a$
Print "Thank you ";a$
Print "Press any key"
Push Key$ : Drop

For module myico we need an icon file type ico. We can use this: myApp.ico

first we have to move it from download folder to M2000 User folder

Apply this statement in M2000 to open the M2000 User folder

Win Dir$

Then copy the myApp.ico to  M2000 User folder.

Now lets get the binary data in the myico module

edit myico

now click on the editor header or use right button to open the context menu. Select the last menu item Load Resource (not shown at first sight, but the menu scrolls down, use mouse or arrows). Now a Load Resource form open and move to the last item (the newer one is the last one, use End key to go fast), and choose myApp.ico. The editor ask for a name so we write in the input form name myappico.

Now we have something like this:

\\$ c:\users\username\appdata\roaming\m2000\myApp.ico
Binary {
      AAABAAMAEBAAAAEACABoBQAANgAAACAgAAABAAgAqAgAAJ4FAABAQAAAAQAYACgy
      AAAAAAB//wAAAAAAAP//gAAAAAAB///AAAAAAAP//+AAAAAAB///+AAAAAAf///+
      ~~~~~~~~~~~~~~~~~~~~~ 300+ lines~~~~~~~~~~~~~~~~~~~~~~~~~
      AAAAAH////+AAAAB//////gAAB//////////////
} As myappico

Some 300 and more lines are deleted from above. The Binary { } has Base64 encoded binary data, and that is the file myApp.ico  (a remark show what the binary structure have). So the data processed when the module myico run, and stored to buffer myappico.



We add this code (we can exclude try but maybe an error can occur if we have a wrong file by mistake). Later we can exclude the try { } structure

try {

      icon myappico
}

So now we have two modules, the app module and the myico module.

lets save the program in an editable format:

save app

We can run the program from console using this:

app


Our application read a name and say Thank you, then wait to press any key to finish.

So now we want to save it with to benefits:

First we want at load event to auto run the gsb file. So we have to append some commands for this. Also we want to obscure the code, using the standard M2000 method for this:

save myApp @, {app:end}

The @ symbol after the name is a switch to enable the code hiding. Statements to run at load event are the app (to run the app module} and then to exit using End (because these statements consumed by console line interpreter).

We can test the myApp.gsb calling notepad to open it from M2000 console, using this:

Win "notepad", dir$+"myApp.gsb"


So now we have all the parts to feed the myApp folder. We have to copy the myApp.gsb from M2000 User folder (use Win Dir$), then we have to copy two files from AppDir$ (Win AppDir$) the folder where the m2000.exe used for this console, and we copy two files, m2000.exe and M2000.dll.


Now we have to rename two files: m2000.exe rename to myApp.exe and M2000.dll rename to lib.bin


We can add the myApp.ico optionally. The three files are all we need. The myApp.exe (which is the M2000.exe) find the myApp.gsb and the lib.bin and use them. The registered M2000.dll not used, so our app always use the version which we pack it (the lib.bin, which is a M2000.dll).

From the example above there is a hidden stage: How we can produce a proper ico file?

Make a proper icon file type ico

An ico file is a collection of images; Each image may have different type.

For our application ico file need 16X16 8bit, 32X32 8bit (don't use 24 or 32 bit images for these resolutions)

We can find many ico files in the internet but need some work to make them compatible.

We need an icon editor. There is one very good online: icon-editor

From the start page choose Open ico File (say we have one from internet which have 32x32 and 16x16 with 32bit color - not compatible)


So we have to change it (also we can delete some other images above 64X64):



So we change to 8bit and that is ok. We choose the download button(with an arrow points down).

Epilogue

The method described here is easy to follow by a novice M2000 user. Before we make the distribution zip file (with the basic three files, myApp.gsb, myApp.exe, lib.bin) we can test the myApp.gsb using the App.gsb (which we can edit) and then using the myApp.

All the files used for this example are in one zip file (7z type, about 2MB): TestApp.7z

Compression / decompression software is free here: https://www.7-zip.org/

George Karras




Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου

You can feel free to write any suggestion, or idea on the subject.