on 10-23-2015 10:02 AM
Hi Everyone,
I am using PB11.1 build 8123. I want to add a functionality to checking the spelling. I write below code but I have a problem that MS WORD open as minimized state. I want this at front of user. Please suggest.
Global external function
------------------------------------------
PUBLIC FUNCTION unsignedlong FindWindow (long &
classname, string windowname) LIBRARY "user32.dll" &
ALIAS FOR FindWindowW
PUBLIC FUNCTION int SetForegroundWindow (unsignedlong &
hwnd) LIBRARY "user32.dll" ALIAS FOR SetForegroundWindowW
code
------------
string ls_current_text
ls_current_text=mle_1.text
If ls_current_text = "" then Return
If Clipboard(ls_current_text) = "" Then RETURN
OleObject myOleObject
myOleObject = CREATE OLEObject
If myOleObject.ConnectToNewObject("word.application") <> 0 Then Return
unsignedlong hwnd
hwnd = FindWindow ( 0, "Document1")
myoleobject.Application.Visible = True
myoleobject.Application.WindowState = 1
myoleobject.Application.Documents.Add.Content.Paste
if hwnd = 0 then
//
else
SetForegroundWindow ( hwnd)
end if
myoleobject.Application.ActiveDocument.CheckSpelling
myoleobject.Application.ActiveDocument.Content.Copy
myoleobject.ActiveDocument.Close(0)
myoleobject.Application.Quit
myOleObject.disconnectobject()
Destroy myOleObject
messagebox("Information", "The spelling and grammer check is complete.")
mle_1.text=Clipboard(ls_current_text)
I think I found the problem:
The code "hwnd = FindWindow ( 0, "Documento1 - Word")" is before "myoleobject.Application.Visible = True", so it always return 0. Just put it after.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
As you suggest, I change below code, but it still not shown on top.
string ls_current_text
unsignedlong hwnd
ls_current_text=mle_1.text
If ls_current_text = "" then Return
If Clipboard(ls_current_text) = "" Then RETURN
OleObject myOleObject
myOleObject = CREATE OLEObject
If myOleObject.ConnectToNewObject("word.application") <> 0 Then Return
myoleobject.Application.Visible = false
myoleobject.Application.WindowState = 2
hwnd = FindWindow ( 0, "Documento1 - Word")
myoleobject.Application.Documents.Add.Content.Paste
if hwnd = 0 then
//
else
SetForegroundWindow ( hwnd)
end if
myoleobject.Application.Visible = true
myoleobject.Application.WindowState = 1
myoleobject.Application.ActiveDocument.CheckSpelling
myoleobject.Application.ActiveDocument.Content.Copy
myoleobject.ActiveDocument.Close(0)
myoleobject.Application.Quit
myOleObject.disconnectobject()
Destroy myOleObject
messagebox("Information", "The spelling and grammer check is complete.")
mle_1.text=Clipboard(ls_current_text)
If you have any better solution, please share.
Following code that works for me:
Just make sure to put in FindWindow the name of your Word document.
Mine is "Documento1 - Word" because I use Word 2013 in Portuguese.
--------------------------------------
string ls_current_text
unsignedlong hwnd
ls_current_text=mle_1.text
If ls_current_text = "" then Return
If Clipboard(ls_current_text) = "" Then RETURN
OleObject myOleObject
myOleObject = CREATE OLEObject
If myOleObject.ConnectToNewObject("word.application") <> 0 Then Return
myoleobject.Application.Visible = True
myoleobject.Application.WindowState = 1
myoleobject.Application.Documents.Add.Content.Paste
hwnd = FindWindow ( 0, "Documento1 - Word")
if hwnd <> 0 then
SetForegroundWindow ( hwnd)
end if
myoleobject.Application.ActiveDocument.CheckSpelling
myoleobject.Application.ActiveDocument.Content.Copy
myoleobject.ActiveDocument.Close(0)
myoleobject.Application.Quit
myOleObject.disconnectobject()
Destroy myOleObject
messagebox("Information", "The spelling and grammer check is complete.")
mle_1.text=Clipboard(ls_current_text)
Don't know if this workaround is too ugly, but...
You can set "w_yourWindow.visible = false" before setting Word visibility, and back again to true after spell check.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.