Small Question about Word and FWH

Small Question about Word and FWH

Postby driessen » Wed Jul 12, 2023 11:20 pm

Hello,

If I open a Word document in my application by using:

odoc := oWord:Documents:Open(cFile)

1. How do I open my document minimized?
2. How do I minimize a document that already has been opened, without using oWord:Visible := .F. which minimizes all my opened Word documents?

Thanks.
Last edited by driessen on Mon Jul 17, 2023 9:28 am, edited 2 times in total.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Small Question about Word and FWH

Postby Antonio Linares » Thu Jul 13, 2023 4:48 am

Dear Michel,

> 1. How do I open my document minimized?

odoc := oWord:Documents:Open( cFile )
odoc:WindowState := 1 // wdWindowStateMinimize

> How do I minimize a document that already has been opened, without using oWord:Visible := .F. which minimizes all my opened Word documents?

oDoc:Activate()
oDoc:WindowState := 1 // wdWindowStateMinimize
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Small Question about Word and FWH

Postby driessen » Fri Jul 14, 2023 7:57 am

Antonio,

Once again for your help.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Small Question about Word and FWH

Postby driessen » Mon Jul 17, 2023 9:34 am

Guys,

I have another question about Word and OLE.

This is the situation.

I have 2 applications running together.

Application 1 creates the object jWord
Application 2 creates the object cWord.

The Word-objects are both created by "WinOle()".

If I close Application 2, I perform a "cWord:Quit()". Then Word (cWord) is closed, but also Word (jWord) is closed. If in jWord no document is opened, that is no problem.But in case a document has been opened in jWord, that document is closed to.

So, I need to check in Application 2 if a document is opened in jWord, opened by Application 1. If so, I can't perform "cWord:Quit()".

Any idea how I can do that?

Thank you so much for any help in advance.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Small Question about Word and FWH

Postby Antonio Linares » Mon Jul 17, 2023 9:38 am

Dear Michel,

chatGPT help:
To check if a document is opened in jWord by Application 1 before closing cWord in Application 2, you can use the following approach:

In Application 1, keep track of the document state using a variable or flag that indicates whether a document is currently open or not. Set the flag to true when a document is opened in jWord and false when the document is closed.

In Application 2, before calling cWord:Quit(), you can use inter-process communication to check the state of the document in jWord. Here's a general outline of the steps involved:

a. Use a suitable inter-process communication mechanism supported by your programming language or platform, such as named pipes, sockets, or shared memory, to establish communication between Application 1 and Application 2.

b. In Application 1, expose a method or API that returns the current state of the document in jWord (i.e., whether it is open or closed).

c. In Application 2, call the method or API provided by Application 1 to query the document state in jWord. Based on the response received, you can determine whether it's safe to call cWord:Quit().

d. If the document state returned from Application 1 indicates that a document is open in jWord, skip calling cWord:Quit() to avoid closing the shared document.

Note that the exact implementation details may vary depending on the programming languages and frameworks you're using for both applications. Make sure to consult the documentation and resources specific to your development environment for guidance on inter-process communication and exposing APIs.


Public Const WM_COPYDATA As Integer = &H4A

Private Sub CheckJWordDocumentState()
' Find the handle of Application 1
Dim hWnd As IntPtr = FindWindow(Nothing, "Application 1 Window Title") ' Replace "Application 1 Window Title" with the actual title of Application 1

If hWnd <> IntPtr.Zero Then
' Send a message to Application 1 to check the document state
Dim documentState As Boolean = GetJWordDocumentState(hWnd)

If Not documentState Then
' Call cWord:Quit() because no document is open in jWord
cWord.Quit()
Else
' Handle the case when a document is open in jWord
' You can display an error message or prompt the user to close the document manually
End If
End If
End Sub

Private Function GetJWordDocumentState(ByVal hWnd As IntPtr) As Boolean
Dim cds As New CopyDataStruct()
cds.dwData = IntPtr.Zero
cds.lpData = String.Empty
cds.cbData = 0

