|
- Written and documented by David Deley
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12.1:
12.2:
12.3:
12.4:
Introduction to CMac Chapter 12.2: DIALOG BOXES: The X & Y Coordinates
(Note: Attached below is a file with the two sample code files shown here.)
DlgAddCtrl asks for the X and Y coordinates of the element (control) you wish to add.
| Code: |
int DlgAddCtrl(
int dlg the dialog handle create with DlgCreate
int ctrltype the control type (defined in Dialog.sh)
str ctrltitle the control title
int X the X coordinate
int Y the Y coordinate
int width the width of the control
int height the height of the control
int ctrlid the identifying number for the control
int flags miscellaneous flags (defined in Dialog.sh)
str misc miscellaneous parameters
)
|
The origin for the X and Y coordinates is the upper left corner of the
dialog box. The X coordinate goes across to the right, and the Y
coordinate goes down. The X coordinate unit is slightly less than the
width of a character, and the Y coordinate unit is the distance from
one line to the next.
The X and Y parameters of the DlgAddCtrl macro are interpreted as a
combination of flags and a number. The lower 16 bits represent an
unsigned word (0 - 65535), and the upper 16 bits represent flags. The
flags available are:
| Code: |
(defined in Dialog.sh)
#define dlg_PosOffset 0x00010000
#define dlg_NegOffset 0x00020000
#define dlg_Units 0x00040000
|
There are two ways to combine a number with these flags. You can either use '|' or '+'.
(dlg_PosOffset | 10) is the same as (dlg_PosOffset + 10)
(dlg_NegOffset | 12) is the same as (dlg_NegOffset + 12)
Note: Do not use a negative number!
Do not do (dlg_PosOffset - 12).
The usage of dlg_PosOffset and dlg_NegOffset is discussed in Chapter 6 of the CMAC User Guide (pg. 55).
Here is the code that produced the above dialog box. (Note:
DlgAddCtrl also asks for the width and height of the element you are
adding. In the following examples we use (0,0) for the width and
height, and let Multi-Edit come up with appropriate values for the
width and height. This isn't guaranteed to work, but it often does
work.)
| Code: |
#include dialog.sh
void MyXandYDlg()
{
int Dlg, Result;
DlgCreate( Dlg );
DlgAddCtrl( Dlg, Dlg_Static,
'mmmmvmmmm1mmmmvmmmm2mmmmvmmmm3'+
'mmmmvmmmm4mmmmvmmmm50mmmvmmmm6mmmmvm',
1, 1,
//coordinates X, Y
100, 1,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y=2',
1, dlg_PosOffset | 1, //coordinates X, Y
0, 0,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y=3',
1, dlg_PosOffset | 1, //coordinates X, Y
0, 0,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y=4',
1, dlg_PosOffset | 1, //coordinates X, Y
0, 0,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y=5',
1, dlg_PosOffset | 1, //coordinates X, Y
0, 0,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y=6',
1, dlg_PosOffset | 1, //coordinates X, Y
0, 0,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y=7',
1, dlg_PosOffset | 1, //coordinates X, Y
0, 0,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y=8',
1, dlg_PosOffset | 1, //coordinates X, Y
0, 0,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y=9',
1, dlg_PosOffset | 1, //coordinates X, Y
0, 0,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y=10',
1, dlg_PosOffset | 1, //coordinates X, Y
0, 0,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static,
'String above has width=100 (string has 66 characters)',
24, 2,
//coordinates X, Y
0,
0,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'x',
100, 10,
//coordinates X, Y
0,
0,
//Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static,
" Coordinates of 'x' in corner are (X=100,Y=10) ---->",
36, 10, //coordinates X, Y
0, 0, //Width, Height
-1, 0, "" );
Result = DlgExecute( Dlg, -1, "X and Y coordinates",
"",
"",
0 );
MAKE_MESSAGE("Result="+str(result));
DlgKill( Dlg );
}
|
You can get finer positioning control by switching to Dialog Units.
Add the dlg_Units flag to indicate you want to use Dialog Units instead
of the default units. Here is the same dialog box, this time showing
the X and Y values in Dialog Units.
(A default X unit equals 4 Dialog Units, and a default Y unit
equals 12 Dialog Units. Dialog Units are what Microsoft Windows uses
when it constructs a dialog box. Multi-Edit's DlgAddCtrl macro converts
default X and Y units to Dialog Units. If the dlg_Units flag is
present, no conversion is performed.)
Here is the code that produced the above dialog box:
| Code: |
#include dialog.sh
void MyXandYDlgUnits()
{
int Dlg, Result;
DlgCreate( Dlg );
DlgAddCtrl( Dlg, Dlg_Static,
'mmmmvmmmm1mmmmvmmmm2mmmmvmmmm3'+
'mmmmvmmmm4mmmmvmmmm50mmmvmmmm6mmmmvm',
dlg_Units | 1, dlg_Units | 1, //coordinates X, Y
dlg_Units | 400, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y = 12 dlg_Units',
dlg_Units | 1, dlg_Units | dlg_PosOffset | 12, //X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y = 24 dlg_Units',
dlg_Units | 1, dlg_Units | dlg_PosOffset | 12, //X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y = 36 dlg_Units',
dlg_Units | 1, dlg_Units | dlg_PosOffset | 12, //X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y = 48 dlg_Units',
dlg_Units | 1, dlg_Units | dlg_PosOffset | 12, //X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y = 60 dlg_Units',
dlg_Units | 1, dlg_Units | dlg_PosOffset | 12, //X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y = 72 dlg_Units',
dlg_Units | 1, dlg_Units | dlg_PosOffset | 12, //X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y = 84 dlg_Units',
dlg_Units | 1, dlg_Units | dlg_PosOffset | 12, //X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y = 96 dlg_Units',
dlg_Units | 1, dlg_Units | dlg_PosOffset | 12, //X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'Y = 108 dlg_Units',
dlg_Units | 1, dlg_Units | dlg_PosOffset | 12, //X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, "Y = 120 dlg_Units.",
dlg_Units | 1, dlg_Units | dlg_PosOffset | 12, //X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static,
'String above has width=400 dlg_Units '+
'(string has 66 characters)',
dlg_Units | 100, dlg_Units | 12, //coordinates X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static, 'x',
dlg_Units | 400, dlg_Units | 120, //coordinates X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
DlgAddCtrl( Dlg, Dlg_Static,
"Coordinates of 'x' in corner are (X=400,Y=120) " +
"dlg_Units ---->",
dlg_Units | 132, dlg_Units | 120, //coordinates X, Y
dlg_Units | 0, dlg_Units | 0, //Width, Height
-1, 0, "" );
Result = DlgExecute( Dlg, -1, "X and Y dlg_Units coordinates",
"",
"",
0 );
MAKE_MESSAGE("Result="+str(result));
DlgKill( Dlg );
}
|
(Andy Colson won first place for his Dialog Builder
program. It's a GUI program which helps you create a Multi-Edit dialog
box. We may see it in the next major release of Multi-Edit.)
Related Articles:
Introduction to CMAC 12.1 DIALOG BOXES: The Elements
Introduction to CMAC 12.2 DIALOG BOXES: The Coordinates
Introduction to CMAC 12.3 DIALOG BOXES: Sample Code For Each Control
Introduction to CMAC 12.4 DIALOG BOXES: DlgExecute {under construction}
(Edits to this
Introduction to CMAC series are occasionally made as I learn more.) |