April 30, 2024, 06:10:31 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


window within a window

Started by TexasPete, July 20, 2009, 04:15:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TexasPete

I am learning about the window and dialog relationships in CB. I am working on crossing  a Liberty basic program to cb.
In Liberty basic I have a window  and a graphic box to draw in. In CB , I assume I would use a window and a dialog  or should I use a window with a "@midframe" and another window to get the equivilent graphic box.
Any suggest would be appreciated.

Texas Pete

ZeroDog

July 20, 2009, 04:49:18 PM #1 Last Edit: July 20, 2009, 04:51:33 PM by ZeroDog
what does the graphic box have in it?   If you just want to draw stuff in the window you can do that directly into the window.  If you want to have a window within a window that you can drag around, you can just set the parent flag of the openwindow function for the second window to that of the first window.  You could try making the first window an MDI window as well and see how it functions.

Usually I only use dialog boxes when I have something like an option window.

ZeroDog

July 20, 2009, 05:07:21 PM #2 Last Edit: July 20, 2009, 11:13:50 PM by ZeroDog
heres a couple samples to show the different types of window within window drawing.

This one draws straight to the window:
def win:window

window win, 0,0,300,300, @CAPTION, 0, "draw directly to window", winproc

circle win,150,150,100, rgb(255,0,0),rgb(0,0,255)

run=1
waituntil run=0
closewindow win
end

sub winproc
if @CLASS = @IDCLOSEWINDOW then run=0
return



This one draws into a window that is created within the first window, and has a caption so you can drag it around:
def win,win2:window

window win, 0,0,300,300, @CAPTION, 0, "draw to window 2", winproc
window win2, 50,50,200,200, @CAPTION, win, "window 2", winproc

circle win2,150,150,100, rgb(255,0,0),rgb(0,0,255)

run=1
waituntil run=0
closewindow win
end

sub winproc
if @CLASS = @IDCLOSEWINDOW then run=0
return



This one has a captionless window within a window:
def win,win2:window

window win, 0,0,300,300, @CAPTION, 0, "draw to no caption window", winproc
window win2, 50,50,200,200, @NOCAPTION, win, "No Caption", winproc

setwindowcolor win,rgb(255,0,0)
circle win2,150,150,100, rgb(255,0,0),rgb(0,0,255)

run=1
waituntil run=0
closewindow win
end

sub winproc
if @CLASS = @IDCLOSEWINDOW then run=0
return


This one draws in an MDI child frame:
def win,win2,win3:window

window win, 0,0,300,300, @CAPTION|@MDIFRAME|@SIZE, 0, "draw to MDI child", winproc
window win2, 50,50,200,200, @CAPTION, win, "Child", winproc
window win3, 0,0,200,200, @CAPTION, win, "Child 2", winproc

circle win2,150,150,100, rgb(255,0,0),rgb(0,0,255)

run=1
waituntil run=0
closewindow win
end

sub winproc
if @CLASS = @IDCLOSEWINDOW then run=0
return



aurelCB

TexasPete graphic box in Liberty is some kind of child window placed inside parent window.
So this is ordinary child window.
But maby there is something like child window inside dialog - im not quite sure.

see code:

' child window
def win:window
def graphicbox:window
'parent win
Window win,0,0,400,300,@minbox,0,"ChildWin",main
setwindowcolor win,rgb(230,230,235)
'child win
Window graphicbox,50,50,200,100,@border|@nocaption,win,"Child",main
Move graphicbox,10,10:Print graphicbox,"GraphicBox Window"


Waituntil win=0
END

SUB main
select @class
case @IDclosewindow
closewindow win
case @idcreate
centerwindow win
endselect
RETURN

ZeroDog

July 20, 2009, 11:06:24 PM #4 Last Edit: July 20, 2009, 11:14:22 PM by ZeroDog
oooh, i was in the wrong forum location, and posted code for EBasic, not CBasic...  :-[

Im changing it now...  ::)
...'k its changed now.

GWS

Yep .. all the LB stuff about 'delsegment, discard and flush' commands .. and running out of memory if you keep drawing and flushing .. do not apply in Creative Basic.

Once you have a normal window, you can draw whatever you want to it.  Try the 'lines' sample program for example.  Your machine won't run out of memory, however many lines it draws.

Of course, if you want to play with 2D sprites and 3D, you will need a DirectX window - which is 'flipping' different. ;D

best wishes, :)

Graham
Tomorrow may be too late ..

TexasPete

fELLAS , I see all the examples and I am thinking about them. It seems that it should be easy to do. But right off the bat I defined to windows and creative is giving me an error. below is my sample code.' Demonstrating how easy it is to create a window in Creative Basic
' also includes a Text Box control to display some text ..
'---------------------------------------
def main1:window
def main2:window
'def GraphicBox:window
def wstyle1:int
DEF wstyle2:int

def a$,newline:string

wstyle1 = @SIZE|@MINBOX|@MDIFRAME
wstyle2 = @NOCAPTION|@BORDER|@HSCROLL|@VSCROLL

newline = chr$(10)
window main1,0,0,600,800,wstyle,0,"Main Window Basic",main1
setwindowcolor main1,rgb(0,0,40)
centerwindow main1
'----second window-----------
window main2,0,30,300,400,wstyle2,0,"Main Window Basic",main2:setwindowcolor main2,rgb(200,0,40):centerwindow main2
'----end second window

