Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Need to Find the TWindow that owns a HWND

Posted on 1998-07-24
7
546 Views
Last Modified: 2013-12-26
I'm converting an app from MFC 4.0 to OWL 5 and need to know how to do the following: -

MFC provides a static member function of the CWnd class that returns a pointer to the CWnd object that is attached to a specific HWND.  If no object is attached, NULL is returned.  This is useful when the Cwnd (TWindow ?) object does not directly create the actual window, but rather is passed a handle to an already existing window and you want to verify that the handle is not already assigned to an object.

 Its declaration is: -
static CWnd * CWnd::FromHandlePermanent(HWND hWnd)

Is there a similar functionality within OWL ?  I've gone over the TWindow class and can't seem to find anything similar.

Thanks.
0
Comment
Question by:brosenb0
  • 5
  • 2
7 Comments
 
LVL 2

Expert Comment

by:duneram
ID: 1299723
I am not aware of a way to do this in OWL, but if you wanted to find the child windows for a parent you could use the EnumChildWindows api.
0
 
LVL 2

Expert Comment

by:duneram
ID: 1299724
Another way to do this is

You have a  HWND for a window but don't know which TWindow it is tied to, right?

Well if you have a list of TWindows, you could always traverse the list until the hwnd values matched....




0
 
LVL 2

Accepted Solution

by:
duneram earned 50 total points
ID: 1299725
If you use the TWindow(HWND x, ...) constructor, it will attach a TWindow object to the HWND using the wfAlias flag.  This is not quite the same functionality, but it may work in your case.

On further examination it looks like you should use the  AttachHandle method to accomplish the same feat.  AttachHandle is a method of TWindow that will give you a TWindow for a given HWND.  You can look in the Init method to see how it works.


0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 3

Author Comment

by:brosenb0
ID: 1299726
There's a couple of small problems: -

1) What if I don't have a list of TWindows and need to build that first ?

2) I can't find a method TWindow::AttachHandle(HWND).

3) TWindow::Init is protected and is meant to be called by a derived class's constructor, which basically boils down to a whole lot more coding.  It also means the HWND has to be available when the TWindow is created.

From what I can see OWL is not flexible enough to do the job without a substantial amount of work, so I will recommend that we stick with MFC.  At least we can use the Borland (Inprise ?) compiler to build MFC based code and won't have to wait for several weeks for it to compile.

Thanks anyway.
0
 
LVL 2

Expert Comment

by:duneram
ID: 1299727
the attachhandle is part of the TWindow Class, it calls Init  I found it in window.cpp  I will verify this in a few hours as I am upgrading my disks and my compilers are temporarily not available on the computer (the disk has been removed temporarily).

If you do a find and hunt for files containing attachhandle you will see it.  

Attach handle is there.  all you have to do is call it.
0
 
LVL 2

Expert Comment

by:duneram
ID: 1299728
here is some extracted code from window.cpp:

void
TWindow::AttachHandle(HWND handle)
{
  ClearFlag(wfDetached);
  ::FreeInstanceThunk(Thunk);
  Thunk = 0;
  Init(handle, GetModule());
}

and this is the Init you end up calling:

void
TWindow::Init(HWND handle, TModule* module)
{
}

Borland originally added this for Delphi/Owl applications...

0
 
LVL 3

Author Comment

by:brosenb0
ID: 1299729
I found AttachHandle in the window.cpp file in the OWL source dir and it looks like it will do the job.  The only problem I'm left with is finding the TWindow *.  The reason I need to be able to do this is because I'm writing a DLL that has to provide a callback function  for the Windows C interface.  Windows passes a HWND which I have to associate with a TWindow.  There is a protected TWindow member function,
TWindow * GetWindowPtr(HWND), however, it calls the TApplication Object (I don't have one because its a DLL).  In any case I can't call it with any old TWindow * because its protected.  Perhaps I could over-ride the access specifier in a derived class eg.

class derived : public TDialog
{
public:
    TWindow * TWindow::GetWindowPtr(HWND)  
}

I'm not sure if this is legal.  Any thoughts ?

Thanks for the assistance.  
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question