04140243.txt 14-Apr-00


App handle

If I want to find the handle() of the shellwindow from
anywhere in the thread, can I do that? Sometimes it's
impossible to know how many SELF:Owner:Owner:ow...

--
Jean-Marie Berthiaume

Hi Jean-Marie,

What I do is subclass app. See below

CLASS MyApp INHERIT App

     EXPORT oMainShellW  AS OBJECT

At Start() I assign oMainWin to that iVar
Then I can reach the shell object form anywhere in the app
using GetAppObject()

Func  MyAnyOne()
     LOCAL oShell   AS OBJECT
     LOCAL oApp     AS OBJECT

     oApp := GetAppObject()

     oShell := oApp:oMainShellW

You can do it directly:
     oShell := GetAppObject():oMainShellW
But in VO 2.5 this causes a warning msg that I dont't like

Geoff has pointed out in other thread  that this can be also
done using SysObject() but I have not tryed it.

HTH
Ernesto


Hi Ernesto,

> But in VO 2.5 this causes a warning msg that I dont't like


this easy to prevent, for example you do something like

 oShell := IVarGet(GetAppObject(),#oMainShellW)

or even smarter with

 function MyGetAppObject() as MyAppClass pascal
 return GetAppObject()

 ....
 OShell := MyGetAppObject():oMainShellW
 ....

Regards,
Meinhard


Jean-MarieA possible solution occurs below the line

--------------------------------------------
GLOBAL gAppHandle
GLOBAL gAppDC

FUNCTION Start
LOCAL oShellWindow AS ShellWindow

oShellWindow := ShellWindsow{}

gAppHandle := oShellWindow:Handle(0)
gAppDC      := oShellWindow:Handle(2)

--
HTH
Steve Quinn

Well no.

As I says "find... from anywhere in the thread". With your
solution I found it only at the beginning .

Jean-Marie Berthiaume

Jean-Marie

Just put it in a GLOBAL variable.
GLOBALs are available application wide and you have it no
matter where you are in the app, it's not going to change
for the lifetime of the app (unless you overwrite it or
destroy the shellwindow and you can NULL the thing if you
do)

or
make it an instance variable with an access of your
subclassed shellwindow and instantiate it in the POSTINIT of
the window

Change
    xHandle := self:owner:owner:owner:etc...
    to
    xHandle := gAppHandle
    or
    xHandle := self:Parent()

I did say it was a 'possible' solution
--
HTH
Steve Quinn

Stephen,

> gAppHandle := oShellWindow:Handle(0)
> gAppDC      := oShellWindow:Handle(2)


The SDK only shows Handle(4), which is the MdiClient handle
(ie hWndClient) and anything else is the hWnd. Never a DC.
How is it that you can expect the DC or am I missing
something here?  The SDK code is:

METHOD Handle(nHandleType) CLASS ShellWindow
  VTrace VMethod

  IF !IsNil(nHandleType)
    IF !IsLong(nHandleType)
      WCError{#Handle,#ShellWindow,__WCSTypeError,;

        nHandleType,1}:Throw()
    ENDIF
    IF (nHandleType == 4)
      RETURN hwndClient
    ENDIF
  ENDIF

  RETURN hWnd

Geoff


Geoff,

From the help file :

----------------------------------
ShellWindow:Handle() Method
Syntax

:Handle([]) ---> nHandle

Arguments

 The type of handle required.  Specify 0 for
the window handle and 2 for the window device context.  If
omitted, 0 is the default.

Returns

A handle to the window, describing the underlying system
object.
-----------------------------------

I will be happy to know all the HandleType usable in the
Handle() Method.

Jean-Marie Berthiaume

That's my point.  From the SDK there are only two:

0 - hWnd
4 - hWndclient

Both are handles to the main shellwindow and its primaruy
client MDI window.
I do not understand the full interaction between these two,
except that I need to detect messages for my app with
hWndclient and this is you do window background painting and
graphics. That being the case I don't know what relevance
hWnd has or what it is good for . Maybe some guru on this
stuff can write in and tell us (...please?).

However, 2 is definitely not processed, according to the SDK
- in which case, if it works, then the SDK is wrong. When I
send 2 now, I get a ptr but I get the same pointer as if I
sent 0, 7 or anything else! I am not sure what is going on.

Geoff


Geoff

I just copied the them (0,2 parameters) from the help file,
I didn't investigate further or test the result.
--
HTH
Steve Quinn

Yo! that's cool.

My instinct is always to believe the help file too. And for
98% of the time its definitely correct. But there are a few
inconsistencies like this one and sometimes, even the SDK as
it is delivered to us, is not up to date. But at least
discussions like this can bring such issues to the front.

Now, if we could just get the dev team to peek in here
occassionally
and.....

Jean-Marie:

Try a "pseudo-recursing" function: this will return the
handle for the ShellWindow if there is any in the hierarchy
of ownership or a NULL_PTR if not. (this is from the top of
my mind, so test and debug it).

FUNCTION FindMyShellHandle( oThis AS WINDOW ) AS PTR PASCAL
     LOCAL     ptrRet         AS PTR
     LOCAL     oWin      AS OBJECT
     LOCAL     oOwner         AS OBJECT

     // Just for fun
     ptrRet := NULL_PTR
     oWin := oThis

     // Loop until we find it or give up
     DO WHILE IsInstanceOf( oWin, #Window )
          oOwner := oWin:Owner

          // Just if its a window
          IF IsInstanceOf( oOwner, #Window )
               IF IsInstanceOf( oOwner, #ShellWindow )
                    ptrRet := oOwner:Handle()
                    EXIT
               ENDIF
               oWin := oOwner

          // It's not a window, forget anything else
          ELSE
               EXIT
          ENDIF

     ENDDO

     RETURN ptrRet


HTH,

Amilcar A. Camargo

This is how I do it.
Method Start() Class App

SysObject(AppClassNieuw{})
SysObject():Start()Class AppClassNieuw Inherit App


Protect oShellWindow     as Object


Method Start() Class AppClassNieuw

     Self:oShellWindow := MySW{Self}
     Self:oShellWindow:Show(SHOWZOOMED)


Access ShellWindow Class AppClassNieuw
Return oShellWindow


The I just use the following function

Function GetShellWindow()
Return SysObject():ShellWindow


HTH

Stephen Schlette

I usually put an access in each window that returns the
shell window, like this:

access ssw class MyWindow
    return self:owner:ssw

access ssw class StandardShellWindow
    return self

The nice thing about this solution is that I don't have to
care about where in the hierarcy my window is. The access
method can redirect this call as many times as it wants, it
still returns the shellwindow.

Mathias


Jean-Marie,
I'm using the following function :

FUNCTION RETURNShell() AS ShellWindow
LOCAL oO:=GetFocusedObject() AS OBJECT
    DO WHILE !IsInstanceOf(oO,#ShellWindow)
            oO:=oO:Owner
    ENDDO
    RETURN oO

Guy Deprez,Belgium

    Source: geocities.com/n_s_wong/vo/ng

               ( geocities.com/n_s_wong/vo)                   ( geocities.com/n_s_wong)