No tag for PB 12.5
I have a function that checks the spelling of reports generated in PowerBuilder 12.5, using external windows functions.
my problem is on the line:
ll_Hwnd = FindWindowA ( ls_Null, "Documento1 - Microsoft Word" ).
Hardcode the title of the window to find it faster. if the user has an open word window, he will never find the window and I will not be able to bring it to the front. so my question is if there is any function in OleObject that allows me to read the title of the window. all the examples that I found, save the document by assigning a name and after using the file, they delete it, but they demanded that nothing be saved.
If it works, it works, but if someone knows another way to make the word corrector window go forward, it would be very helpful.
example:
global external functions:
FUNCTION uInt FindWindowA(string szClass, string szName) LIBRARY "user32.dll" alias for "FindWindowA;Ansi"
FUNCTION uInt GetWindow(long hwnd, long lnextwindow) LIBRARY "user32.dll"
FUNCTION uInt GetWindowTextA(long hwnd, ref string titleText, long nMaxCount) LIBRARY "user32.dll" alias for "GetWindowTextA;Ansi"
FUNCTION boolean BringWindowToTop(long hwnd) LIBRARY "user32.dll"
FUNCTION boolean SetForegroundWindow(long hwnd) LIBRARY "user32.dll"
FUNCTION uInt SetActiveWindow(long hwnd) LIBRARY "user32.dll"
PB function:
Long ll_Hwnd
String ls_Null
OLEObject Ole_Word
LONG ll_rc, lnStart, lnEnd
ULONG hActiveWindow, hData
uint HRTF
ulong CF_TEXT = 1
p_rtf.SelectTextAll()
if p_rtf.selectedlength() <= 0 then
Messagebox("Atención","No hay texto a Revisar",Information!)
return -1
end if
SetPointer(Hourglass!)
clipboard("")
p_rtf.Copy()
//* Obtener un identificador de la ventana activa.
hActiveWindow = gu_ext_func.uf_GetActiveWindow()
//* Abrir el portapapeles con una asociación a la
// Ventana activa.
gu_ext_func.uf_OpenClipboard (hActiveWindow)
// Registro RTF como formato de portapapeles válido.
HRTF = gu_ext_func.uf_RegisterClipboardFormatA("Rich Text Format")
// Obtener datos colocados en el portapapeles
// En formato de texto.
hData = gu_ext_func.uf_GetClipboardData (CF_TEXT)
// Re-enviar el mismo bloque de memoria en el portapapeles
gu_ext_func.uf_SetClipboardData (HRTF, hData)
gu_ext_func.uf_CloseClipboard ()
ole_Word = CREATE OleObject
ll_rc =Ole_Word.ConnectToNewObject( 'Word.Application' )
if ll_rc <> 0 THEN
destroy ole_Word
RETURN -1
end if
//Si se pudo crear el Word se crea y muestra el Documento
ole_Word.Application.DisplayAlerts = True
ole_Word.Application.Visible = True
ole_Word.Application.WindowState = 2
ole_Word.Documents.Add()
ole_Word.Selection.Paste()
SetNull (ls_Null)
// busco la ventana
ll_Hwnd = FindWindowA ( ls_Null, "Documento1 - Microsoft Word" )
// una vez lo tengo, lo mando al frente
SetForegroundWindow((ll_Hwnd))
SetActiveWindow(ll_Hwnd)
BringWindowToTop(ll_Hwnd)
ole_Word.ActiveDocument.CheckSpelling()
lnStart = ole_Word.ActiveDocument.Content.Start
lnEnd = ole_Word.ActiveDocument.Content.End
ole_Word.ActiveDocument.Range(lnStart, lnEnd).Select
gu_ext_func.uf_EmptyClipboard()
ole_Word.Selection.Copy()
p_rtf.Paste()
ole_Word.ActiveDocument.Close( False )
ole_Word.Application.Quit
ole_Word.DisconnectObject()
Destroy ole_Word