Solved

Need to Find the TWindow that owns a HWND

Posted on 1998-07-24
7
547 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
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
HTML Video won't Autoplay on site 6 39
removing hyperlinks from end-notes in a PDF to HTML conversion 8 120
Download a website to hdd 2 89
Randomize in Owl Carousel v1.3.2 6 100
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…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
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:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

756 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