Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to set the properties of window by handle in MFC. That is to say, I only know the handle. So , I want to use the handle to set the properties in MFC.Thank you for your help.

What I have tried:

How to set the properties of window by handle in MFC. That is to say, I only know the handle. So , I want to use the handle to set the properties in MFC, I I have used a lot of methods to solve, but failed. Thank you for your help. I I wait for your answer online.
Posted
Updated 9-May-16 6:15am
Comments
Richard MacCutchan 9-May-16 12:09pm    
What properties do you want to set? And what problems did you have?
Sergey Alexandrovich Kryukov 9-May-16 12:09pm    
Everything in a window is accessible through its handle. What exactly you want to achieve?
—SA

1 solution

It depends what you mean by "properties"...

IF you mean Win32 window properties (Window Properties (Windows)[^]) then you can look at the reference above.

IF you mean data stored in the Win32 window structure or WNDCLASS structure then you'll need Set/GetWindowLongPtrPtr or the 32 bit equivalent.

IF you mean the members of an MFC C++ object associated with a given window handle you can use CWnd::FromHandle to get a CWnd pointer from the associated window handle. However there has to be an MFC C++ object associated with the handle - i.e. you've created a CWnd derived object, called Create on that or used some other baroque MFC method of creating the window (or subclassing it, but that's hopefully another story). If there's no MFC object associated with the window handle it'll appear to work but will go horribly wrong.

So the upshot of this lot is if you need a CWnd pointer to do something later stash the address when you create the MFC object and don't rely on being able to recover it later.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900