Dim result As IntPtr = SendMessage(hWnd, WM_COPYDATA, IntPtr.Zero, cds)

If cds.cbData = 1 AndAlso cds.lpData <> String.Empty Then
Return cds.lpData = "1"
End If

Return False ' Default state if an error occurred
End Function

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowW" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageW" (ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByRef lParam As CopyDataStruct) As IntPtr


In your code, call the CheckJWordDocumentState() method before closing Application 2 or before invoking cWord:Quit().
Note: Replace "Application 1 Window Title" in Application 2 code with the actual title of the Application 1 window. Ensure that both applications are running with their respective windows open before attempting to check the document state.


Please review FWH\samples\fwcopy16.prg to see how to use WM_COPYDATA
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Small Question about Word and FWH

Postby driessen » Mon Jul 17, 2023 9:52 am

Thanks again, Antonio,
I check it out this afternoon and I will reply with the result.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Small Question about Word and FWH

Postby driessen » Mon Jul 17, 2023 10:46 am

Antonio,

What if I don't know the title of the window of the other application is changing while using the application?
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Small Question about Word and FWH

Postby Antonio Linares » Mon Jul 17, 2023 11:41 am

Dear Michel,

Maybe we can find the window based on its class name instead of its title. We need to do some research about it...
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Small Question about Word and FWH

Postby Antonio Linares » Mon Jul 17, 2023 11:44 am

Yes, we can do it using the function EnumWindows()

using C language:
Code: Select all  Expand view  RUN
#include <iostream>
#include <vector>
#include <windows.h>

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
    std::vector<HWND>& windows = *reinterpret_cast<std::vector<HWND>*>(lParam);

    char className[256];
    if (GetClassName(hwnd, className, sizeof(className)) != 0) {
        if (strcmp(className, "YourTargetClassName") == 0) {
            windows.push_back(hwnd);
        }
    }

    return TRUE;
}

int main() {
    std::vector<HWND> windows;

    if (EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(&windows))) {
        for (HWND hwnd : windows) {
            char windowTitle[256];
            GetWindowText(hwnd, windowTitle, sizeof(windowTitle));
            std::cout << "Window Title: " << windowTitle << std::endl;
        }
    }

    return 0;
}
 

We need to test it using FWH :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Small Question about Word and FWH

Postby driessen » Mon Jul 17, 2023 12:31 pm

I'm very sorry, Antonio, but all of this goes far beyond my knowledge.

This is the source right now:
Code: Select all  Expand view  RUN
STATIC PROCEDURE WordQuit

   cWord:Quit()

RETURN
Is it possible for you to adapt it so that Word-documents from other applications which are still opened, changed and unchanged, are not closed by my "cWord:Quit()"?
What do have to put where?

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Small Question about Word and FWH

Postby Antonio Linares » Mon Jul 17, 2023 4:14 pm

Dear Michel,

Is your main FWH window MDI ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Small Question about Word and FWH

Postby driessen » Mon Jul 17, 2023 4:26 pm

Antonio,

No, it is not MDI.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Small Question about Word and FWH

Postby Antonio Linares » Mon Jul 17, 2023 4:30 pm

What C compiler are you using to email you the new FWH lib ?

With the new lib that I will send you, please run this test, once you have opened your FWH apps and please let me know what you get:

michel.prg
Code: Select all  Expand view  RUN
#include "FiveWin.ch"

function Main()

    local nFWHApps := 0

    EnumWindows( { | hWnd | If( GetClassName( hWnd ) == "TWINDOW", nFWHApps++, ) } )

    MsgInfo( nFWHApps )

return nil  
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Small Question about Word and FWH

Postby Antonio Linares » Mon Jul 17, 2023 4:58 pm

Is there any specific reason why you need to call cWord:Quit() ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Small Question about Word and FWH

Postby driessen » Mon Jul 17, 2023 5:28 pm

Yes.

If app 1 is closed, its Word niets to quit, but the word of app 2 can’t nr closed
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests