home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2003 February / PCpro_2003_02.ISO / trials / omnipage / Data.Cab / F16296_aware_word12.bas < prev    next >
Encoding:
BASIC Source File  |  2002-08-09  |  10.0 KB  |  249 lines

  1. Attribute VB_Name = "ScanSoft_OP12"
  2.  
  3. ' Things to change for the next version of OP or for TextBridge:
  4. ' VB_Name, strActionAcquire, strActionSettings, strTagAcquire, strTagSettings
  5. ' strDotName
  6. ' MACRO_OMNIPAGE_OCR in OfficeAut.cpp
  7.  
  8. ' Declare necessary API routines:
  9. Declare Function FindWindow Lib "user32" Alias _
  10. "FindWindowA" (ByVal lpClassName As String, _
  11.                ByVal lpWindowName As Long) As Long
  12.  
  13. Declare Function PostMessage Lib "user32" Alias _
  14. "PostMessageA" (ByVal hwnd As Long, ByVal msg As Long, _
  15.                 ByVal lParam As Long, ByVal wParam As Long) As Long
  16.  
  17. Private lang As Integer
  18. Private strItemExit As String
  19. Private strItemAcquire As String
  20. Private strItemAcquireTip As String
  21. Private strItemSettings As String
  22. Private strItemSettingsTip As String
  23. 'This is the name of the macro function which calls the OCR function in OfficeAut
  24. Const strActionAcquire As String = "OmniPage12_OCR"
  25. 'This is the name of the macro function which calls the Settings function in OfficeAut
  26. Const strActionSettings As String = "OmniPage12_Settings"
  27. Const strTagAcquire As String = "OmniPage Pro 12 (Acquire)"
  28. Const strTagSettings As String = "OmniPage Pro 12 (Settings)"
  29. Private strTemplatePath As String
  30. Const strDotName As String = "\OP12_tmp.dot"
  31. Const SSFTAppName As String = "OmniPage Pro 12.0"
  32. Const SSFTWndName As String = "Scansoft.OCRAware12"
  33.  
  34. 'This will send a 'start settings' message to the OpWare12.exe
  35. Sub OmniPage12_Settings()
  36.  
  37.     hwnd = FindWindow(SSFTWndName, 0)
  38.     
  39.     If hwnd <> 0 Then
  40.         PostMessage hwnd, &H402, 0, 0 ' 402: WM_USER+2
  41.         System.Cursor = wdCursorWait
  42.     End If
  43.  
  44. End Sub
  45.  
  46. 'This will send a 'start OCR' message to the OpWare12.exe
  47. Sub OmniPage12_OCR()
  48.  
  49.     hwnd = FindWindow(SSFTWndName, 0)
  50.     
  51.     If hwnd <> 0 Then
  52.         PostMessage hwnd, &H401, 0, 0 ' 401: WM_USER+1
  53.         System.Cursor = wdCursorWait
  54.     End If
  55.  
  56. End Sub
  57.  
  58. Private Sub SetupMenuItems()
  59.  
  60.     Dim newStr As String
  61.     ' first find out what language this Word is in, then insert the appropriate menu items.
  62.     Set myitem = CommandBars.Item("File")
  63.     If myitem.NameLocal = "File" Then
  64.         ' English and Italian both use "File" so we need to check Exit also
  65.         Set exititem = CommandBars("File").Controls.Item("Exit")
  66.         newStr = exititem.Caption
  67.         If newStr = "E&xit" Then 'it's english
  68.             ' English
  69.             lang = 0
  70.             strItemExit = "Exit"
  71.             strItemAcquire = "Acquire Text (" + SSFTAppName + ")..."
  72.             strItemAcquireTip = "Acquire Text (" + SSFTAppName + ")"
  73.             strItemSettings = "Acquire Text Settings (" + SSFTAppName + ")..."
  74.             strItemSettingsTip = "Acquire Text Settings (" + SSFTAppName + ")"
  75.         Else
  76.             ' Italian
  77.             lang = 5
  78.             strItemExit = "Esci"
  79.             strItemAcquire = "Acquisisci testo (" + SSFTAppName + ")..."
  80.             strItemAcquireTip = "Acquisisci testo (" + SSFTAppName + ")"
  81.             strItemSettings = "Acquisisci impostazioni del testo (" + SSFTAppName + ")..."
  82.             strItemSettingsTip = "Acquisisci impostazioni del testo (" + SSFTAppName + ")"
  83.         End If
  84.     ElseIf myitem.NameLocal = "Fichier" Then
  85.         ' French
  86.         lang = 1
  87.         strItemExit = "Quitter"
  88.         strItemAcquire = "AcquΘrir le texte (" + SSFTAppName + ")..."
  89.         strItemAcquireTip = "AcquΘrir le texte (" + SSFTAppName + ")"
  90.         strItemSettings = "Configuration d'acquisition du texte (" + SSFTAppName + ")..."
  91.         strItemSettingsTip = "Configuration d'acquisition du texte (" + SSFTAppName + ")"
  92.     ElseIf myitem.NameLocal = "Datei" Then
  93.         ' German
  94.         lang = 2
  95.         strItemExit = "Beenden"
  96.         strItemAcquire = "Texterfassen (" + SSFTAppName + ")..."
  97.         strItemAcquireTip = "Texterfassen (" + SSFTAppName + ")"
  98.         strItemSettings = "Texteinstellungen ⁿbernehmen (" + SSFTAppName + ")..."
  99.         strItemSettingsTip = "Texteinstellungen ⁿbernehmen (" + SSFTAppName + ")"
  100.     ElseIf myitem.NameLocal = "Archivo" Then
  101.         ' Spanish
  102.         lang = 4
  103.         strItemExit = "Salir"
  104.         strItemAcquire = "Adquirir texto (" + SSFTAppName + ")..."
  105.         strItemAcquireTip = "Adquirir texto (" + SSFTAppName + ")"
  106.         strItemSettings = "Parßmetros de Adquirir texto (" + SSFTAppName + ")..."
  107.         strItemSettingsTip = "Parßmetros de Adquirir texto (" + SSFTAppName + ")"
  108.     ElseIf myitem.NameLocal = "Bestand" Then
  109.         ' Dutch
  110.         lang = 6
  111.         strItemExit = "Afsluiten"
  112.         strItemAcquire = "Tekst verwerven (" + SSFTAppName + ")..."
  113.         strItemAcquireTip = "Tekst verwerven (" + SSFTAppName + ")"
  114.         strItemSettings = "Tekstinstellingen verwerven (" + SSFTAppName + ")..."
  115.         strItemSettingsTip = "Tekstinstellingen verwerven (" + SSFTAppName + ")"
  116.     ElseIf myitem.NameLocal = "Arkiv" Then
  117.         ' Swedish
  118.         lang = 8
  119.         strItemExit = "Avsluta"
  120.         strItemAcquire = "Generera text (" + SSFTAppName + ")..."
  121.         strItemAcquireTip = "Generera text (" + SSFTAppName + ")"
  122.         strItemSettings = "Generera textinstΣllningar (" + SSFTAppName + ")..."
  123.         strItemSettingsTip = "Generera textinstΣllningar (" + SSFTAppName + ")"
  124.     ElseIf myitem.NameLocal = "Arquivo" Or myitem.NameLocal = "Ficheiro" Then
  125.         ' Brazilian
  126.         lang = 15
  127.         strItemExit = "Sair"
  128.         strItemAcquire = "Adquirir texto (" + SSFTAppName + ")..."
  129.         strItemAcquireTip = "Adquirir texto (" + SSFTAppName + ")"
  130.         strItemSettings = "Adquirir definiτ⌡es de texto (" + SSFTAppName + ")..."
  131.         strItemSettingsTip = "Adquirir definiτ⌡es de texto (" + SSFTAppName + ")"
  132.     ElseIf myitem.NameLocal = "Fßjl" Then
  133.         ' Hungarian
  134.         lang = 16
  135.         strItemExit = "KilΘpΘs"
  136.         strItemAcquire = "Sz÷veg beolvasßsa (" + SSFTAppName + ")..."
  137.         strItemAcquireTip = "Sz÷veg beolvasßsa (" + SSFTAppName + ")"
  138.         strItemSettings = "Sz÷veg beolvasßs beßllφtßsai (" + SSFTAppName + ")..."
  139.         strItemSettingsTip = "Sz÷veg beolvasßs beßllφtßsai (" + SSFTAppName + ")"
  140.     ElseIf myitem.NameLocal = "Plik" Then
  141.         ' Polish
  142.         lang = 17
  143.         strItemExit = "Zamknij"
  144.         strItemAcquire = "Pobierz tekst (" + SSFTAppName + ")..."
  145.         strItemAcquireTip = "Pobierz tekst (" + SSFTAppName + ")"
  146.         strItemSettings = "Pobierz ustawienia tekstu (" + SSFTAppName + ")..."
  147.         strItemSettingsTip = "Pobierz ustawienia tekstu (" + SSFTAppName + ")"
  148.     ElseIf myitem.NameLocal = "Soubor" Then
  149.         ' Czech
  150.         lang = 18
  151.         strItemExit = "Konec"
  152.         strItemAcquire = "Zφskat text (" + SSFTAppName + ")..."
  153.         strItemAcquireTip = "Zφskat text (" + SSFTAppName + ")"
  154.         strItemSettings = "Nastavenφ funkce Zφskat text (" + SSFTAppName + ")..."
  155.         strItemSettingsTip = "Nastavenφ funkce Zφskat text (" + SSFTAppName + ")"
  156.     End If
  157.  
  158. End Sub
  159.  
  160. Public Sub AutoExec()
  161.  
  162.     strTemplatePath = Application.StartupPath + strDotName
  163.  
  164.     ' There will be an error if the Acquire Text item doesn't exist.
  165.     ' But we still want to execute the next statement
  166.     On Error Resume Next
  167.  
  168.     ' So that we don't save our changes into normal.dot.  This code also needs to
  169.     ' be in AutoExit - wherever we make changes to Word.
  170.     CustomizationContext = Templates(strTemplatePath)
  171.  
  172.     SetupMenuItems
  173.  
  174.     Set oaitem = CommandBars("File").Controls.Item(strItemAcquire)
  175.     If oaitem.Caption <> strItemAcquire Then
  176.         itemindex = CommandBars("File").Controls.Item(strItemExit).Index
  177.         Set newitem = CommandBars("File").Controls.Add(Type:=msoControlButton)
  178.         With newitem
  179.             .Move Before:=itemindex
  180.             .Caption = strItemAcquire
  181.             .TooltipText = strItemAcquireTip
  182.             .Style = msoButtonCaption
  183.             .Visible = True
  184.             .BeginGroup = True
  185.             .FaceId = 0
  186.             .OnAction = strActionAcquire
  187.             .Tag = strTagAcquire
  188.         End With
  189.     End If
  190.  
  191.     Set oaitem = CommandBars("File").Controls.Item(strItemSettings)
  192.     If oaitem.Caption <> strItemSettings Then
  193.         itemindex = CommandBars("File").Controls.Item(strItemAcquire).Index
  194.         Set newitem = CommandBars("File").Controls.Add(Type:=msoControlButton)
  195.         With newitem
  196.             .Caption = strItemSettings
  197.             .TooltipText = strItemSettingsTip
  198.             .Style = msoButtonCaption
  199.             .FaceId = 0
  200.             .OnAction = strActionSettings
  201.             .Tag = strTagSettings
  202.             .Move Before:=itemindex + 1
  203.         End With
  204.     End If
  205.     
  206.     ecount = CommandBars("File").Controls.Count
  207.     Set exititem = CommandBars("File").Controls.Item(ecount)
  208.     exitIndex = exititem.Index
  209.     With exititem
  210.         .BeginGroup = True
  211.     End With
  212.  
  213.     'so that we don't get the "Do you want to save..." message
  214.     Templates(aTemp).Saved = True
  215.  
  216. End Sub
  217.  
  218. Public Sub AutoExit()
  219.  
  220.     ' this will remove the ocraware global addin whenever Word is exited.
  221.     ' When OmniPage is uninstalled, the Aware97.dot file is removed.  However, when Word was
  222.     ' run, the menu items continued to show, with no actions performed.  Now, we will manually
  223.     ' remove it from the AddIns list everytime we exit Word.  And when Word is started the next
  224.     ' time, if the Aware97.dot file is in the startup menu it will reload the AddIn.
  225.  
  226.     Dim newStr As String
  227.     On Error Resume Next
  228.  
  229.     ' So that we don't save our changes into normal.dot.  This code is also
  230.     ' in AutoExex - wherever we make changes to Word.
  231.     CustomizationContext = Templates(strTemplatePath)
  232.  
  233.     Set oaitem = CommandBars("File").Controls.Item(strItemAcquire)
  234.     newStr = oaitem.TooltipText
  235.     If newStr = strItemAcquireTip Then
  236.         oaitem.Delete
  237.     End If
  238.  
  239.     Set oaitem = CommandBars.Item("File").Controls.Item(strItemSettings)
  240.     newStr = oaitem.TooltipText
  241.     If newStr = strItemSettingsTip Then
  242.         oaitem.Delete
  243.     End If
  244.  
  245.     NormalTemplate.Saved = True
  246.     Templates(aTemp).Saved = True
  247.  
  248. End Sub
  249.