Solved

Need to Find the TWindow that owns a HWND

Posted on 1998-07-24
7
537 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WSDL Soap Error 12 244
Simple PHP - search by location postcode/zip code 8 29
RSS Feeds--IE 13 150
ASP.NET ReportViewer from WebMethod. 14 184
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

757 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

19 Experts available now in Live!

Get 1:1 Help Now