April 24, 2024, 09:35:12 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


rgn_button_test does not work as a window

Started by Andy, November 18, 2017, 03:21:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

November 18, 2017, 03:21:57 AM Last Edit: November 18, 2017, 03:24:01 AM by Andy
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.
 

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

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

Brian

Andy

November 18, 2017, 04:43:05 AM #2 Last Edit: November 18, 2017, 04:50:06 AM by Andy
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.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

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

Brian

Andy

November 18, 2017, 04:56:50 AM #4 Last Edit: November 18, 2017, 05:21:06 AM by Andy
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.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Is it because you have called it rng.bmp when it should be rgn.bmp?

Brian

Andy

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.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

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 ;)
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

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

Support Amateur Radio  -  Have a ham  for dinner!

Andy

Thanks Egil  :)

Good suggestion, and every one of them very welcome!

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.