|
Hello,
I have created a menu in my Application class and one of my child windows have that menu when the child window is created.
How do I create object Ids for the menu options so that I can write function handlers for the menu option through class wizard by selectiong those object Ids.
Or Is it that I cannot go through the class wizard route if I have created my menu through CMenu class.
Thanks
Prithaa
|
|
|
|
|
prithaa wrote: I have created a menu in my Application class
Do u have the menu in the resource or you dynamically created it?
nave
|
|
|
|
|
Hello,
Thanks for your reply
I created the menu using CMenu class.
CMenu M;
M.CreateMenu();
M.AppendMenu(MF_POPUP ,IDR_STRING142,(LPCTSTR)"Demand");
M.AppendMenu(MF_STRING ,IDS_STRING143,(LPCTSTR)"Supply");
M.AppendMenu(MF_STRING ,IDS_STRING144,(LPCTSTR)"Cost");
And I added these IDS_STRING142 in the string Table.
Now I want Object Ids to write sunction handlers for the above menu options
Prithaa
|
|
|
|
|
When a menu is clicked, a WM_COMMAND message is send to the parent window of that menu. So handle the WM_COMMAND message ( overide the OnCommand if your using MFC dialog ) in the parent window.
BOOL CMyDlg::OnCommand(WPARAM wParam, LPARAM lParam) <br />
{<br />
if( HIWORD(wParam) == 0 )<br />
{<br />
if ( LOWORD(wParam) == IDR_STRING142 )<br />
{<br />
}<br />
else if ( LOWORD(wParam) == IDS_STRING143 )<br />
{<br />
}<br />
....<br />
}<br />
return CDialog::OnCommand(wParam, lParam);<br />
}
nave
|
|
|
|
|
Hello,
Thanks Naveen.
This should work I'll try. I just forgot about WM_COMMAND messages.I could not think out of MFC's and got lost in the class wizard ,I suppose
Anyway thanks Bye
Thanks
|
|
|
|
|
prithaa wrote: Thanks Naveen.
And with my previous post I made my post count 1000
nave
|
|
|
|
|
Hello,
Oh that's great.
And I was a part of it.
You seem to be an active member of codeproject.
All the best for all your pojects.
Thanks ,WM_COMMAND worked.I am going ahead with your advice.
Bye
|
|
|
|
|
Is there anyway to detect virus in a usb device using mfc?
|
|
|
|
|
I think if virus detection would be that easy then we wouldn't have to pay companies for writing anti virus software
|
|
|
|
|
GetVirusInfo() must help you. If you want the name of the virus too, use GetVirusInfoEx()
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
Is it possible for me to override GetVirusInfo();;)
|
|
|
|
|
brahmma wrote: GetVirusInfo() must help you. If you want the name of the virus too, use GetVirusInfoEx()
Do we also have access to SetVirusInfo() and SetVirusInfoEx() ? It doesn't make any sense to get your virus information if you have not set it correctly to begin with.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Do we also have access to SetVirusInfo() and SetVirusInfoEx()?
Yes, but it's a PITA now with all the UAC business...
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hi everybody,
if a key is stroken, the message is catched into the current view.
PreTranslateMessage sends the message to the class-parents (View->CFormView->...)
If the message isn't "used" it should return FALSE and at the end the Parent of
the current view gets the message, send it's to his parent-classes and so on...
If i hit for example the R-key the message travels down to the class-parents and returns
TRUE in the function IsDialogMessage. So the parent-views doesn't get this message.
My structure is Frame -> View1 -> TabWnd -> View2 ... if i hit the R-Key in View2 the message
should travel till View1 where i catch it and return TRUE
Big thanks in advance
|
|
|
|
|
baerten wrote: if i hit the R-Key in View2 the message
should travel till View1 where i catch it and return TRUE
Handle the WM_GETDLGCODE message in the view2 and return 0 when the message is WM_KEYDOWN and key is "R".
nave
|
|
|
|
|
Yes thats a possibility, but if i have the View1 with all the keystrokes (10 for example)
And 15 possible View2's (View2 is loaded in circumstance of the keystroke )
I need to add all 10 keystrokes into all 15 Views ...
And a generally WM_KEYDOWN return TRUE is also not the solution, because the parent-class of
all my views handles for example the ESCAPE Key...
Mmh, but nevertheless Thanks for your help
|
|
|
|
|
Why coudnt you overide the PreTranslateMessage() in the app class and handle the keystrokes there itself?
nave
|
|
|
|
|
Thats doesn't work
Because the message must travel to the bottom of hierarchy, for example to put the
Key into the textbox. If i send the KeyDown directly to my own Basic-View, the textboxes
will never be filled
Thanks anyway
|
|
|
|
|
I never said not to send the message to the child window. I mean to do as below
BOOL CMyApp::PreTranslateMessage(MSG* pMsg) <br />
{ <br />
BOOL bRetun = CWinApp::PreTranslateMessage(pMsg);<br />
<br />
if( pMsg->message == WM_KEYDOWN && )<br />
{<br />
}<br />
return bRetun;<br />
}
nave
|
|
|
|
|
I made it now in this way,
the base class of all my view has now this line in PreTranslateMessage:
if(pMsg->message == WM_KEYDOWN) {
if(pMsg->wParam == ...
if( ...
CWnd *Parent = GetParent();
if(Parent)
Parent->PreTranslateMessage(pMsg);
return CFormView::PreTranslateMessage(pMsg);
}
the same in the TabWnd and it seems to work. Propably it has some side effects.
To send the message from out CMyApp to the view1 is a solution, but only for a specific case.
If i have the same problem in another structure of View->Tab->View->Tab->View the CMyApp
needs to check from which tree the message comes and send it to the right view...
But big thanks for your help
|
|
|
|
|
baerten wrote: if(Parent) Parent->PreTranslateMessage(pMsg);
whats problem in sending the message directly to the view1?
nave
|
|
|
|
|
For the customers i have for example this structure :
Frame->View1->Tab->View2->Tab->View3->Tab->View4 ( crazy, i know LOL )
for the articles i have for example Frame->View1->Tab->View2->Tab->View3
and the Keystrokes should be catched at different locations ( Customers at View1 and Articles at View2 )
so the CMyApp needs to know which view should receive the message.
With a GetParent()->PreTranslateMessage the Message travels directly down and stops
where it's needed.
I hope you understand it. My structure of the programm is a little bit strange
Because there are a huge of sub-views in tabs, and the active tab should open via the
first view another view in one of the Tab-Windows...
Have a nice day
Greetings
|
|
|
|
|
Hi,
I need to convert .txt format file to .xls(excel) format file upon a click on the button in a dialog box.
Any APIs regarding This ?
plz help me.
thanks in advance.
|
|
|
|
|
See here[^] if any helpfuls.
|
|
|
|
|
You can do this with Excel Automation. Something like:
_Application app;
Workbooks books;
_Workbook book;
COleVariant vtOptional((long) DISP_E_PARAMNOTFOUND, VT_ERROR),
vtTrue((short) TRUE),
vtFalse((short) FALSE);
if (app.CreateDispatch("Excel.Application") == TRUE)
{
books = app.GetWorkbooks();
book = books.Open("c:\\book1.txt", COleVariant((long) 0), vtFalse,
COleVariant((long) 2), vtOptional, vtOptional, vtTrue,
vtOptional, vtOptional, vtOptional, vtOptional, vtOptional,
vtFalse);
book.SaveAs(COleVariant("c:\\book1.xls"), COleVariant((long) -4143), vtOptional,
vtOptional, vtOptional, vtOptional, 1, vtOptional,
vtOptional, vtOptional, vtOptional);
app.Quit();
}
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|