Window List Functions
Examples:
To browse a web site:
ShellExecute("open", "http://www.somedomain.com", "", "", 1)
To open a document file:
ShellExecute("open", "somefile.doc", "", "", 1)
To explore your Windows documents file folder:
ShellExecute("explore", "C :\Documents and Settings", "", "", 1)
To launch Internet Explorer:
ShellExecute("", "iexplore", "", "", 1)
To preview a file in Internet Explorer:
ShellExecute("", "iexplore somefile.htm", "", "", 1)
To search for files in the current project folder:
ShellExecute("find", filespec, "", "", 1)
Window List Functions
A window list is a collection of source file window handles. There is only one window list in the Source Insight application. It contains all the source window handles. You can use the window list to enumerate through all source file windows.
WndListCount ()
This function returns the number of windows in the window list. Use WndListItem to access the window handle at a particular index in the list.
WndListItem (index)
This function returns the window handle at the given index. The size of the window list is returned by
WndListCount. Index values start at zero, and continue up to one less than the value returned by WndList-
Count.
This example enumerates all the open window handles: cwnd = WndListCount() iwnd = 0 while (iwnd < cwnd)
{ hwnd = WndListItem(iwnd)
// … do something with window hwnd iwnd = iwnd + 1
}
Window Functions
Window functions allow manipulation of source file windows. File buffers are displayed in source windows.
An hwnd is typically a small integer value. An hwnd of hNil indicates an error.
Source Insight 4 User Guide 393
Window Functions
The functions use window handle (hwnd) parameters. These are macro-level handles to open source file windows. Note that a macro hwnd is similar in concept, but is not exactly the same as a window handle HWND in the Microsoft Windows API.
Each source window has a selection in it, which describes what characters are selected. See “GetWndSel
(hwnd)” on page 395 for more information.
In some functions, a window handle (hwnd) can also represent a handle to a system level window, such as the application window. System level windows do not contain a file buffer, or a selection. The GetApplicationWnd function returns a handle to the Source Insight application window.
CloseWnd (hwnd)
Closes the window hwnd. Closing a window does not close the file buffer displayed in the window.
GetApplicationWnd ()
Returns a window handle to the Source Insight application window.
Note:
This is not the same as a system-level window handle. It is a Source Insight macro-level handle value.
The returned handle can be passed to functions that do not assume a file buffer or selection, such as
GetWndDim and IsWndMax.
GetCurrentWnd ()
Returns the handle of the active, front-most source file window, or returns hNil if no windows are open.
GetNextWnd (hwnd)
Returns the next window handle in the window Z order after hwnd. This is usually the previous window that was active. GetNextWnd returns hNil if there are no other windows.
For example, if hwnd is the top-most window, then GetNextWnd(hwnd) will return the next window down.
Note that if you are using SetCurrentWnd to set the front-most active window, subsequent calls to GetNextWnd are affected.
GetWndBuf (hwnd)
Returns the handle of the file buffer displayed in the window hwnd.
GetWndClientRect (hwnd)
Returns a Rect record, which contains the client rectangle of the given window. The coordinates are given in the window's local coordinate system. The client rectangle does not include the window's frame or other
non-client areas. See “Rect Record” on page 381.
GetWndDim (hwnd)
Returns a DIM record, which describes the pixel dimension of the given window hwnd. See “DIM Record” on page 380.
The horizontal dimension returned is the width of the text area of the window only. It does not include the left margin or the symbol window attached to the source window.
GetWndHandle (hbuf)
Returns a window handle for the front-most window that displays the file buffer specified by hbuf. GetWnd-
Handle returns hNil if the file buffer is not in a window.
Since a file buffer may appear in more than one window, GetWndHandle searches through all windows in front-to-back order. So if the specified file buffer is the current buffer in the active window, the handle for that window is always returned.
394 Source Insight 4 User Guide
Window Functions
GetWndHorizScroll (hwnd)
Returns the horizontal scroll state of the window hwnd. The horizontal scroll state is the pixel count of the scroll.
GetWndLineCount (hwnd)
Returns the vertical size of the window hwnd in lines. This is the maximum number of lines potentially visible in the window. If the file buffer does not fill the entire window, GetWndLineCount will still return the maximum number of lines.
GetWndLineWidth (hwnd, ln, cch)
Returns the width of a specified line of text in the given window.
Inputs:
Parameter
hwnd ln cch
Description
The window.
The line number that contains the text to be measured. If ln is out of range, then –1 is returned.
The count of characters to measure on the line. If cch is set to –1, then the whole line length is measured.
This function allows you to measure the width of characters in a given window. Since the font used by each window is determined by the file's document type, the width of text can vary from window to window. Syntax formatting also affects the width of text.
This function can be used along with ScrollWndHoriz to scroll a window to show a particular character.
Examples
To find the width of the whole line at line 100: dim = GetWndLineWidth(hwnd, 100, -1)
Msg ("Line 100 is " # dim.cxp # " pixels wide.")
To find the width of the first 3 characters on line 200:
Dim = GetWndLineWidth(hwnd, 200, 3)
GetWndParent (hwnd)
Returns the handle to the window's parent window. Returns hNil if there is no parent.
GetWndRect (hwnd)
Returns a Rect record, which contains the screen rectangle coordinates of the given window. The rectangle
includes the window frame and non-client areas. See “Rect Record” on page 381.
GetWndSel (hwnd)
Returns the selection state of the window specified by hwnd. The selection state is returned in a Selection
record. See “Selection Record” on page 382.
GetWndSelIchFirst (hwnd)
Returns the index of the first character in the selection in the window hwnd.
GetWndSelIchLim (hwnd)
Returns the index of one past the last character in the selection in the window hwnd.
Source Insight 4 User Guide 395
Window Functions
GetWndSelLnFirst (hwnd)
Returns the first line number of the selection in the window hwnd.
GetWndSelLnLast (hwnd)
Returns the last line number of the selection in the window hwnd.
GetWndVertScroll (hwnd)
Returns the vertical scroll state of the window hwnd. The vertical scroll state is the line number that appears at the top of the window.
IchFromXpos (hwnd, ln, xp)
Returns the character index given a pixel x-position (xp) on the line number (ln) in the given window. The character index is the zero based index of a character on the specified line. The line does not actually have to
be displayed in the window at the time this function is called. See “XposFromIch (hwnd, ln, ich)” on page 397.
Inputs:
Parameter
hwnd ln xp
Description
The window.
The line number that contains the text to be measured. If ln is out of range, then –1 is returned.
The x-position, which is relative to the left edge of the whole window. If xp exceeds the width of the line, then the total number of characters on the line is returned.
Note:
You can use the XposFromIch function to perform the reverse mapping.
IsWndMax (hwnd)
Returns TRUE if the window hwnd is currently maximized.
IsWndMin (hwnd)
Returns TRUE if the window hwnd is currently minimized.
IsWndRestored (hwnd)
Returns TRUE if the window hwnd is currently not maximized and not minimized.
LineFromYpos (hwnd, ypos)
Returns the line number located at the given y-pixel position in the given window. The y-position is relative to
the top edge of the window. If the line number is not visible in the window, then -1 is returned. See “Ypos-
FromLine (hwnd, ln)” on page 398.
Inputs:
Parameter
hwnd ypos
Description
The window.
The y-pixel position relative to the top of the window. Ypos values are zero at the top of the window, and a positive value at the bottom of the window. If ypos is not inside the window, then -1 is returned.
396 Source Insight 4 User Guide
Window Functions
Note:
You can use the YposFromLine function to perform the reverse mapping.
MaximizeWnd (hwnd)
Maximizes (or "zooms") the window specified by hwnd.
MinimizeWnd (hwnd)
Minimizes (or "iconizes") the window specified by hwnd.
NewWnd (hbuf)
Creates a new window and displays the file buffer hbuf in the window. NewWnd returns a window handle, or hNil if errors.
ScrollWndHoriz (hwnd, pixel_count)
Scrolls the window hwnd horizontally by an amount given in pixel_count.
If pixel_count is less than zero, then the scroll is backward in the line (screen contents scrolls right).
If pixel_count is greater than zero, then the scroll is forward in the line (screen contents scrolls left).
ScrollWndToLine (hwnd, ln)
Scrolls the window hwnd to show the line number ln at the top of the window.
ScrollWndVert (hwnd, line_count)
Scrolls the window hwnd vertically by an amount given in line_count.
If line_count is less than zero, then the scroll is backward in the file (screen contents scrolls down).
If line_count is greater than zero, then the scroll is forward in the file (screen contents scrolls up).
SetCurrentWnd (hwnd)
Sets the front-most active window. Hwnd is the window handle to activate.
SetWndRect (hwnd, left, top, right, bottom)
Sets the new position of the given window. The Z-order is not affected. The coordinates given are in the local pixel coordinate system of the window's parent window. If the window is the application window, then the coordinate system is the global screen pixel coordinate system.
SetWndSel (hwnd, selection_record)
Sets the selection state for the window specified by hwnd to the Selection record given in selection_record.
See also “GetWndSel (hwnd)” on page 395.. See “Selection Record” on page 382.
ToggleWndMax (hwnd)
Toggles the window hwnd between maximized and restored sizes.
XposFromIch (hwnd, ln, ich)
Returns the pixel x-position number given character position (ich) on the line number (ln) in the given window. The x-position is relative to the left edge of the whole window. The line does not actually have to be dis-
played in the window at the time this function is called. See “IchFromXpos (hwnd, ln, xp)” on page 396.
Source Insight 4 User Guide 397