|
overriden OnCreate of your view class and change it to this:
int CYourView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
lpCreateStruct->style |= LVS_REPORT;
if (CListView::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Thank you thank you thank you thank you thank you
(and I didn't use copy and paste there either!)
It works great! Thank you!
skydiving....if at first you don't succeed, you're fecked!
|
|
|
|
|
In MFC Doc/View SDI or MDI application, every command message sent by menu items or buttons in a toolbar can be routed to CMainFram::OnCmdMsg(..) function. Howevey, if I want to menually send a command message using:
<br />
SendMessage(AfxGetMainWnd(), WM_COMMAND, ID_MYCOMMAND, 0);<br />
or using
<br />
PostMessage(AfxGetMainWnd(), WM_COMMAND, ID_MYCOMMAND, 0);<br />
this message doesn't get routed to CMainFram::OnCmdMsg(..). Why? In other words, how can I simulate the menu command message using SendMessage or PostMessage?
|
|
|
|
|
You're sending/posting the message correctly. However, you need a handler of the form:
ON_COMMAND(ID_MYCOMMAND, OnMyCommand) /ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Thanks. I did have the command handler. The message sent by SendMessage or PostMessage did get routed to CMainFrame::OnCommand(...) function not CMainFrame::OnCmdMsg(...). But the message sent by a menu item gets routed to CMainFrame::OnCmdMsg(...). What I am wondering is that the difference between those two mechanism.
|
|
|
|
|
Hmmm, that's odd. The command handler for IDC_MYCOMMAND should get called for the menu item IDC_MYCOMMAND. Perhaps the notification isn't being passed down the chain.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
The command handler gets called actually for either mechanism but it seems so via different road. Menu command thru OnCmdMessage, and mannually sent command thru OnCommand.
The reason I ask this question is that the command handler may be located in a View or Doc class, not necessary in CMainFrame class, if the menually sent command message is routed to CMainFrame::OnCmdMsg function, then I had the chance to forward the message to other classes capable of handling message.
|
|
|
|
|
as far as I can see all WM_COMMAND messages gets routed to the receiving windows' OnCommand handler, which in turn calls OnCmdMsg (provided some prerequisites are present).
Call stack:
CCmdTarget::OnCmdMsg
CWinApp::OnCmdMsg
CWnd::OnCmdMsg
CView::OnCmdMsg
CFrameWnd::OnCmdMsg
CWnd::OnCommand
CFrameWnd::OnCommand
CWnd::OnWndMsg
CWnd::WindowProc
AfxCallWndProc
AfxWndProc
So your SendMessage and your menu selection should all be routed through OnCommand first and then to OnCmdMsg. You could put a breakpoint in OnCmdMsg and check on the call stack that OnCmdMsg is called from OnCommand in both instances.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Steen Krogsgaard wrote:
So your SendMessage and your menu selection should all be routed through OnCommand first and then to OnCmdMsg. You could put a breakpoint in OnCmdMsg and check on the call stack that OnCmdMsg is called from OnCommand in both instances.
I did exactly what you described above but I did not see the command got routed to OnCmdMsg. However, it did get routed to OnCommand function. Odd, huh.
Is there any difference between menu sent message and message sent by SentMessage or PostMessage?
|
|
|
|
|
I made a little test program with three menu items: The Option, Post It and Send It. The Option just displays a message box. Post It and Send It posts or sends a WM_COMMAND with IDC_THE_OPTION as wParam to the AfxGetMainWnd() window. I have overriden the view OnCmdMsg and the framewnd OnCmdMsg (it's a SDI app) and put traces in if IDC_THE_OPTION (or any of the other two menu items) passes through.
I get what I'd expect: Everything goes through first CFrameWnd::OnCmdMsg and the CView::OnCmdMsg. So there must be something else "wrong" with your app.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I appreciated your helped me on this question. I used an MDI app and overriden the CMainFrame's OnCommand. To test if the command message is routed to this function I used an IF statement to see the command ID.
I am wondering if you could make a test MDI program on this point, zipped it and sent it to me via email to convince me?
Thank you so much!
|
|
|
|
|
I tried to mail the MDI program to you but your mailer won't allow a 5 meg zip attach.
Anyway, the result is that invoking the command through a menu selection or through SendMessage/PostMessage yield identical call patterns. CMainFrame::OnCommand is called, followed by CChildFrame::OnCommand, which calls CChildFrame::OnCmdMsg and CView::OnCmdMsg. CMainFrame::OnCmdMsg is not called because CChildFrame::OnCmdMsg handles the command (returns TRUE) and thereby shortcuts CMainFrame::OnCommand.
One thing that may confuse you is that ON_COMMAND_UI handling is routed through some of the same pathway, namely CMainFrame::OnCmdMsg, CChildFrame::OnCmdMsg and finally CView::OnCmdMsg. Here only the menu selection invocation will cause this chain to be called, as SendMessage/PostMessage does not relate to the UI and hence does not provoke UI updating. So if you just checked whether CMainFrame::OnCmdMsg was called at all you'd see a difference between menu selection and Send-/PostMessage, but that's not for the WM_COMMAND message, thats for MFC's private UI update mechanisms (illustrated by the fact that OnCommand is not called in response to UI updates).
This is the best I can do. If you are absolutely sure that WM_COMMAND send by a menu and send by Send-/PostMessage leads to different call stacks I suggest you write a minimum program to reproduce the problem and send it to me or to this forum (oops! I just recommended posting code, sorry!!!)
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I am very convinced by your explanation here. Thank you so much!
Have a nice weekend.
|
|
|
|
|
Does VC7 offer support for WinXP-64/Itanium targets?
Thanks,
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
|
Hi,
I want to pass metafile to my ATl control ( from an MFC client), is there any easy way to do that, something pretty cool would be like:
MyAtlCtrlInstace->PassMetafile(hMyMetafile) ( VT_METAFILE)
But it seems that I have to use IOleDataObject ( but I don´t want drag and drop and that stuff just directly call it from the client!!!!), is there any easy way to do that ?, if not... which method should I override from IOleDataObjectImpl ?
Thanks in avance, Bye !
Braulio
|
|
|
|
|
Sorry to disappoint you that I don't know the answer but I can help you in another way,because it seems you are really in trouble;) (2 or 3 message about this problem in disccution board)
Anyway,Have you read Dr.Grimes books about ATL programming?(wrox publisher)There are two version ,one for Begginers and another one is for prof. I have the begginer version but there is nothing useful about this subject in it,maybe if you find prof. one it can help you.
I also have Dr.Grimes email address,one time he helped me to solve my problem in ATL ,if you want I can send it for you,I think he helps you
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Hi,
Anyway thanks for your help ( yes I feel like a dummy sorry , just posting posting..., aaaah !).
Sometimes to do something wiht ATL looks like weird or complicated but.... well... just give a metafile !!! oh my god !... I think I´m going bananas
If you can give me the address of Dr. Grimes I will send one e-mail, but I don´t know if he will answer me...
Thanks anyway, Bye !
Braulio
|
|
|
|
|
atl.dev@grimes.demon.co.uk
If you ask how should I write my project,he won't answer.Ask your question as you ask them here,"SHORT" and "COMPLETE",he answers the questions that thier answers are one or two line,just like this question
Good luck
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
I'm having some problems with inheritance and virtual functions. Supose the following classes:
class CMyClass
{
virtual void DoSomething() = 0;
}
class CMyDialog : public CDialog, public CMyClass
{
void Init()
{
m_oUsingClass.Init(this);
}
virtual void DoSomething()
{
}
CUsingClass m_oUsingClass;
}
class CUsingClass
{
void Init(CWnd *pWnd)
{
m_pWnd = pWnd;
m_pMyClass = (CMyClass *)pWnd; // error - it doesn't work
m_pMyClass->DoSomething(); // error - caused by prior error
}
CWnd *m_pWnd;
CMyClass *m_pMyClass;
}
When I assign "m_pMyClass = (CMyClass *)pWnd;" it doesn't work. So I can't call virtual function DoSomething() defined in CMyDialog class.
How can I do this?
What I need is to have a class (CMyDialog) that is derived from CDialog and CMyClass and in another class (CUsingClass) I need to access CDialog and CMyClass (passed by "this" parameter in m_oUsingClass.Init(this)). Can I do it simply passing this as CWnd * or I need to have two parameters in CUsingClass::Init(CWnd *, CMyClass *) and I have to pass "this" parameter twice in CMyDialog (m_oUsingClass.Init(this, this))?
If you have any idea about how can I do this, or if you know where can I get documentation explaining why this doesn't work, I would appreciate.
Thanks
Vanessa
|
|
|
|
|
Try this:
m_pMyClass = dynamic_cast<CMyClass *>(pWnd);
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
IMHO, the *real* problem you have here is trying to use a "CMyClass" polymorphically as a CWnd. Why? This does not make a lot of sense. A CWnd is *not* a CMyClass. Trying to cast your way out of that situation is not a good idea. Are there going to be other types of CWnd's muliply inherited from CMyClass? If so, are some of them not CDialogs? For example, do you plan on passing in a CView that also inherits from CMyClass? If that is your goal, than I would seriously suggest you reconsider your design.
If not, than I would suggest getting rid of the attempt at polymorphism based upon CWnd. If you have a set of dialogs that need this polymorphic behavior than you should base your polymorphic behavior on that class.
i.e.
Init( CMyDialog* pmydlg )
{
pmydlg->DoSomething();
}
Since a CMyDialog *is* a CMyClass this is straight forward...
I think you are going to get yourself into a lot of trouble trying to do things the way you are.
"Thank you, thank you very much" Elvis.
|
|
|
|
|
I have created an MDI application with appwizard.
In MyProgram.cpp in initinstance I register the applications
document templates. I want to open the document from a menu item.
The problem is that the document is opened everytime I execute
the program. How can I avoid this?
|
|
|
|
|
To create a new doc/view at a later time save the doc template pointer in your applications header file:
CMultiDocTemplate *m_pMyDocTemplate; Use it when the doc template is created:
m_pMyDocTemplate = new CMultiDocTemplate(
IDR_TARGETTYPE,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CMyView));
AddDocTemplate(m_pMyDocTemplate); When you are ready to create a new doc/view call this:
m_pMyDocTemplate->OpenDocumentFile(NULL, TRUE); If you call AddDocTemplate() above you do not have to delete the m_pMyDocTemplate pointer when the application ends. If you don't call AddDocTemplate() you will need to delete the m_pMyDocTemplate pointer.
To keep the default new doc/view from showing add the code below:
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if(cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
if (!ProcessShellCommand(cmdInfo))
return FALSE; Hope this helps.
Jonathan Craig
www.mcw-tech.com
|
|
|
|
|
Arrgghhh!!!! Can anyone tell me what I'm doing wrong or let me know that I'm not lossing my mind?
I have some code, does nothing fancy, compiles fine normally, but today when I compile I get the following:
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\crtdbg.h(536) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type<br />
C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\crtdbg.h(536) : error C2059: syntax error : 'newline'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(674) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(674) : error C2059: syntax error : 'newline'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(674) : error C2238: unexpected token(s) preceding ';'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(675) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(675) : error C2059: syntax error : 'newline'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(675) : error C2238: unexpected token(s) preceding ';'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(683) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(683) : error C2059: syntax error : 'newline'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(683) : error C2238: unexpected token(s) preceding ';'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(1631) : error C2833: 'operator DEBUG_NEW' is not a recognized operator or type<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afx.h(1631) : error C2059: syntax error : 'newline'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(122) : error C2059: syntax error : 'string'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(123) : error C2091: function returns function<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(123) : error C2802: static member 'operator new' has no formal parameters<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(123) : error C2333: 'new' : error in function declaration; skipping function body<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(131) : error C2059: syntax error : 'string'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(131) : error C2091: function returns function<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(131) : error C2802: static member 'operator new' has no formal parameters<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(135) : error C2059: syntax error : 'string'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(135) : error C2091: function returns function<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(135) : error C2556: 'void *(__cdecl *__stdcall CNoTrackObject::operator new(void))(unsigned int,const char *,int)' : overloaded function differs only by return type from 'void *(__c<br />
decl *__stdcall CNoTrackObject::operator new(void))(unsigned int)'<br />
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtls_.h(131) : see declaration of 'new'<br />
E:\develop\absolve\absolve\MainMenuView.cpp(29) : error C2660: 'new' : function does not take 3 parameters<br />
Error executing cl.exe.
Nothing's been changed in the code, so I can't see what the hell I've done, and I can't make it go away!
Any ideas folks?
Dylan Kenneally
London,UK
|
|
|
|