News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

GUI programming with events

Started by jj2007, February 25, 2019, 11:07:31 AM

Previous topic - Next topic

jj2007

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:
#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

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

Thanks, Marinus. The stretching behaviour is by design, only the "fit" forces adjusting the size.

guga

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

Equations in Assembly: SmplMath

jj2007

Quote from: guga on February 26, 2019, 01:23:51 AMAnd, 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

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

Thanks, Guga. I have no idea what's happening. Can you please test the attached debug version?

LordAdef

NICE JJ!
I used to first version, without any issue

guga

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

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

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--

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.

jj2007

> extract the exe to a folder that contains images

Hutch,
Does the folder contain any images?

hutch--

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.