Page 1
Page 2
Page 3
Page 4
A futuristic view: you go to a pizza
place. You see all the tables have a WinCE device with this
application running. You fill it up, it signals the central
database with your requirements and the pizza is delivered
to your table. Just a thought. Ha ha!
Now, you know how to parse the XML documents
and get all the attributes of a tag. How are you going to
display them? The thing is that you have to create your
controls at run-time. In plain English, you have to add
the controls on the form as you go on parsing the XML document.
In VB 6, there is a Controls Collection object that exists
with every VB form, and you add a control at run-time by
issuing statements like this:
Dim objNewLabel As VB.Label
Set objNewLabel = Controls.Add("VB.Label", "label" + objName,
Me)
You can play with the newly created
control's properties by changing the properties of the newly
created object 'objNewLabel' and read the existing properties
like this:
Msgbox objNewLabel.name
But in EVB, you do not get this one.
Don't get upset. Even you can build an object-like Controls
Collection. It is easy. With a bit of WinCE API, you can
create the controls at run-time. Create two arrays, one
for keeping their names and another for keeping their window
handle. Create a counter for keeping them in right order
and when you are finished creating one, increase the counter.
Simple right?
The windows API
Now, what API to use? Well, to create
a control using API, you use this one:
Declare Function CreateWindowExW Lib "coredll"
(ByVal unknown As Long, ByVal lpClassName As String, ByVal
lpWindowName As String, ByVal dwStyle As Long, ByVal X As
Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight
As Long, ByVal hWndParent As Long, ByVal hMenu As Long,
ByVal hInstance As Long, ByVal lpParam As Long) As Long
This is the basic one for creating any
kind of windows control. Depending on lpClassName parameter
of this API, it creates a STATIC, EDIT, BUTTON, LIST BOX
and a few other controls. So, what about a check box, radio
button and other objects ? Well, by changing the property
of the BUTTON, you can make it a radio button or check box.
These properties are called control styles. Look into any
Windows API book for more information since describing each
one of them will take too much space and the books/msdn/www.vbapi.com
is rich in terms of explanations. Lets look into the basic
controls and the properties that we are going to use:
Static text: STATIC class with styles
WS_TABSTOP Or WS_CHILD Or WS_VISIBLE
Text box: EDIT class with styles WS_TABSTOP Or WS_CHILD
Or WS_VISIBLE Or WS_BORDER Or ES_LEFT
Text area: EDIT class with styles WS_TABSTOP Or WS_CHILD
Or WS_VISIBLE Or WS_BORDER Or ES_LEFT Or ES_AUTOHSCROLL
Or ES_MULTILINE Or WS_VSCROLL Or WS_HSCROLL
Radio box: BUTTON class with styles WS_TABSTOP Or WS_CHILD
Or WS_VISIBLE Or BS_AUTORADIOBUTTON
Check box: BUTTON class with styles WS_TABSTOP Or WS_CHILD
Or WS_VISIBLE Or BS_AUTOCHECKBOX
List Box: LISTBOX class with styles WS_TABSTOP Or WS_CHILD
Or WS_VISIBLE Or WS_BORDER Or LBS_MULTIPLESEL Or LBS_DISABLENOSCROLL
Or WS_VSCROLL Or WS_HSCROLL
Creating the windows controls
First make a procedure that will create
the window controls on the form, keep their information
in arrays. For simplicity, let's say we will have maximum
of 255 controls on a form. So we declare array accordingly
and a counter. For this example, we are assuming that the
controls will be created as they are traversed in the XML
tree. So we will just keep the list of window handles and
use the counter to reference to the correct windows control.
Dim controlsHwnD(255) As Long
Dim controlsIndex As Integer
And the function to create the window
controls:
Private Sub createControl(objclassName
As String, objText As String, objOptions As Long, objLength
As Long, objHeight As Long)
Dim objHandle As Long
Dim messageStatus As Long
'creates the window object and returns the handle of the
object
objHandle = CreateWindowExW(CLng(0), objclassName, objText,
objOptions, currX, currY, objLength, objHeight, Frame1.hwnd,
0, App.hInstance, CLng(0))
'if the window is not for displaying text then save the
handle. This is ok since when we are going to save the XML
file, we are not going to alter the static text portion.
If objclassName <> "STATIC" Then
controlsHwnD(controlsIndex) = objHandle
controlsIndex = controlsIndex + 1
End If
addMaxs objLength, 0
End Sub
'this function is useful for large forms to set the maximum
values for the scroll bars for scrolling
Private Sub getMAX()
If maxCurrX < currX Then maxCurrX = currX
If maxCurrY < currY Then maxCurrY = currY
End Sub
'this function is useful to decide where we are going to
put the next object
Private Sub addMaxs(ByVal X As Integer, ByVal Y As Integer)
currX = currX + X
currY = currY + Y
getMAX
End Sub
Previous Page
Next Page