Click here to Skip to main content
15,920,217 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: ATL COM Pin
vishalmore7-Feb-05 20:30
vishalmore7-Feb-05 20:30 
GeneralRe: ATL COM Pin
vishalmore8-Feb-05 2:58
vishalmore8-Feb-05 2:58 
GeneralSTL Vector sort, memory corruption Pin
Ron Arnan1-Feb-05 10:50
Ron Arnan1-Feb-05 10:50 
GeneralRe: STL Vector sort, memory corruption Pin
Joaquín M López Muñoz2-Feb-05 2:28
Joaquín M López Muñoz2-Feb-05 2:28 
GeneralRe: STL Vector sort, memory corruption Pin
Ron Arnan2-Feb-05 3:55
Ron Arnan2-Feb-05 3:55 
GeneralRe: STL Vector sort, memory corruption Pin
Jörgen Sigvardsson2-Feb-05 10:57
Jörgen Sigvardsson2-Feb-05 10:57 
GeneralRe: STL Vector sort, memory corruption Pin
Joaquín M López Muñoz2-Feb-05 21:59
Joaquín M López Muñoz2-Feb-05 21:59 
GeneralWTL work around WM_NOTIFY Pin
conman1101-Feb-05 7:03
conman1101-Feb-05 7:03 
Hi,

I came up with a way how to call member functions directly so sending WM_NODIFY messages is no longer neccessary and I am interested in your opinions!

I have a MDI window (derived from CMDIFrameWindowImpl) that notifies the active MDI child (CChildFrame derived from CMDIChildWindowImpl) if its document should be opened/saved/reopened ect...

The only way I knew to do this was to send the MDI child a WM_NOTIFY message with different notification code and NMHDR*.

I thought it would be nice to call member function like Save(), Open(CString file),... directly on the CChildFrame object because it would be a lot easier to read and the casting of NMHDR* would no longer be neccessary.

So here is the code:
<br />
// The notification code<br />
#define	ATL_GET_THIS 100 <br />
<br />
template<typename T><br />
T* AtlGetObject(HWND hWnd) <br />
{<br />
  NMHDR nmhdr = { hWnd, 0, ATL_GET_THIS };<br />
  return (T*)(::SendMessage(hWnd, WM_NOTIFY, 0, (LPARAM)&nmhdr));<br />
}<br />


The CChildFrame must handle the ATL_GET_THIS notification:
<br />
BEGIN_MSG_MAP_EX(CChildFrame)<br />
...<br />
NOTIFY_CODE_HANDLER_EX(ATL_GET_THIS, _AtlOnNotifyGetThis) <br />
...<br />
END_MSG_MAP()<br />
<br />
LRESULT _AtlOnNotifyGetThis(NMHDR* /*phdr*/) { return (LRESULT)this; }


So the code in the parent to call some member function in the active MDI child would look like this:

<br />
CChildFrame* pWndChild = AtlGetObject<CChildFrame>(MDIGetActive());<br />
<br />
CString sFilename = pWndChild->GetFilename();<br />
CFileDialog dlg(FALSE, 0, sFilename);<br />
if (dlg.DoModal() == IDOK)<br />
{<br />
   pWndChild->SaveAs(dlg.m_ofn.lpstrFile);<br />
}  <br />


What do you say?
I know it works, but are there some traps I didn't see? And if this is a good idea, why is nothing like this in the ATL/WTL already? Or there is and I didn't see it?

Thanks for your time!
Constantin
GeneralEnvDTE::Document.Open returns null Pin
JabraJabra1-Feb-05 6:12
JabraJabra1-Feb-05 6:12 
Generalget project full name Pin
JabraJabra1-Feb-05 2:49
JabraJabra1-Feb-05 2:49 
GeneralTBN_DROPDOWN : Problems with dropdown button in ATL Pin
tnguyen44431-Jan-05 10:16
tnguyen44431-Jan-05 10:16 
GeneralRe: TBN_DROPDOWN : Problems with dropdown button in ATL Pin
Michael Dunn31-Jan-05 11:14
sitebuilderMichael Dunn31-Jan-05 11:14 
GeneralCstring with ATL Pin
JabraJabra31-Jan-05 4:24
JabraJabra31-Jan-05 4:24 
GeneralRe: Cstring with ATL Pin
Ralph Wetzel31-Jan-05 5:49
Ralph Wetzel31-Jan-05 5:49 
GeneralRe: Cstring with ATL Pin
ThatsAlok31-Jan-05 18:09
ThatsAlok31-Jan-05 18:09 
GeneralRe: Cstring with ATL Pin
conman1101-Feb-05 2:12
conman1101-Feb-05 2:12 
GeneralRe: Cstring with ATL Pin
ThatsAlok1-Feb-05 2:54
ThatsAlok1-Feb-05 2:54 
GeneralRe: Cstring with ATL Pin
JabraJabra31-Jan-05 20:36
JabraJabra31-Jan-05 20:36 
Generalfindresource return null Pin
JabraJabra30-Jan-05 0:57
JabraJabra30-Jan-05 0:57 
GeneralParameter problem Pin
Monty229-Jan-05 22:14
Monty229-Jan-05 22:14 
GeneralRe: Parameter problem Pin
Jörgen Sigvardsson29-Jan-05 22:32
Jörgen Sigvardsson29-Jan-05 22:32 
GeneralRe: Parameter problem Pin
Monty229-Jan-05 22:40
Monty229-Jan-05 22:40 
GeneralFindResourceEx Pin
GanescuC27-Jan-05 23:36
GanescuC27-Jan-05 23:36 
QuestionHow to get the active project in visual studio Pin
JabraJabra26-Jan-05 21:51
JabraJabra26-Jan-05 21:51 
AnswerRe: How to get the active project in visual studio Pin
Stuart Dootson27-Jan-05 21:01
professionalStuart Dootson27-Jan-05 21:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.