control main1,"T,,100,30,400,300,@cteditcenter,1"
setcontrolcolor main1,1,rgb(55,255,160),rgb(0,0,50)
rect main1,99,29,402,302,rgb(0,150,150)

a$ = string$(3,newline) + "A Simple" + newline + "Creative Window"
setfont main1,"Arial", 20, 700, @SFITALIC,1

setcontroltext main1,1,a$

waituntil main1 = 0
END
SUB main
    IF @CLASS = @IDCLOSEWINDOW
        REM closes the window and sets w1 = 0
        CLOSEWINDOW main1
    ENDIF
RETURN
SUB main2
    IF @CLASS = @IDCLOSEWINDOW
        REM closes the window and sets w1 = 0
        CLOSEWINDOW main2
    ENDIF
RETURN
'--------------------------------------------

Creative does not want to recognize the second window,

Aurel  I looked and your example and I think I am doing the right thing.  It gives an error on the second window. on line 4

LarryMc

You named your WINDOW variables main1 and main2

the you named the handler for window main2 also main2

so you have a WINDOW and a SUBROUTINE with the same name.

Also you don't have the parent of main2 named as main1.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

also you have wstyle1 defined but you use wstyle which isn't defined.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

ZeroDog

heh.  You're close.  You just have a few typos and such that are clobbering your program.  Larry has pointed out a few.
But, I did notice one thing tho.  You're using and MDI frame for the main window.  Theres nothing wrong with that as such, but, MDI frames are special windows.  They are used for things such as editors and such.  Yuo arent really supposed to draw directly into an MDI frame itself, as it doesnt re-paint itself automatically like other windows.  You can do it, but, it takes alot more workarounds to keep your graphic painted onto an MDI frame directly.  You dont need to use an MDI frame just to have multiple windows.  You can do it with a regular window.  MDI's are special, and should only be used when needed.

Heres your program back, with a few changes and typos fixed to make it run, and I removed the MDI Frame as well:

'---------------------------------------
def win1:window
def win2:window
'def GraphicBox:window
def wstyle1:int
DEF wstyle2:int

def a$,newline:string

wstyle1 = @SIZE|@MINBOX
wstyle2 = @NOCAPTION|@BORDER|@HSCROLL|@VSCROLL

newline = chr$(10)
window win1,0,0,600,800,wstyle1,0,"Main Window Basic",main1
setwindowcolor win1,rgb(0,0,40)
centerwindow win1
'----second window-----------
window win2,0,30,300,400,wstyle2,win1,"Main Window Basic",main2
setwindowcolor win2,rgb(200,0,40):centerwindow win2
'----end second window

control win1,"T,,100,30,400,300,@cteditcenter,1"
setcontrolcolor win1,1,rgb(55,255,160),rgb(0,0,50)
rect win1,99,29,402,302,rgb(0,150,150)

a$ = string$(3,newline) + "A Simple" + newline + "Creative Window"
setfont win1,"Arial", 20, 700, @SFITALIC,1

setcontroltext win1,1,a$

waituntil win1 = 0
END
SUB main1
    IF @CLASS = @IDCLOSEWINDOW
        REM closes the window and sets w1 = 0
        CLOSEWINDOW win1
    ENDIF
RETURN
SUB main2
    IF @CLASS = @IDCLOSEWINDOW
        REM closes the window and sets w1 = 0
        CLOSEWINDOW win2
    ENDIF
RETURN
'--------------------------------------------



TexasPete

Boy , you guys are just great! That help's me pick it up so much easier. I will play with it some more and go over each mistake To make sure I have it down.
Thanks
Texas Pete

aurelCB

Ah i see .Zero you create child window with it own handler main2.
But from what i know in LB he use graphicbox as child window to .
Becose of that i called child window graphicbox.
Of course child window with his own handler have purpose in some situation.
I hope that will help to Texas Man.

TexasPete

Aurel, in LB there is a graphic glich bug. After you schroll down so far the glich messes up the screen.
Do you know if that graphic glich exists in CB. I was told it was in the windows api.
If it does exist what is the fix for it in CB.
Texas Pete

aurelCB

July 22, 2009, 12:35:22 PM #13 Last Edit: July 23, 2009, 01:57:27 AM by aurelCB
TPete JB/LB is full of bugs something like that about you talkig.
Man dont get me wrong i study very well code of JB/LB
My own language is superior to JB/LB code sorry but that is 'true' ;D
Of course i'm jokin in one part ::)

TexasPete

aurel, I believe you. I have had to come up with many work arounds while using the language. Creative appears to be far superior to lb . I personally wish I had written my code in cb first. Rewriting 5,000 lines of code is no fun.
Trying to become familiar with cb enought to get the job done will take some time.
Thanks for all your help.

ZeroDog

QuoteAfter you schroll down so far the glich messes up the screen.
Do you know if that graphic glich exists in CB. I was told it was in the windows api.

If you come across this while programming in CB just post your code here and I'll be happy to help.  I've had to deal with things like this in the past, but, its all workable.  One method is to scroll the contents of the window instead of the window itself.

aurelCB

5000 lines :o
for i supose "Chicken Little" - right?