Solved

Need to Find the TWindow that owns a HWND

Posted on 1998-07-24
7
540 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now