Author Topic: GUI programming with events  (Read 2636 times)

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9747
  • Assembler is fun ;-)
    • MasmBasic
GUI programming with events
« on: February 25, 2019, 11:07:31 AM »
Example #1: Loading and displaying images

GuiParas equ "GuiImage demo", w555, h500, bLiteYellow, m9
include \masm32\MasmBasic\Res\MbGui.asm
Event Paint
  GuiImage 123, fit             ; image from resources, ID 123; fit to window size
  GuiImage "\Masm32\examples\exampl04\car\car.jpg", 220, 280, 300, 80  ; image from disk, pos x, y, w, h
  GuiImage "http://www.animatedgif.net/cartoons/apinksax_e0.gif", 20, 220      ; image from the web, pos x, y
  GuiTextBox 99.9-100, 99.9-55, 80, 32, "Try sizing the window", bcol LiteGreen
GuiEnd


The resource file:
Code: [Select]
#include "resource.h"
IDI_APPLICATION ICON "\\Masm32\\MasmBasic\\icons\\Globe.ico"
01 RT_MANIFEST "\\Masm32\\MasmBasic\\Res\\XpManifest.xml"
123 RCDATA "\Masm32\\MasmBasic\\BugTests\\pics\\beach.jpg"

Project attached, greatful for feedback if it works on all Windows versions. Building requires MasmBasic version 25 Feb 19

Siekmanski

  • Member
  • *****
  • Posts: 1909
Re: GUI programming with events
« Reply #1 on: February 25, 2019, 08:34:29 PM »
Works on Windows 8.1
The background stretches and the foreground anim and bitmap image are not.
Creative coders use backward thinking techniques as a strategy.

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9747
  • Assembler is fun ;-)
    • MasmBasic
Re: GUI programming with events
« Reply #2 on: February 25, 2019, 09:22:33 PM »
Thanks, Marinus. The stretching behaviour is by design, only the "fit" forces adjusting the size.

guga

  • Member
  • *****
  • Posts: 1063
  • Assembly is a state of art.
    • RosAsm
Re: GUI programming with events
« Reply #3 on: February 26, 2019, 01:23:51 AM »
Hi JJ

not working here on Windows10




And, if i put the file on another directory, the gui opened, but without the image. This error came up "Could not open \Masm32\examples\exampl04\car\car.jpg for FileRead$ etc" (yes, car.jpg is inside the masm directory on my PC at: "C:\masm32\examples\exampl04\car\car.jpg"
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

HSE

  • Member
  • *****
  • Posts: 1131
  • <AMD>< 7-32>
Re: GUI programming with events
« Reply #4 on: February 26, 2019, 02:39:22 AM »
Hi JJ. Perfect in 7-32

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9747
  • Assembler is fun ;-)
    • MasmBasic
Re: GUI programming with events
« Reply #5 on: February 26, 2019, 03:38:19 AM »
And, if i put the file on another directory, the gui opened, but without the image. This error came up "Could not open \Masm32\examples\exampl04\car\car.jpg for FileRead$ etc" (yes, car.jpg is inside the masm directory on my PC at: "C:\masm32\examples\exampl04\car\car.jpg"

Hi Guga,

Apparently something blocks the download of the http: gif. It works on wifee's Win10 machine, but security settings are not that strict 8)
Re car: Did you try from drive C: or from another drive? The program tries to load ?:\Masm32\examples\exampl04\car\car.jpg, i.e. from the current drive.

@HSE, thanks, good to know.

guga

  • Member
  • *****
  • Posts: 1063
  • Assembly is a state of art.
    • RosAsm
Re: GUI programming with events
« Reply #6 on: February 26, 2019, 04:30:14 AM »
HI JJ

I tried both ways. car.jpg is in drive "c" (on the directory where masm ins installed)

I tested it putting GuiImageDemo.exe in masmbasic directory "ascuser" and the error showed up. Then i tried in the main masm directory "c:\masm32', and the main "c:\" and the error happened again, then i tried on other drives "D", "E", "H" and the error in the image showed up too.

Windows10 is a true hell. I had some problems of that with RosAsm too, when trying to close some apps after debugging it.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9747
  • Assembler is fun ;-)
    • MasmBasic
