1. Olan Knight
  2. PowerBuilder
  3. Friday, 4 June 2021 14:33 PM UTC

Update:  The issue was that the window title was too long AND had spaces in it.
             Once I replaced the title with a simple, short string using no spaces it worked.
             I replaced my search code with the more complete version presented by Chris!
          
--------------------------------------------------------------


PBv12.1, b7055

Q:  What am I doing wrong?


App A renames its FRAME window to be unique; appending the session ID.
App A uses the RUN command to start app B.
App B uses FindWindowW() to get a handle to app A, but always fails.

App A Window title:
     50001 - InterconnecT CABS   - (026D - CSGI NTtest (026D-CO))   (Database: DEV12C) 21156

App B knows the title:

Here's the declaration:

// Returns a handle to the named application if it exists/is active
FUNCTION ulong FindWindowW (long classname, string windowname) LIBRARY "user32.dll"


// This is the messageBox shown above:
Messagebox ("W_Invoicing", "Open event - called from ~r~n~t " + gs_cabs_window_name)

Here's the code to find app A:
// Get a pointer to the calling application
ll_seconds = 0
DO
    iui_cabs   = FindWindowW (0, gs_cabs_window_name)
    ll_seconds = ll_seconds + 1
    Sleep (0.5)
LOOP UNTIL(iui_cabs > 0) OR (ABS (ll_seconds) > 10)

Messagebox ("W_Invoicing", "Open event - found the calling window: " + string (iui_cabs))


The value returned is always zero:



I've also tried using this:
FUNCTION ulong FindWindowW (ref string classname, string windowname) LIBRARY "user32.dll"

and

 iui_cabs   = FindWindowW ("w_cabs_frame", gs_cabs_window_name)


Thank You!

Roland Smith Accepted Answer Pending Moderation
  1. Friday, 4 June 2021 17:33 PM UTC
  2. PowerBuilder
  3. # 1

The window class is not the PowerBuilder object name.

All window objects have the same window class:  FNWND3###. I am pretty sure for PB12 it is FNWND3120.

 

Comment
  1. Olan Knight
  2. Friday, 4 June 2021 17:41 PM UTC
Wow! I learn something new EVERY DAY. Thanks! I'll try using that value (FNWND3120).
  1. Helpful
  1. Chris Pollach @Appeon
  2. Friday, 4 June 2021 17:49 PM UTC
Hi Guys;

If you really want to see what is going on inside the Windows O/S ...

http://chrispollach.blogspot.com/2020/08/explorer.html

Regards ... Chris
  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Friday, 4 June 2021 17:27 PM UTC
  2. PowerBuilder
  3. # 2

Thank you, Chris! 

The problem turned out to be that the window title can have no spaces in it. Once I replaced the long title with a simple, short title with no spaces, your code worked perfectly.

I'm also now using your search code as it's more complete than my old version.


// New search code:
String       ls_class               // Windows Class Name
uLong        lul_handle          // Window's "handle"

SetNull (ls_class)               // Set Class to NULL (all)
lul_handle = THIS.FindWindowW ( ls_class, gs_cabs_window_name )       // Try to locate it!
IF (lul_handle = 0) THEN                                                                   // Found?    

    SetNull (ls_class)
   lul_handle = THIS.FindWindowEx (0, 0, ls_class, gs_cabs_window_name )     // NO => Try Extended search!
    IF (lul_handle = 0) THEN
        
        lul_handle = THIS.FindWindowEx (0, 0, 0, gs_cabs_window_name )
        IF (lul_handle = 0) THEN
            
            ls_class   = "w_cabs_frame"
            lul_handle = THIS.FindWindowEx (0, 0, ls_class, gs_cabs_window_name )
            
        END IF
        
    END IF
        
END IF

Comment
  1. Chris Pollach @Appeon
  2. Friday, 4 June 2021 17:36 PM UTC
Hi Olan .. that is "awesome" news!

Glad that I was able to help you upgrade your old code. ;-)
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 4 June 2021 15:56 PM UTC
  2. PowerBuilder
  3. # 3

Hi Olan;

  Here is the code I use for my searching ...

String        ls_class                                                                // Windows Class Name
uLong        lul_handle                                                            // Window's "handle"
SetNull (ls_class)                                                                   // Set Class 2 NULL (all)
lul_handle     =    THIS.FindWindow ( ls_class, as_title )              // Try to locate it!
If  lul_handle    =    0    THEN                                                     // Found?
    lul_handle     =    THIS.FindWindowEx (0, 0, ls_class, as_title )     // NO=>Try Extended search!
END IF
Return      lul_handle


FUNCTION    uLong         FindWindowEx ( uLong hwnd, uLong childAfter, ref string classname, ref string windowname ) LIBRARY "USER32.dll"  ALIAS FOR "FindWindowExW"
FUNCTION    uLong         FindWindowEx ( uLong hwnd, uLong childAfter, long classname, ref string windowname )  LIBRARY "USER32.dll"  ALIAS FOR "FindWindowExW"
FUNCTION    uLong         FindWindowEx ( uLong hwnd, uLong childAfter, ref string classname, long windowname )  LIBRARY "USER32.dll"  ALIAS FOR "FindWindowExW"


HTH

Regards ... Chris

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.