OnUpdateGUI Event

[Top]  [Chapter]  [Previous]  [Next]

This is the main event to update any custom toolbar and menu.

Member of WPDLLInt

Declaration C#

OnUpdateGUIEvent(Object Sender, int Editor, int UpdateFlags, int StateFlags, int PageNr, int PageCount, int LineNr)


Declaration OCX

OnUpdateGUI(ByVal Editor As Long, ByVal UpdateFlags As Long, ByVal StateFlags As Long, ByVal PageNr As Long, ByVal PageCount As Long, ByVal LineNr As Long)


The event can be used to show the current position in a statusbar:


Private void wpdllInt1_OnUpdateGUI(Object Sender, 

   int Editor, 

   int UpdateFlags, 

   int StateFlags, 

   int PageNr, 

   int PageCount, 

   int LineNr)


      stPage.Text = Convert.ToString(PageNr)+'/'+ Convert.ToString(PageCount);

      stLine.Text = "Line " + Convert.ToString(LineNr); 

      stIns.Text = (((StateFlags&2)!=0)?"INS":"");



This is also the recommended event to update any custom toolbar and menu. Inside this event You can use the wpaGetFlags to retrieve the states of all implemented wpa actions in one array.

C# example:

private void wpdllInt1_OnUpdateGUI(object Sender, int Editor, int UpdateFlags, int StateFlags, int PageNr, int PageCount, int LineNr)


 int wpa_italic = wpdllInt1.wpaGetID("Italic");

 byte[] stateflags = wpdllInt1.wpaGetFlags(0); // Current editor

 btItalic.Pushed =(stateflags[wpa_italic] & 2)!=0;


In this example we use wpaGetID to get the ID for a certain action to make the process better to understand. In a real world application you would use wpaGetID() only once and then save the result id in an integer property added to the button or menu class. (see example "First C# Application" in the manual)


Note: You can use wpaSetFlags to modify certain internal states. This makes it possible to disable internal buttons under program control.


Also see: IWPAttrInterface TextAttr;




The number of the current editor, 1 or 2


The bitfield UpdateFlags selects the elements of the GUI which need update:

bit 1 (1): Selection has been changed/

bit 2 (2): Undo/Redo state has been changed

bit 3 (4): Paragraph properties have been changed

bit 4 (8): Character attributes have been changed

bit 5 (16): The Layout mode was changed

bit 6 (32): Cursor position has been changed

bit 7 (64): The Readonly property was changed

bit 8 (128): The editor features/license has been changed

Usually you do not have to use this parameter. It is internally used to update the flag array in a more effective way.


The bitfield StateFlags contains the flags:

bit 1 (1): The text was modified

bit 2 (2): The editor is insertion mode, otherwise overwrite mode

bit 3 (4): Can Undo

bit 4 (8): Can Redo

bit 5 (16): Currently text or an object is selected

bit 6 (32): Currently an object is selected

bit 7 (64): The selected object is an image

bit 8 (128): The cursor is undefined - the current position has not been set

bit 9 (256): The cursor is within a table

bit 10 (512): The current paragraph uses a style

bit 12 (1024): The current position is not inside the text body but in header/footer, text box or footnote. uses a style


The current page number


The currenbt page count


The current line number on the current page

VB 6 Example:

Here we took the automatically created MDI example and converted it to use TextDynamic. The way a the toolbar is processed here is not optimal - it uses fixed names. We would recommend to use IDs in the toolbar and use a separate array to match the button to the action.

This is the code which simply uses the original logic:


Private Sub rtfText_OnUpdateGUI(ByVal Editor As LongByVal UpdateFlags As LongByVal StateFlags As LongByVal PageNr As LongByVal PageCount As LongByVal LineNr As Long)

  Dim s As String ' the returned array is a string

  Dim i As Integer ' we need the index of a certain action

  Dim Bytes() As Byte ' we need a bytes array to test the flags


  ' Retrieve the setting of all atcions

  s = rtfText.wpaGetFlags(0) ' this are the flags for the current editor

  Bytes = StrConv(s, vbFromUnicode) ' convert string to bytes


  ' Character attributes have been changed

  If (UpdateFlags And 8 <> 0) Then

    ' this is the id for the command to toggle 'bold'

    i = rtfText.wpaGetID("bold")

    ' Use the id to update the setting of 'Bold'

    fMainForm.tbToolBar.Buttons("Fett").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed)

    ' Proceed with the other elements

    ' ...

    ' this is the id for the command to toggle 'italic'

    i = rtfText.wpaGetID("italic")

    ' Use the id to update the setting of 'italic'

    fMainForm.tbToolBar.Buttons("Kursiv").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed)



    ' this is the id for the command to toggle 'underline'

    i = rtfText.wpaGetID("underline")

    ' Use the id to update the setting of 'underlined'

    fMainForm.tbToolBar.Buttons("Unterstrichen").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed)

  End If


  ' Paragraph attributes have been changed

  If (UpdateFlags And 4 <> 0) Then

    ' this is the id for the command to toggle 'left'

    i = rtfText.wpaGetID("left")

    ' Use the id to update the setting of 'left aligned'

    fMainForm.tbToolBar.Buttons("Links ausrichten").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed)

    ' Proceed with the other elements

    ' ...

    ' this is the id for the command to toggle 'Center'

    i = rtfText.wpaGetID("Center")

    ' Use the id to update the setting of 'Centered'

    fMainForm.tbToolBar.Buttons("Zentrieren").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed)



    ' this is the id for the command to toggle 'Right'

    i = rtfText.wpaGetID("Right")

    ' Use the id to update the setting of 'Rechts ausrichten'

    fMainForm.tbToolBar.Buttons("Rechts ausrichten").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed)

  End If


End Sub



Display Status Information

[idh_wpdllint_onupdategui.htm]    Copyright © 2007 by WPCubed GmbH