sx_SetGaugeHook

<< Click to Display Table of Contents >>

Navigation:  Apollo API Listing >

sx_SetGaugeHook

VB Declaration

Declare Sub sx_SetGaugeHook Lib "Apollo9.dll"

(ByVal hWndGauge As Integer)

Description

Defines a window that time consuming operations may communicate with in order to inform the user as to the progress of the operation.

 

The following functions can utilize sx_SetGaugeHook:

 

  sx_CopyFile

  sx_CopyFileText

  sx_DbfDecrypt

  sx_DbfEncrypt

  sx_Pack

  sx_Index

  sx_IndexTag

  sx_Reindex

Parameters

hWndGauge: The window handle of an edit control that is to receive messages from the sending operation.

If the window handle is valid (i.e., the window exists), a KeyDown event is fired for the defined window whenever the completion percentage of the operation changes.

The KeyCode parameter passed to the KeyDown event contains the percentage complete as a negative number instead of a key value. This allows the programmer to distinguish between normal key events and the gauge hook events.

If the operation using the gauge hook is working on a single file (e.g., sx_Index), the percentage passed is an absolute measure of the progress of the procedure.

If the operation is one in which a number of files are involved (e.g., sx_Pack, sx_Reindex), you must invent an algorithm to process successive percentages as a ratio of all of the files taking part in the procedure.

For example, if packing a file that has two active indexes (or tags) and a memo file, the window receiving the gauge hook messages will receive percentages of 1 to 100 four times (for the dbf, the 2 indexes, and the memo file). Before displaying the percentage or setting your gauge, you must therefore divide the absolute value of the percentage received from the hook by 4 (the number of files) before displaying it.

VB Example

' Global vars to manage gauge hook

Global GaugeFiles As Integer

Global GaugePercent As Integer

 

Sub ButtonIndexMake_Click ()

If Not sx_Use("c:\vb\cust.dbf", "cust", EXCLUSIVE, SDENTX)

MsgBox "File not available. Try again later."

Else

iRet1 = sx_IndexOpen("c:\vb\sxcust1.ntx")

iRet2 = sx_IndexOpen("c:\vb\sxcust2.ntx")

iRet3 = sx_IndexOpen("c:\vb\sxcust3.ntx")

 

' set up vars to manage gauge display

sx_SetGaugeHook GaugeBox.hWnd

GaugePercent = 0

GaugeFiles = 3 ' global var to be used by GaugeBox

sx_Reindex

sx_SetGaugeHook 0

sx_Close

End If

End Sub

 

Sub GaugeBox_KeyDown (KeyCode As Integer, Shift As Integer)

' display gauge numbers sent here

' this could also be a meter bar or analog gauge

' like those shipped with the VB professional kit

Dim iCurrent As Integer

 

If KeyCode < 0 Then

If GaugeFiles > 0 Then

If Abs(KeyCode) = 100 Then

GaugePercent = (100 / GaugeFiles) + GaugePercent

iCurrent = 0

Else

iCurrent = Abs(KeyCode) / GaugeFiles

End If

Else

iCurrent = Abs(KeyCode)

End If

GaugePercent = GaugePercent + iCurrent

GaugeBox.Text = Format$(GaugePercent, "##0")

End If

End Sub

C Example

// Global vars to manage gauge hook

SHORT iGaugeFiles;

SHORT iGaugePercent;

 

void CMainForm::OnButtonIndex()

{

if (!sx_Use("c:\\vb\\cust.dbf", "cust", EXCLUSIVE, SDENTX))

AfxMessageBox((LPCSTR) "File not available. Try again.");

else

{

sx_IndexOpen("c:\\vb\\sxcust1.ntx")

sx_IndexOpen("c:\\vb\\sxcust2.ntx")

sx_IndexOpen("c:\\vb\\sxcust3.ntx")

 

// set up vars to manage gauge display

sx_SetGaugeHook(m_gauge->GetNumProperty("hWnd"));

iGaugePercent = 0;

iGaugeFiles = 3;

sx_Reindex();

sx_SetGaugeHook(0);

sx_Close();

}

}

 

// Gauge control KeyDown event

void CMainForm::OnKeyDown(UINT, int, CWnd*, LPVOID lpParams)

{

SHORT iKeyCode;

 

iKeyCode = AFX_NUM_EVENTPARAMINDEX(SHORT, lpParams,1);

if (iKeyCode < 0)

{

iKeyCode = -iKeyCode;

if (iGaugeFiles > 0)

{

if (iKeyCode = 100)

{

iGaugePercent = (100 / iGaugeFiles) + iGaugePercent;

iKeyCode = 0;

else

iKeyCode = iKeyCode / GaugeFiles;

}

iGaugePercent = iGaugePercent + iKeyCode;

m_gauge->SetNumProperty("Value", iGaugePercent);

}

}

See Also

sx_AppendFrom, sx_CopyFile, sx_DbfDecrypt, sx_DbfEncrypt, sx_Pack, sx_Index, sx_IndexTag, sx_Reindex