Professional Web Applications Themes

GrafPtr to WindowRef - Mac Programming

Hi list, I'm new to Mac/Carbon programming (from a Windows background), so sorry if these questions are daft ;) I'm writing a plug-in, where the host software creates a window for my plug-in to display in, and passes me a GrafPtr. Now I need to attach a carbon event handler to this window, but GetWindowEventTarget() returns zero when passed the GrafPtr (presumably because it needs a WindowRef) - How can I obtain a WindowRef for the window? (from the GrafPtr?) Can I get an error code from somewhere when GetWindowEventTarget() fails? (returns zero) So I also figured that if I ...

  1. #1

    Default GrafPtr to WindowRef

    Hi list, I'm new to Mac/Carbon programming (from a Windows background),
    so sorry if these questions are daft ;)

    I'm writing a plug-in, where the host software creates a window for my
    plug-in to display in, and passes me a GrafPtr.

    Now I need to attach a carbon event handler to this window, but
    GetWindowEventTarget() returns zero when passed the GrafPtr (presumably
    because it needs a WindowRef) -

    How can I obtain a WindowRef for the window? (from the GrafPtr?)

    Can I get an error code from somewhere when GetWindowEventTarget()
    fails? (returns zero)

    So I also figured that if I cannot attach a window handler to this
    window, I should be able to create a 'child window' (to move around with
    the 'parent' window), but all attempts to do this just create a window
    relative to the desktop, not the parent window - how do you create a
    'child' window with Carbon?!?

    Using OS10.2.3 w/ CodeWarrior8 btw.

    Many thanks,

    graf.
    graffiti Guest

  2. #2

    Default Re: GrafPtr to WindowRef

    In article <pIBwc.1160$cableinet.net>,
    graffiti <bluefishaudio.com> wrote:
     

    GrafPtr is a pointer to a GrafPort data structure. So,
    GetWindowRefFromPort() should do what you want (the name is from memory,
    but it's named something like that, do a little searching through
    Apple's docs to find it).

    Cheers,
    -- Uli
    Uli Guest

  3. #3

    Default Re: GrafPtr to WindowRef

    Uli Kusterer wrote: 
    >
    > GrafPtr is a pointer to a GrafPort data structure. So,
    > GetWindowRefFromPort() should do what you want (the name is from memory,
    > but it's named something like that, do a little searching through
    > Apple's docs to find it).[/ref]

    Oh yes, found it - GetWindowFromPort() - simple when you know what
    you're looking for :)

    Thanks,

    graf.
    graffiti Guest

  4. #4

    Default Re: GrafPtr to WindowRef

    dans l'article h0Dwc.1247$%cableinet.net, graffiti à
    bluefishaudio.com a écrit le 6/06/04 13:14:
     
    >>
    >> GrafPtr is a pointer to a GrafPort data structure. So,
    >> GetWindowRefFromPort() should do what you want (the name is from memory,
    >> but it's named something like that, do a little searching through
    >> Apple's docs to find it).[/ref]
    >
    > Oh yes, found it - GetWindowFromPort() - simple when you know what
    > you're looking for :)
    >[/ref]

    However there is no guarantee that you will receive carbon events fo rthis
    window. The fact that you have only a grafptr shows that maybe the host app
    is using the WaitNextEvent model rather than the Carbon event.

    What is that app ? Maybe someone can help you further.

    Eric

    Eric Guest

  5. #5

    Default Re: GrafPtr to WindowRef

    In article <pIBwc.1160$cableinet.net>, graffiti
    <bluefishaudio.com> wrote:
     

    I am not sure what a child window is, but there are "window groups"
    APIs (see MacWindows.h) that make it possible for windows to be locked
    together.
    James Guest

  6. #6

    Default Re: GrafPtr to WindowRef

    In article <BCE94539.22877%fr>,
    Eric VERGNAUD <fr> wrote:
     
    > >
    > > Oh yes, found it - GetWindowFromPort() - simple when you know what
    > > you're looking for :)[/ref]
    >
    > However there is no guarantee that you will receive carbon events fo rthis
    > window. The fact that you have only a grafptr shows that maybe the host app
    > is using the WaitNextEvent model rather than the Carbon event.[/ref]

    But if you install a Carbon event handler on that window, it should get
    called before WaitNextEvent. As long as your handler is careful to not
    handle any events that it isn't supposed to handle, everything should
    work fine.

    -Eric

    --
    Eric Albert stanford.edu
    http://rescomp.stanford.edu/~ejalbert/
    Eric Guest

  7. #7

    Default Re: GrafPtr to WindowRef

    Eric Albert wrote: 
    >
    >
    > But if you install a Carbon event handler on that window, it should get
    > called before WaitNextEvent. As long as your handler is careful to not
    > handle any events that it isn't supposed to handle, everything should
    > work fine.
    >
    > -Eric
    >[/ref]

    The event handler attached OK and is being called OK, so that's the
    major hurdle out the way - thanks for your replies :)
    graffiti Guest

  8. #8

    Default Re: GrafPtr to WindowRef

    In article <BCE94539.22877%fr>,
    Eric VERGNAUD <fr> wrote:
     

    Doesn't matter. Carbon Events are dispatched from inside
    WaitNextEvent(), too. You can mix-and-match old style events and Carbon
    events freely.

    Cheers,
    -- Uli
    Uli Guest

  9. #9

    Default Re: GrafPtr to WindowRef

    graffiti <bluefishaudio.com> wrote:
     

    Just a quick note that you are not guaranteed to get a WindowRef back
    from GetWindowFromPort.

    The GrafPtr could be for an off-screen graphics world.

    The doentation for GetWindowFromPort probably says that.

    --
    net http://www.mts.net/~gbeggs1/
    Gerry Guest

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139