Re: GUI programming with events
« Reply #7 on: February 26, 2019, 05:18:56 AM »
Thanks, Guga. I have no idea what's happening. Can you please test the attached debug version?

LordAdef

  • Member
  • ****
  • Posts: 642
Re: GUI programming with events
« Reply #8 on: February 27, 2019, 04:53:40 AM »
NICE JJ!
I used to first version, without any issue

guga

  • Member
  • *****
  • Posts: 1063
  • Assembly is a state of art.
    • RosAsm
Re: GUI programming with events
« Reply #9 on: February 27, 2019, 05:34:02 AM »
Don´t know why windows10 is doing this with the app when i put it in the masm32 directory or in masmbasic one. You other files works ok.

To make it work, i did 2 tests:

1st) Extracted the file to drive "D:" and opened from there:

The gui showed up, but an error came out:

Quote
"0       01.01.1601  00:00:00
test    $f$:20          0       <not a pointer>
## line 11: image could not be loaded, Ok
Could not open

for FileRead$ etc.
## line 15: image could not be loaded, Ok"

After i  clicked on "Ok" (After the error message), the gui appeared, but the image of the pink panther just was displayed after i  resize the window.


2nd test) -

Strangely, the file loaded Ok, when i opened directly through the zip file. Windows saved it on the temp directory.


The error above was still there, but this time, the pink panther image showed up right in time. I mean, when the gui was displayed without i having to resize the window

Btw, the same error msg came up, but no messagebox.

"22115   16.03.2002  03:41:38    \Masm32\examples\exampl04\car\car.jpg
test    $f$:20          ÿØÿà
## line 11: image could not be loaded, Ok
## line 15: image could not be loaded, Ok"


Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9747
  • Assembler is fun ;-)
    • MasmBasic
Re: GUI programming with events
« Reply #10 on: February 27, 2019, 07:11:05 AM »
01.01.1601 and not a pointer mean the car.jpg simply wasn't there - which is normal if the current drive does not have a Masm32 installation.

The "image could not be loaded" is GdiPlus stuff, probably because the download of one of the GIFs was not finished. Will investigate, thanxalot for the feedback :icon14:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9747
  • Assembler is fun ;-)
    • MasmBasic
Re: GUI programming with events
« Reply #11 on: March 13, 2019, 01:10:00 AM »
Latest version - extract the exe to a folder that contains images. This one does not attempt to download images.

GuiParas equ "GuiImage demo", w555, h500, bLiteYellow, m5      ; width, height, background colour, margins
include \masm32\MasmBasic\Res\MbGui.asm

GuiControl MyCanvas, "canvas", w800, WS_THICKFRAME
GuiControl MyList, "listbox", x800, w200
GetFiles *.gif|*.jpg|*.png|*.jpeg
SetListbox Files$()

Event CanvasPaint
  MemState("leaked kBytes: %i\n")              ; check if there are leaks
  GuiImage 123, fit                            ; image from resources, ID 123; fit to canvas control size
  GuiImage Files$(LbSel), 50, 180, 360, 240    ; image from disk, pos x, y, w, h
  GuiTextBox 78.0-100, 99.9-55, 80, 32, "Try sizing the window", bcol LiteGreen
GuiEnd

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6718
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: GUI programming with events
« Reply #12 on: March 19, 2019, 12:38:01 PM »
JJ,

Worked OK on my win10 64 pro but it showed a message box with an error about fileread$. The resizing works fine, no flicker and seemed to be fast enough without any lag.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Moderator
  • Member
  • *****
  • Posts: 9747
  • Assembler is fun ;-)
    • MasmBasic
Re: GUI programming with events
« Reply #13 on: March 19, 2019, 06:42:19 PM »
> extract the exe to a folder that contains images

Hutch,
Does the folder contain any images?

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6718
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: GUI programming with events
« Reply #14 on: March 21, 2019, 03:38:38 AM »
No, I did not realise at the time that I should have got the images from the earlier post. The resizing and stretching worked well on my box, very smooth and no flicker.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: