IonicWind Software

IWBasic => General Questions => Topic started by: Andy on November 18, 2017, 03:21:57 AM

Title: rgn_button_test does not work as a window
Post by: Andy on November 18, 2017, 03:21:57 AM
Just playing around with images on buttons, I looked at the example code program rgn_button_test.

Now as a Dialog it works, but when I change:

Createdialog to Openwinow
Domodal d1 to waituntil d1 = 0

and finally,
case @idinitdialog to case @idcreate

It doesn't display the bitmaps on the buttons?

CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
CONST BUTTON_3 = 3
CONST BUTTON_4 = 4
CONST BUTTON_5 = 5

window d1
openwindow d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@RGNBUTTON,"Button1",0,0,87,30,0x50000000,BUTTON_1
CONTROL d1,@RGNBUTTON,"Button2",90,0,87,30,0x50000000,BUTTON_2
CONTROL d1,@RGNBUTTON,"Hit Me",0,50,87,30,0x50000000|@CTLBTNDEFAULT|@CTLBTNFLAT,BUTTON_3
CONTROL d1,@RGNBUTTON,"#4",90,50,87,30,0x50000000,BUTTON_4
CONTROL d1,@RGNBUTTON,"Button Five",0,100,87,30,0x50000000,BUTTON_5

waituntil d1 = 0
END

SUB d1_handler
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW d1
/* Initialize any controls here */
'how to share a region between two buttons....
int hrgn = RGNFROMBITMAP(GETSTARTPATH()+"rgn_bmp1.bmp")
'button 1 is a regioned button with automatic hot tracking COLOR
'we use COPYRGN here because we want to apply the same region
'to two buttons
SETCONTROLCOLOR d1,BUTTON_1,RGB(255,255,255),RGB(10,100,128)
SETBUTTONRGN d1,BUTTON_1,COPYRGN(hrgn)
SETHTCOLOR d1,BUTTON_1,RGB(20,138,138)
SETBUTTONBORDER d1,BUTTON_1,0
'button 2 is a regioned button with a bitmap and automatic hot tracking COLOR
'here we just pass the hrgn.  Regions are owned by the button so we needed to make a
'copy of it for the first button.
SETFONT d1,"Arial",14,800,0,BUTTON_2
SETCONTROLCOLOR d1,BUTTON_2,RGB(255,255,255),RGB(10,100,128)
SETBUTTONRGN d1,BUTTON_2,hrgn
SETBUTTONBITMAPS d1,BUTTON_2,LOADIMAGE(GETSTARTPATH()+"button_bmp_normal.bmp",@IMGBITMAP),0,0
SETHTCOLOR d1,BUTTON_2,RGB(80,80,80)

'button 3 is a regioned button with automatic hot tracking COLOR
SETCONTROLCOLOR d1,BUTTON_3,RGB(255,255,255),RGB(10,100,128)
SETBUTTONRGN d1,BUTTON_3,RGNFROMBITMAP(GETSTARTPATH()+"rgn_bmp2.bmp")
SETHTCOLOR d1,BUTTON_3,RGB(20,138,138)
SETBUTTONBORDER d1,BUTTON_3,2

'button 4 is a normal button with 2 bitmaps, 1 for normal and one for hot tracking
SETCONTROLCOLOR d1,BUTTON_4,RGB(200,200,200),RGB(10,100,128)
SETBUTTONBITMAPS d1,BUTTON_4,LOADIMAGE(GETSTARTPATH()+"button_bmp_normal2.bmp",@IMGBITMAP),LOADIMAGE(GETSTARTPATH()+"button_bmp_hot2.bmp",@IMGBITMAP),0
'button 5 is just a normal button, no hot tracking
CASE @IDCLOSEWINDOW
CLOSEWINDOW d1
         end

CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
/*button clicked*/
ENDIF
ENDSELECT
ENDSELECT
RETURN 0
ENDSUB


Am I doing something wrong here, or does it have to be a dialog screen?

Thanks,
Andy.
 

Title: Re: rgn_button_test does not work as a window
Post by: Brian on November 18, 2017, 04:03:02 AM
Andy,

This one works for me - you should be able to modify it what you require

Brian
Title: Re: rgn_button_test does not work as a window
Post by: Andy on November 18, 2017, 04:43:05 AM
Brian,

Thanks for that, I stopped the timer and managed to load a button (button 4) with the bitmap and hot tracking.

I didn't understand the region part.


UINT hrgn = RGNFROMBITMAP(GETSTARTPATH+"rgn.bmp")
SETCONTROLCOLOR w1,1027,RGB(255,255,255),RGB(10,100,128)
SETBUTTONRGN w1,1027,COPYRGN(hrgn)


The only thing is rgn.bmp does not exist in the folder I'm compiling the code from?

Andy.
Title: Re: rgn_button_test does not work as a window
Post by: Brian on November 18, 2017, 04:50:55 AM
Andy,

I just copied rgn_bmp1.bmp to rgn.bmp, and made sure it was in the same folder as the program

Brian
Title: Re: rgn_button_test does not work as a window
Post by: Andy on November 18, 2017, 04:56:50 AM
Still puzzled!

