This interface allows you to do window management, and change the size and position of windows. Other interfaces that may be useful include ICodeWarriorProjectDocument and ICodeWarriorTextDocument. For text engine work, you'll use ICodeWarriorTextEngine.
You will probably also want to utilize the interface called ICodeWarriorDocumentCollection. For example, you would use the Item() method of ICodeWarriorDocumentCollection to get a document.
For an example illustrating the use of some of these methods, refer to Listing 3.19.
The methods documented here include:
This allows you to determine whether you are working with the active document (the currently-selected document in the foreground).
VARIANT_BOOL* pval - true or false, whether this is the active document.
This allows you to activate the document (the currently-selected document in the foreground).
This allows you to check for whether the document has changed and needs to be saved. Refer to "Saving a Document - Save" to learn how to save a document.
VARIANT_BOOL* pval - true or false, whether the document is dirty or not.
Allows you to get a document's name.
BSTR* pval - the document name.
Allows to see if a document is marked read-only. Refer to "ICodeWarriorVCSState" and "ICodeWarriorVersionControl" for related discussion.
VARIANT_BOOL* pval - true or false, whether the document is marked read-only (non-modifiable) or not.
Get the X-axis window position.
int* pval - an integer giving the X-axis window coordinate of the document's window.
Set the X-axis document position.
ICodeWarriorDocument.XPos Arguments:
Get the Y-axis window position.
int* pval - an integer giving the X-axis window coordinate of the document's window.
Set the Y-axis document position.
ICodeWarriorDocument.YPos Arguments:
Get the document's window width (size along the X-axis).
int* pval - the width of the window.
Sets the document window's width.
ICodeWarriorDocument.Width Arguments:
Get the height of the document's window.
int* pval - the height of the document's window.
Set the height of the document's window.
ICodeWarriorDocument.Height Arguments:
Checking to see whether a document's window is currently visible or not.
VARIANT_BOOL* pval - true or false, whether the window is visible or not.
Sets the visibility of a document's window.
ICodeWarriorDocument.Visible Arguments:
Retrieves the document's IFileSpec.
Argument
Functionality
IFileSpec** pval
ICodeWarriorDocument.FileSpec Arguments:
ICodeWarriorDocument Example Usage:
Option Explicit
Dim theCodeWarriorApp
Dim theTextDocument
Dim theTextEngine
Dim theCollection
Main
Sub Main
Dim theDocument
Dim thePath
Dim i
'Create automation app object
Set theCodeWarriorApp = CreateObject("CodeWarrior.CodeWarriorApp")
'Get a TextEngine
thePath = "C:\temp.txt"
Set theTextDocument = theCodeWarriorApp.OpenTextDocument(thePath, true)
Set theTextEngine = theTextDocument.TextEngine
'Print a list of all the documents
Set theCollection = theCodeWarriorApp.Documents
For i = 0 to theCollection.Count - 1
Set theDocument = theCollection.Item(i)
theTextEngine.InsertText("Document: " + theDocument.Name + Chr(13))
Next
'Print the active document
Set theDocument = theCodeWarriorApp.ActiveDocument
theTextEngine.InsertText(Chr(13) + "Active Document: " + theDocument.Name + Chr(13))
'Print the FileSpecs
PrintFileSpecs
'Print readonly
PrintReadOnly
PrintModified
MoveWindows
End Sub
' Prints fileSpecs
Sub PrintFileSpecs
Dim theFileSpec
Dim theDocument
Dim i
on error resume next
theTextEngine.InsertText(Chr(13) + "FileSpecs: " + Chr(13))
For i = 0 to theCollection.Count - 1
Set theDocument = theCollection.Item(i)
Set theFileSpec = theDocument.FileSpec
theTextEngine.InsertText(theDocument.Name + " -> ")
theTextEngine.InsertText(theFileSpec.FullPath + Chr(13))
Next
End Sub
' Prints names of readonly documents
Sub PrintReadOnly
Dim theDocument
Dim i
'on error resume next
theTextEngine.InsertText(Chr(13) + "ReadOnly Documents: " + Chr(13))
For i = 0 to theCollection.Count - 1
Set theDocument = theCollection.Item(i)
if theDocument.ReadOnly then
theTextEngine.InsertText(theDocument.Name + Chr(13))
end if
Next
End Sub
' Prints names of modified documents
Sub PrintModified
Dim theDocument
Dim i
'on error resume next
theTextEngine.InsertText(Chr(13) + "Modified Documents: " + Chr(13))
For i = 0 to theCollection.Count - 1
Set theDocument = theCollection.Item(i)
if theDocument.Dirty then
theTextEngine.InsertText(theDocument.Name + Chr(13))
end if
Next
End Sub
Sub MoveWindows
Dim theDocument
Dim x
Dim y
Dim width
Dim height
Dim z
Set theDocument = theCodeWarriorApp.ActiveDocument
x = theDocument.XPos
y = theDocument.YPos
width = theDocument.Width
height = theDocument.Height
theTextEngine.InsertText(x)
theTextEngine.InsertText(Chr(13))
theTextEngine.InsertText(y)
theTextEngine.InsertText(Chr(13))
theTextEngine.InsertText(width)
theTextEngine.InsertText(Chr(13))
theTextEngine.InsertText(height)
theTextEngine.InsertText(Chr(13))
x = 0
y = 0
width = 5
height = 5
theDocument.XPos = x
theDocument.YPos = y
theDocument.Width = width
theDocument.Height = height
theTextEngine.InsertText(x)
theTextEngine.InsertText(Chr(13))
theTextEngine.InsertText(y)
theTextEngine.InsertText(Chr(13))
theTextEngine.InsertText(width)
theTextEngine.InsertText(Chr(13))
theTextEngine.InsertText(height)
End Sub