UBBFriend: Email This Page to Someone!
  Computer Workshop User Forums
  EZGUI Source code
  Fun with Regions

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   Fun with Regions
Chris Boss
Administrator
posted 05-01-2009 12:55 AM     Click Here to See the Profile for Chris Boss     Edit/Delete Message Reply w/Quote
Here is an example where EZGUI generates a region for a Canvas control based on its image and then I use the API to copy that region and use it with EZ_SetRegion to make another control have the same shape.

This creates a sort of shadow effect underneath the Canvas using a label control.

code:



' *************************************************************************************
' Portions: Copyright Christoper R. Boss, 2003 to 2006
' All Rights Reserved !
' Registered EZGUI 4.0 users may use this code Royalty Free !
' *************************************************************************************
#COMPILE EXE
#DIM ALL ' This is helpful to prevent errors in coding
#INCLUDE "win32api.inc"
' --------------------
#INCLUDE "..\includes\ezgui40.inc" ' EZGUI Include file for Declares
' --------------------
' *************************************************************************************

' *************************************************************************************
' Application Constants and Declares
' *************************************************************************************
DECLARE SUB Form1_Display(BYVAL Parent$)
DECLARE SUB Form1_Design()
DECLARE SUB Form1_Events(CID&, CMsg&, CVal&, Cancel&)
' ------------------------------------------------

%FORM1_CANVAS1 = 100
%FORM1_BUTTON1 = 105
%FORM1_LABEL1 = 110
' ------------------------------------------------

DECLARE SUB FORM1_CANVAS1_Draw(BYVAL Mode&)
DECLARE SUB FORM1_CANVAS1_Click()
DECLARE SUB FORM1_BUTTON1_Click()

' *************************************************************************************
' Application Global Variables and Types
' *************************************************************************************

' Note: Do NOT change the names of the EZGUI Callback Procedures !

' --------------------
#INCLUDE "..\includes\ezwmain.inc" ' EZGUI Include file for WinMain
' --------------------
' *************************************************************************************
' EZGUI Program Control Functions
' *************************************************************************************

SUB EZ_Main(VerNum&)
RANDOMIZE
EZ_LoadPatternLib "", ""
Form1_Display ""
END SUB

' -------------------------------------------------------------------------------------

SUB EZ_DesignWindow(FormName$)
' - NOTE: EZGUI passes back Form Name in uppercase letters
SELECT CASE FormName$
CASE "FORM1"
Form1_Design
CASE ELSE
END SELECT
END SUB

' -------------------------------------------------------------------------------------

SUB EZ_Events(FormName$, CID&, CMsg&, CVal&, Cancel&)
' - NOTE: EZGUI passes back Form Name in uppercase letters
SELECT CASE FormName$
CASE "FORM1"
Form1_Events CID&, CMsg&, CVal&, Cancel&
CASE ELSE
END SELECT
END SUB

' -------------------------------------------------------------------------------------


' *************************************************************************************
' Put Your Code Here
' *************************************************************************************

SUB Form1_Display(BYVAL Parent$)
EZ_Color 0, -22
EZ_Form "FORM1", Parent$, "Your Dialog", 0, 0, 50, 18, "CK"
END SUB
' ------------------------------------------------

GLOBAL Form1_FF&

SUB Form1_Design()
LOCAL FF&
'---------------------------------------------------------------
FF& = 9 ' - Offset for Font Numbers
Form1_FF& = FF& ' Global for ODButtons Draw code
'---------------------------------------------------------------
EZ_Color 0, 15
EZ_DefFont FF&+1, "MS Sans Serif", 8, "V"
EZ_UseFont FF&+1

EZ_Canvas %FORM1_CANVAS1, 0, 3, 26, 11, ""
EZ_Color 0, 0
EZ_Label %FORM1_LABEL1, 1,3.5, 26, 11, "", ""
FORM1_CANVAS1_Draw -1
' --------------------------------------------------------------
EZ_Color-1,-1
EZ_UseFont FF&+1
EZ_Button %FORM1_BUTTON1, 5, 2, 40, 14, "Change", "T"
' --------------------------------------------------------------
END SUB
' ------------------------------------------------

SUB Form1_Events(CID&, CMsg&, CVal&, Cancel&)
SELECT CASE CID&
CASE %EZ_Window
IF CMsg&=%EZ_Close THEN
END IF
CASE %FORM1_CANVAS1
IF CMsg&=%EZ_Click THEN
FORM1_CANVAS1_Click
END IF
CASE %FORM1_BUTTON1
IF CMsg&=%EZ_Click THEN
FORM1_BUTTON1_Click
END IF
CASE ELSE
END SELECT
END SUB
' ------------------------------------------------


' ------------------------------------------------

FUNCTION GetCanvasRegion(BYVAL FormName$, BYVAL ID&) AS LONG
LOCAL hWnd&, hRgn&
hWnd&=EZ_Handle(FormName$, ID&)
IF hWnd&<>0 THEN
hRgn&=CreateRectRgn(0,0,0,0)
IF GetWindowRgn(hWnd&, hRgn&)<>0 THEN
FUNCTION=hRgn&
END IF
END IF
END FUNCTION

SUB FORM1_CANVAS1_Draw(BYVAL Mode&)
LOCAL AFG&, ABG&, AFnt&, CW&, CH&
LOCAL LN&, H1&, H2&
LOCAL LP&, FG&, BG&
LOCAL Y1&, Y2&, X1&, X2&, Offset&
AFG&=EZ_FG
ABG&=EZ_BG
AFnt&=EZ_Font
IF Mode&=-1 THEN ' Initial Data
CW&=800 ' emulate 8 inches by .01 inch units
CH&=1050 ' emulate 10.5 inches by .01 inch units
EZ_GetCanvasSize "Form1",%FORM1_CANVAS1, CW&, CH&
EZ_StartDraw "Form1", %FORM1_CANVAS1, CW&, CH&, ""
EZ_Color 0,15
EZ_CDraw %EZ_FILL,0,0, CW&-1, CH&-1,1,1
Offset&=RND(0,CH&/20)
H1&=((CH&/105)*10)+Offset&
LN&=INT((CH&/H1&)/2)
Offset&=RND(0,CW&/8)
X1&=(CW&/4)+Offset&
X2&=CW&-(CW&/4)
Y1&=INT(H1&/2)
FOR LP&=1 TO LN&
FG&=LP& MOD 15
BG&=31-LP&
EZ_Color 0, BG&
Y2&=Y1&+H1&
EZ_CDrawGradient X1&, Y1&, X2&, Y2&, 6
Y1&=Y1&+H1&+H1&
NEXT LP&
EZ_EndDraw
EZ_SetRegion "Form1",%FORM1_CANVAS1,0, EZ_ColorVal(15,0)
EZ_SetRegion "Form1", %FORM1_LABEL1 , 3, GetCanvasRegion("Form1",%FORM1_CANVAS1)
END IF
EZ_Color AFG&, ABG&
EZ_UseFont AFnt&
END SUB

' ------------------------------------------------

SUB FORM1_CANVAS1_Click()

END SUB

' ------------------------------------------------

SUB FORM1_BUTTON1_Click()
FORM1_CANVAS1_Draw -1
EZ_RedrawForm "Form1"
END SUB


All times are EST (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | Computer Workshop ( EZGUI ) Home Page

Copyright 2000 to 2007 Christopher R. Boss

Powered by: Ultimate Bulletin Board, Version 5.44
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 2000.