Page 1 of 1

How can I get PB window of an NSWindow?

Posted: Fri Feb 28, 2020 8:49 pm
by Wolfram
Is there a way to get the PB internal handle of an NSWindow?
The opposed of WindowID()

Re: How can I get PB window of an NSWindow?

Posted: Fri Feb 28, 2020 10:39 pm
by Shardik
You may take a look into mk-soft's cross-platform system module and call procedure System::WindowPB(WindowHandle). For your conveniance I have extracted the essential MacOS parts into the following example:

Code: Select all

ImportC ""
  PB_Object_EnumerateStart(PB_Objects.I)
  PB_Object_EnumerateNext(PB_Objects.I, *ID.Integer )
  PB_Object_EnumerateAbort(PB_Objects.I)
  PB_Window_Objects.I
EndImport

Procedure GetPBWindowIDFromWindowHandle(WindowHandle.I)
  Protected Result.I = -1
  Protected PBWindowID.I

  PB_Object_EnumerateStart(PB_Window_Objects)

  While PB_Object_EnumerateNext(PB_Window_Objects, @PBWindowID)
    If WindowHandle = WindowID(PBWindowID)
      Result = PBWindowID
      Break
    EndIf
  Wend

  PB_Object_EnumerateAbort(PB_Window_Objects)

  ProcedureReturn Result
EndProcedure

OpenWindow(3, 270, 100, 200, 170, "Test")
MessageRequester("Info",
  "PB WindowID = " + Str(GetPBWindowIDFromWindowHandle(WindowID(3))))

Re: How can I get PB window of an NSWindow?

Posted: Sat Feb 29, 2020 9:40 am
by Justin
Or you can save it first and then retrieve it:

Code: Select all

EnableExplicit

Define.i win

win = OpenWindow(#PB_Any, 10, 10, 600, 400, "test")
Debug win
objc_setAssociatedObject_(WindowID(win), "_PBWinID", win, 0)

MessageRequester("Info", "PB WindowID: " + Str(objc_getAssociatedObject_(WindowID(win), "_PBWinID")))

Re: How can I get PB window of an NSWindow?

Posted: Sat Feb 29, 2020 10:42 am
by Wolfram
Shardik wrote:You may take a look into mk-soft's cross-platform system module and call procedure System::WindowPB(WindowHandle). For your conveniance I have extracted the essential MacOS parts into the following example:
Thanks Shardik. I didn't notice mk-soft's post.