' QWinman - Window manager example programmed by Julien Moog - julien.moog@laposte.net ' This example shows with only a few lines of code, a simple way to use multiple windows ' in the same program without the use of the complicate mdi apis ' it uses array of qforms and the setparent api function ' there are still a few bugs or restrictions : ' - when you want to move a window, you need to click on the window first, ' and then click again on that window and move it ' - qrichedit component must be disabled with enable=0, else you can't move the windows ' i took some portions of code from Jernej Simoncic with his CloseQ custom form with flat close button, thanks to him $apptype gui $typecheck on $include "rapidq2.inc" $include "qtabcontrolex.inc" $RESOURCE CloseUp AS "CLOSE_UP.BMP" $RESOURCE CloseDn AS "CLOSE_DN.BMP" $RESOURCE CloseFl AS "CLOSE_FLAT.BMP" declare sub newchild declare sub tabchange declare sub checkfrmfocusontimer declare sub closechildform DECLARE SUB StartMoveForm (BTN AS INTEGER, X AS INTEGER, Y AS INTEGER) DECLARE SUB MoveForm (X AS INTEGER, Y AS INTEGER) DECLARE SUB EndMoveForm (BTN AS INTEGER, X AS INTEGER, Y AS INTEGER) DECLARE SUB CloseClick DECLARE SUB CloseDown(BTN AS INTEGER, X AS INTEGER, Y AS INTEGER) DECLARE SUB CloseMove(x%, y%) DECLARE SUB CloseLift DECLARE SUB CloseDraw DIM x1% AS INTEGER,x2% AS INTEGER,y1% AS INTEGER,y2% AS INTEGER, Moving as integer, Clse AS INTEGER, Min AS INTEGER DIM CDown(1) AS INTEGER, MDown(1) AS INTEGER, UpOrDown AS INTEGER, i% AS INTEGER defint j=0 dim childnbhandle(0 to 99) as integer dim frmfocustimer as qtimer frmfocustimer.interval=100 frmfocustimer.ontimer=checkfrmfocusontimer dim previoushandlefocus as integer dim publicchildfocusnb as integer dim tabchild(0 to 99) as integer dim mousexdiff as integer dim mouseydiff as integer dim form as qformex form.width = screen.width form.height = screen.height form.caption="QWinman" dim windbut as qbutton windbut.parent=form windbut.top=10 windbut.left=10 windbut.caption="New window" windbut.onclick=newchild dim Tab AS QTabControlex with Tab .parent=form .Width = Form.ClientWidth .Height = Form.ClientHeight-30 .top=30 .OnChange = TabChange .HotTrack = True .visible=0 end with dim Tabshow AS QTabControlex with Tabshow .parent=form .Width = Form.ClientWidth .Height = Form.ClientHeight-30 .top=30 .OnChange = TabChange .HotTrack = True .align=2 end with dim scrollbox As qscrollbox with scrollbox .parent=Tabshow .height=Tabshow.clientheight-30 .top=Tabshow.top .width=Tabshow.clientwidth .align=2 end with dim childform(0 to 99) as qform dim btnExit(0 to 99) AS qcoolbtn dim DragImg(0 to 99) AS qscrollbox dim childbox(0 to 99) as qscrollbox dim childcaption(0 to 99) as qlabel dim childcaptionfont(0 to 99) as qfont dim childrichedit(0 to 99) as qrichedit sub newchild tab.AddTabs str$(j) Tabshow.AddTabs str$(j) childform(j).borderstyle=0 Setparent (childform(j).handle, scrollbox.handle) childform(j).top=10 childform(j).left=20 childform(j).caption="Window "+str$(j) childform(j).onclose=closechildform childnbhandle(j)=childform(j).handle DragImg(j).parent=childform(j) DragImg(j).Left=0 DragImg(j).Top=0 DragImg(j).Width=childform(j).clientwidth+20 DragImg(j).Height=childform(j).clientheight+20 DragImg(j).color=rgb(0,0,144) DragImg(j).OnMouseDown = StartMoveForm DragImg(j).OnMouseMove = MoveForm DragImg(j).OnMouseUp = EndMoveForm childbox(j).parent=DragImg(j) childbox(j).width=DragImg(j).width childbox(j).height=DragImg(j).height-20 childbox(j).top=DragImg(j).top+20 childbox(j).left=DragImg(j).left childbox(j).color=rgb(222,222,222) btnExit(j).parent=DragImg(j) btnExit(j).Top = 3 btnExit(j).Left = childform(j).ClientWidth - 18 btnExit(j).Height = 14 btnExit(j).Width = 15 btnExit(j).BMPhandle = CloseFl btnExit(j).OnMouseDown = CloseDown btnExit(j).OnMouseMove = CloseMove btnExit(j).OnMouseUp = CloseLift btnExit(j).OnClick=CloseClick childcaptionfont(j).name="Arial" childcaptionfont(j).color=rgb(222,222,222) childcaption(j).parent=DragImg(j) childcaption(j).enabled=0 childcaption(j).Top=3 childcaption(j).left=3 childcaption(j).Height=20 childcaption(j).Width=100 childcaption(j).font=childcaptionfont(j) childcaption(j).caption="Window "+str$(j) childrichedit(j).parent=childbox(j) childrichedit(j).enabled=0 childrichedit(j).left=0 childrichedit(j).top=0 childrichedit(j).height=childbox(j).height childrichedit(j).width=childbox(j).width-20 childrichedit(j).text="Welcome to QWinman, a cool window manager programmed by Julien Moog - julien.moog@laposte.net "+chr$(10)+chr$(10) childrichedit(j).text=childrichedit(j).text+"This example shows with only a few lines of code, a simple way to use multiple windows " childrichedit(j).text=childrichedit(j).text+"in the same program without the use of the complicate mdi apis. "+chr$(10)+chr$(10) childrichedit(j).text=childrichedit(j).text+"It uses array of qforms and the setparent api function. "+chr$(10)+chr$(10) childrichedit(j).text=childrichedit(j).text+"There are still a few bugs or restrictions : "+chr$(10)+chr$(10) childrichedit(j).text=childrichedit(j).text+"- when you want to move a window, you need to click on the window first, " childrichedit(j).text=childrichedit(j).text+"and then click again on that window and move it. "+chr$(10) childrichedit(j).text=childrichedit(j).text+"- qrichedit component must be disabled with enable=0, else you can't move the windows"+chr$(10) childform(j).show j++ end sub SUB TabChange tab.tabindex=val(tabshow.tab(tabshow.tabindex)) setfocus childform(tab.tabindex).handle end sub sub checkfrmfocusontimer defint hwnd=getfocus() if hwnd<>previoushandlefocus then previoushandlefocus=hwnd defint i defint j for i=0 to 99 DragImg(i).color=rgb(0,0,144) next i for i=0 to 99 if childnbhandle(i)=hwnd then publicchildfocusnb=i DragImg(i).color=rgb(0,0,200) tab.tabindex=i for j=0 to 99 if tabshow.tab(j)=str$(i) then tabshow.tabindex=j exit for end if next j exit for end if next i end if end sub sub closechildform defint i for i=0 to 99 if tabshow.tab(i)=str$(publicchildfocusnb) then tabshow.deletetabs i exit for end if next i end sub SUB StartMoveForm (BTN AS INTEGER, X AS INTEGER, Y AS INTEGER) If Btn=0 AND Y<20 then x2% = childForm(publicchildfocusnb).Left y2% = childForm(publicchildfocusnb).Top mousexdiff=screen.mousex-x2%+scrollbox.left+form.left mouseydiff=screen.mousey-y2%+tab.top+scrollbox.top+form.top+30 Moving = TRUE End If END SUB SUB MoveForm (X AS INTEGER, Y AS INTEGER) IF Moving = TRUE THEN MoveWindow childForm(publicchildfocusnb).handle,screen.mousex-mousexdiff,screen.mousey-mouseydiff,childForm(publicchildfocusnb).width, childForm(publicchildfocusnb).height, 1 ELSE CDown(0)=0 CloseDraw END IF END SUB SUB EndMoveForm (BTN AS INTEGER, X AS INTEGER, Y AS INTEGER) Moving = FALSE END SUB SUB CloseDown (BTN AS INTEGER, X AS INTEGER, Y AS INTEGER) If BTN = 0 then btnExit(publicchildfocusnb).BMPhandle=CloseDn Clse = True CDown(0)=-1 END IF ENd SUB SUB CloseMove (x%, y%) If Clse = True then if x%>0 and x%<15 then if y%>0 and y%<14 then CDown(0)=-1 else CDown(0)=0 end if else CDown(0)=0 end if else CDown(0)=1 end if CloseDraw ENd SUB SUB CloseLift btnExit(publicchildfocusnb).BMPhandle=CloseFl Clse=0 CDown(0)=False ENd SUB SUB CloseDraw If Cdown(0)<>CDown(1) Then if CDown(0)=-1 then btnExit(publicchildfocusnb).BMPhandle=CloseDn ElseIf CDown(0)=1 then btnExit(publicchildfocusnb).BMPhandle=CloseUp else btnExit(publicchildfocusnb).BMPhandle=CloseFl end if CDown(1)=CDown(0) End If end sub SUB CloseClick childForm(publicchildfocusnb).Close END SUB form.showmodal