Hi,
Has anyone got a foolproof way of printing a Round Rectangle to the screen? I can't get my head round
the x and y's, and my attempts are going all over the place. It never lands in my window where I
expect it to be!
Brian
here's some code I use where I print multiple to a single window
int hd=gethdc(win_code)
frontpen(win_code,rgb(255,0,0))
GETCLIENTSIZE win_code, l, t, w, h
uint hbrush = CreateSolidBrush(0xA0F7F6)
uint ohbr = SelectObject(hd,hbrush )
RoundRect(hd, 0, 0, 182, 241, 20, 20)
RoundRect(hd, 0, 246, 182, h, 20, 20)
RoundRect(hd, 187, 0, w, h, 20, 20)
SelectObject(hd,ohbr)
deleteObject(hbrush)
releasehdc win_code,hd
the 1st 4 numbers of RoundRect after the hd are just the regular corners of the rectangle (upper left and lower right corners) which is different than what is used in OPENWINDOW and CONTROL and the last 2 numbers are width and height of elipse(20,20) numbers the same give you a circle
Hope that helps
Good man! Couldn't get my head round which number went where!
Brian
Hi Brian,
Unfortunately I saw your post a little late, and I see that LarryMc has given you solid advice (as always!).
But I could not resist posting a little snippet originally written in CB. The only difference between the two languages is that an ENDSUB is added to the end of the subroutine.
This clearly demonstrates the main reason for me to use CB when exploring new ideas and converting the code to IWB (if needed) when the code has become acceptable..... ;)
Egil
'
' roundedbox.iwb
'
AutoDefine "Off"
$include "windowssdk.inc"
DECLARE gcBox(x:int,y:int,w:int,h:int,msg$:string,boxcolor:int,labelcolor:int)
def win:window
def run,wstyle:int
wstyle = @minbox|@maxbox|@size
' Create a window ..
OpenWindow win,0,0,800,600,wstyle,0," IWB Test Window",&messages
drawmode win,@TRANSPARENT
setwindowcolor win, rgb(100,250,250)
gcBox(25,30,175,100," gcBox1 ",RGB(96,192,240),RGB(255,255,128))
gcBox(210,150,175,60," gcBox2 ",RGB(192,192,240),RGB(255,128,128))
gcBox(250,30,175,30," gcBox3 ",RGB(148,201,201),RGB(204,204,152))
SETFONT win, "Comic Sans MS", 24, 700, @SFITALIC
gcBox(50,240,475,150," Creative Basic rules! ",RGB(255,222,186),RGB(196,255,0))
' Box whitout label (just pass an ampty string instead of label text)
gcBox(100,440,175,100,"",RGB(255,222,186),RGB(196,255,0))
run = 1
WAITUNTIL run = 0
CLOSEWINDOW win
END
'
' Main loop
'-------------------------------------------------------------------------------------
SUB messages(),int
SELECT @class
CASE @idcreate
centerwindow win
CASE @idclosewindow
run = 0
ENDSELECT
RETURN 0
EndSub
'-------------------------------------------------------------------------------------
'
SUB gcBox(x:int,y:int,w:int,h:int,msg$:string,boxcolor:int,labelcolor:int)
'------------------------------------------------------------------------
' Draw colored box with rounded corners
' Adds self dimensioning text labels with border if label text is supplied
'
' Parameters:
' x, y: Upper left corner of rounded box
' h: Box height
' w: Box with
' msg$: Label text string - use "" if no label
' boxcolor: Box fill color
'labelcolor:
'
' Note: To change radius of the rounded corners, change the values
' of the last two parameters in the RoundRect call to suit
' your needs.
'------------------------------------------------------------------------
'
def hdc:int
def textwidth,textheight:int
hdc = GetHDC win
RoundRect(hdc, x,y, x+w, y+h, 9, 9) :' draw rounded box
RELEASEHDC(win,hdc)
FLOODFILL win, x+(w/2), y+(h/2), boxcolor :' background colour
if msg$ <> "" :' text label exists?
GETTEXTSIZE win, msg$, textwidth, textheight :' label dimensions
hdc = GetHDC win
RoundRect(hdc, x+12,y-2-(textheight/2), (x+12+(textwidth)), y-2+(textheight/2)+2, 5, 7) :' draw label border
RELEASEHDC(win,hdc)
FLOODFILL win, x+14, y,labelcolor :' text label background colour
move win, x+12,y-2-(textheight/2) :' positioning text label
print win, msg$ :' printing text label
endif
RETURN
ENDSUB