I even tried to open the non existent rng.bmp and print the results on screen.

See attached compile output and listing of bitmaps.

Title: Re: rgn_button_test does not work as a window
Post by: Brian on November 18, 2017, 06:23:06 AM
Is it because you have called it rng.bmp when it should be rgn.bmp?

Brian
Title: Re: rgn_button_test does not work as a window
Post by: Andy on November 18, 2017, 11:30:38 PM
No Brian that was just a typing error.

file f1
if openfile(f1,getstartpath + "rgn.bmp","R") = 1
move w1,10,40
print w1,"rng.bmp does not exist."
endif


Still puzzled at this.
Title: Re: rgn_button_test does not work as a window
Post by: LarryMc on November 19, 2017, 12:17:38 AM
take all the code out of the @IDCREATE section except centerwindow
and paste it right after the control block of statements (before your waituntil and it will work fine

your welcome ;)
Title: Re: rgn_button_test does not work as a window
Post by: Andy on November 19, 2017, 12:22:55 AM
Thanks Larry  ;) that works.
Title: Re: rgn_button_test does not work as a window
Post by: Egil on November 19, 2017, 03:57:31 AM
Quotetake all the code out of the @IDCREATE section except centerwindow
and paste it right after the control block of statements (before your waituntil and it will work fine

You can also put the mentioned definitions in a subroutine and call that sub just before the waituntil.


Egil


CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
CONST BUTTON_3 = 3
CONST BUTTON_4 = 4
CONST BUTTON_5 = 5

window d1
openwindow d1,0,0,300,202,0x80C80080,0,"Caption",&d1_handler
CONTROL d1,@RGNBUTTON,"Button1",0,0,87,30,0x50000000,BUTTON_1
CONTROL d1,@RGNBUTTON,"Button2",90,0,87,30,0x50000000,BUTTON_2
CONTROL d1,@RGNBUTTON,"Hit Me",0,50,87,30,0x50000000|@CTLBTNDEFAULT|@CTLBTNFLAT,BUTTON_3
CONTROL d1,@RGNBUTTON,"#4",90,50,87,30,0x50000000,BUTTON_4
CONTROL d1,@RGNBUTTON,"Button Five",0,100,87,30,0x50000000,BUTTON_5

/* Initialize any controls here */

BtnSetUp()

waituntil d1 = 0
END

SUB d1_handler(),int
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW d1

CASE @IDCLOSEWINDOW
CLOSEWINDOW d1
         end

CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
/*button clicked*/
ENDIF
ENDSELECT
ENDSELECT
RETURN 0
ENDSUB

sub BtnSetUp()
'how to share a region between two buttons....
int hrgn = RGNFROMBITMAP(GETSTARTPATH()+"rgn_bmp1.bmp")
'button 1 is a regioned button with automatic hot tracking COLOR
'we use COPYRGN here because we want to apply the same region
'to two buttons
SETCONTROLCOLOR d1,BUTTON_1,RGB(255,255,255),RGB(10,100,128)
SETBUTTONRGN d1,BUTTON_1,COPYRGN(hrgn)
SETHTCOLOR d1,BUTTON_1,RGB(20,138,138)
SETBUTTONBORDER d1,BUTTON_1,0
'button 2 is a regioned button with a bitmap and automatic hot tracking COLOR
'here we just pass the hrgn.  Regions are owned by the button so we needed to make a
'copy of it for the first button.
SETFONT d1,"Arial",14,800,0,BUTTON_2
SETCONTROLCOLOR d1,BUTTON_2,RGB(255,255,255),RGB(10,100,128)
SETBUTTONRGN d1,BUTTON_2,hrgn
SETBUTTONBITMAPS d1,BUTTON_2,LOADIMAGE(GETSTARTPATH()+"button_bmp_normal.bmp",@IMGBITMAP),0,0
SETHTCOLOR d1,BUTTON_2,RGB(80,80,80)

'button 3 is a regioned button with automatic hot tracking COLOR
SETCONTROLCOLOR d1,BUTTON_3,RGB(255,255,255),RGB(10,100,128)
SETBUTTONRGN d1,BUTTON_3,RGNFROMBITMAP(GETSTARTPATH()+"rgn_bmp2.bmp")
SETHTCOLOR d1,BUTTON_3,RGB(20,138,138)
SETBUTTONBORDER d1,BUTTON_3,2

'button 4 is a normal button with 2 bitmaps, 1 for normal and one for hot tracking
SETCONTROLCOLOR d1,BUTTON_4,RGB(200,200,200),RGB(10,100,128)
SETBUTTONBITMAPS d1,BUTTON_4,LOADIMAGE(GETSTARTPATH()+"button_bmp_normal2.bmp",@IMGBITMAP),LOADIMAGE(GETSTARTPATH()+"button_bmp_hot2.bmp",@IMGBITMAP),0
'button 5 is just a normal button, no hot tracking
endsub

Title: Re: rgn_button_test does not work as a window
Post by: Andy on November 19, 2017, 04:11:36 AM
Thanks Egil  :)

Good suggestion, and every one of them very welcome!

Andy.