1. Subrat patra
  2. PowerBuilder
  3. Thursday, 11 January 2024 13:28 PM UTC

Hi All,

In our application we are using FindWindowA() function which is correctly working on PB2019. When I migrate it into PB2022, looks like this is not working.

Do I need to change anything to work on PB2022 version?

 

 

 

We have not done any changes to the code, just migrated to PB2022. 

Please help.

 

Regards

Subrat

 

 

Accepted Answer
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 12 January 2024 15:07 PM UTC
  2. PowerBuilder
  3. # Permalink

HI Subrat;

  FYI: These are the External Declarations that I use in my STD Framework for a FindWindow call ...

  • FUNCTION uLong FindWindow ( ref String classname, ref string windowname ) Library "USER32.DLL" ALIAS FOR "FindWindowW"
  • 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"

   FWIW: The above SDK calls are all working perfectly in both 32 bit and 64 bit Apps built from the framework.

   Note: When you call the FindWindow SDK though, you need to nullify the ClassName. For example:

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

The above example is actual code from the STD framework.  HTH

Regards ... Chris

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 11 January 2024 14:22 PM UTC
  2. PowerBuilder
  3. # 1

The arguments should not be defined as by reference, see the documentation:

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-findwindoww

I would do it like this:

Function longptr FindWindow ( string lpClassName, string lpWindowName ) Library "user32.dll" Alias For "FindWindowW"

 

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 11 January 2024 13:41 PM UTC
  2. PowerBuilder
  3. # 2

Hi Subrat;

  Your Apps should not be using any old ANSI SDK calls for a long time now that PB is Unicode.

  In your case, change the SDK call to use a FindWindowW() call instead. HTH

Regards ... Chris 

Comment
There are no comments made yet.
Subrat patra Accepted Answer Pending Moderation
  1. Friday, 12 January 2024 10:50 AM UTC
  2. PowerBuilder
  3. # 3

Hi Roland,

I have changed to use FINDWINDOWA() , but no luck. I am not sure why the same code is working on PB2019, now after migrating this to PB2022, its not working. Is this windowname and classname are registered somewhere ? Can I see those?

 

Regards

Subrat

 

Comment
  1. Roland Smith
  2. Friday, 12 January 2024 15:15 PM UTC
Change ClassName to longptr and pass zero. The classname for windows probably changed between PB versions.
  1. Helpful
There are no comments made yet.
Subrat patra Accepted Answer Pending Moderation
  1. Friday, 12 January 2024 11:01 AM UTC
  2. PowerBuilder
  3. # 4

Hi Chris,

 

I have changed the logic but no luck.

Is this windowname and classname registered somewhere ? I need to check how it stored in Pb2019 and PB2022.

 

Regards

Subrat

 

Comment
  1. Andreas Mykonios
  2. Friday, 12 January 2024 11:52 AM UTC
Have you tried to call GetLastError to see if any error occuered?

Andreas.
  1. Helpful
  1. Andreas Mykonios
  2. Friday, 12 January 2024 12:05 PM UTC
By the way, in PB's help, while looking at handle method, FindWindowW is declared as: FUNCTION unsignedlong FindWindow (long classname, string windowname) LIBRARY "user32.dll" ALIAS FOR FindWindowW (https://docs.appeon.com/pb2022r3/powerscript_reference/handle_func.html).

Andreas.
  1. Helpful
There are no comments made yet.
Subrat patra Accepted Answer Pending Moderation
  1. Friday, 12 January 2024 18:45 PM UTC
  2. PowerBuilder
  3. # 5

Thanks a lot. I set the classname as null and it worked. Thanks a lot.

Comment
  1. Chris Pollach @Appeon
  2. Friday, 12 January 2024 20:26 PM UTC
HI Subrat;

That is "awesome" news .. thanks for the update! :-)

Yes, that NULL is an important setting. I found that out over 5+ years ago when I first started to support W10.

Regards ... Chris
  1. Helpful
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.