|
thank you very much for that help... that point work quite fine now.
i say quite because the popup is drawn, but so thin that i can't read if there are items on (it is about 2 or 3 pixels wide) ; but high enough though.
moreover, when i click on the last item of the menu, it ends the program returning an
Run-Time Check Failure #2 - Stack around the variable 'dlg' was corrupted.
into InitInstance() (it is a dialog based application).
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I don't know what happen to your stack, however the thin menu is because your popping up the menu, you want to popup a popup of the menu. Try this:
CMenu popup_menu = PhonesMenu.GetSubMenu(0);
popup_menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, rect.right, rect.top, AfxGetMainWnd());
|
|
|
|
|
no more luck
i added this to my code
CMenu* popup_menu = PhonesMenu.GetSubMenu(0);
popup_menu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, rect.right, rect.top, AfxGetMainWnd());
but popup_menu is handling NULL pointer, and so, calling TrackPopupMenu() is crashing...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Sorry, remember when I told you to use CreateMenu()? Try calling CreatePopupMenu(). Also remember when I told you to call GetSubMenu(), that doesn't matter anymore with CreatePopupMenu(). Yeah I know, sorry, I never made it out of highschool.
CMenu popup_menu;<br />
popup_menu.CreatePopupMenu();<br />
<br />
popup_menu.AppendMenu(MF_STRING, 2, _T("I know they're stolen"));<br />
popup_menu.AppendMenu(MF_STRING, 3, _T("But I don't feel bad"));<br />
<br />
CRect rect;<br />
<br />
popup_menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, rect.right, rect.top, AfxGetMainWnd());
|
|
|
|
|
hello again mark,
ok, that's ok now. here is what i did during the last hour (when the server of my school was off ). actually, you were right with CreatePopupMenu() but i found it by myself, as you aswered at 15' ...
see the first post on that thread for the working function...
now, the popup displays correctly, and its content is perfectly and fully dynamic : i select someone in a combobox and all his phone numbers are listed on the popup menu. What i would like so is to be able to copy the number the user click on into its related EditBox...
I however don't know how to dynamically assign such a behavior to the menu and its items...
anyway, thanks for your help.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Handle WM_COMMAND, the ID will be the ID you passed to AppendMenu(), if the CMenu is global you can query it for it's text, or use the ID to look up the string vector directly.
|
|
|
|
|
hello Mark,
i ended the taff on that menu... it works now.
however, i think there might be a better to do it, but as i could find out how, here is what i did :
FactEditor.h :
<font color=blue>class</font> CFactEditorDlg : <font color=blue>public</font> CDialog {
<font color=green>
<font color=blue>protected</font>:
<font color=green>
std::vector<CString> m_vPersonPhoneNumbers;
<font color=blue>bool</font> m_bPhonesMenuCalled;
<font color=green>
};
FactEditor.cpp :
<font color=blue>void</font> CFactEditorDlg::OnSClickShowNumbers() {
<font color=blue>using namespace</font> std;
m_vPersonPhoneNumbers.clear();
map<CString, TOperatorPersonPair>::const_iterator itmPersonNumbers;
<font color=green>
<font color=blue>for</font> (itmPersonNumbers = m_mapPhoneWithOpPersPair.begin();
itmPersonNumbers != m_mapPhoneWithOpPersPair.end();
itmPersonNumbers++) {
<font color=blue>if</font> (itmPersonNumbers->second.m_strPerson == m_strCalledPerson) {
m_vPersonPhoneNumbers.push_back(itmPersonNumbers->first);
}
}
sort(m_vPersonPhoneNumbers.begin(), m_vPersonPhoneNumbers.end());
<font color=green>
<font color=blue>if</font> (m_vPersonPhoneNumbers.size() != 0) {
CMenu PhonesMenu;
<font color=blue>if</font> (PhonesMenu.CreatePopupMenu()) {
vector<CString>::const_iterator itvPhoneNumbers;
CString strRes, strMenuTitle;
strRes.LoadString(IDS_FACTEDITORDLGTITLE);
strMenuTitle.Format(strRes, m_strEditorVersion);
PhonesMenu.AppendMenu(MF_STRING, 1, strMenuTitle);
PhonesMenu.AppendMenu(MF_SEPARATOR);
<font color=blue>int</font> iCpt = 3;
<font color=blue>for</font> (itvPhoneNumbers = m_vPersonPhoneNumbers.begin();
itvPhoneNumbers != m_vPersonPhoneNumbers.end();
itvPhoneNumbers++, iCpt++) {
PhonesMenu.AppendMenu(MF_STRING, iCpt, *itvPhoneNumbers);
}
CRect rect;
m_pbShowNumbers->GetWindowRect(&rect);
PhonesMenu.EnableMenuItem(1, MF_GRAYED);
m_bPhonesMenuCalled = <font color=blue>true</font>;
PhonesMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, rect.right+1, rect.top-1, AfxGetMainWnd());
}
}
}
BOOL CFactEditorDlg::OnCommand(WPARAM wParam, LPARAM lParam) {
<font color=blue>if</font> (HIWORD(wParam) == (UINT)0) { <font color=green>
<font color=blue>if</font> (m_bPhonesMenuCalled) { <font color=green>
m_peCalledNumber->SetWindowText(m_vPersonPhoneNumbers[LOWORD(wParam)-3]);
m_bPhonesMenuCalled = <font color=blue>false</font>;
}
}
<font color=blue>return</font> CDialog::OnCommand(wParam, lParam);
}
as you see, i use a boolean flag to test is the WM_COMMAND is sent by my popup or another menu because i couldn't find other way to test it.
i also wanted to put the menu as a member of the class, but here again, no way to turn the new incoming exceptions off... i think i had to do with DestroyMenu() and/or Attach() /Detach() , but where to put them, and how to use them ???
well, i'd like to thank you very much for you help, it was very good, and quite fast too !!
thanks
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Usually what I do with a dynamic menu like that is have a begining ID range and an ending ID range, I define this in the resource header like
#define ID_DYNAMIC_MENU_BEGIN 3000
#define ID_DYNAMIC_MENU_END (ID_DYNAMIC_MENU_BEGIN + 100)
I then call AppendMenu with ID_DYNAMIC_MENU_BEGIN + index;
That would get rid of your m_bPhonesMenuCalled flag because you can just check the wParam to see if it's the range. To get an index use wParam - ID_DYNAMIC_MENU_BEGIN.
Attach()/Detach() are unwanted since they are for menus that already exist. You do however have a resource leak in that you never destroy the menu. After your TrackPopupMenu() you should call DestroyMenu(), with that in place I see no reason for you to Assert by using a CMenu as a member. You were probably ASSERTing by calling CreatePopupMenu() twice without a DestroyMenu().
You ask good questions.
|
|
|
|
|
Mark Petrik Sosa wrote:
Usually what I do with a dynamic menu like that is have a begging ID range and an ending ID range, I define this in the resource header
i cannot do that as i don't know how many items will be placed into the menu when i populate it (it depends on what person is selected to show its phne numbers)...
Mark Petrik Sosa wrote:
That would get rid of your m_bPhonesMenuCalled flag because you can just check the wParam
i don't agree, it could exist several menus in a bigger application than mine that have ID defined twice... i should better have a menu handle.
Mark Petrik Sosa wrote:
You were probably ASSERTing by calling CreatePopupMenu() twice without a DestroyMenu().
yes, that's it, but were to place DestroyMenu() so ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
TrackPopupMenu() blocks until they select something or it loses focus and goes away so you can call DestroyMenu() right after TrackPopupMenu().
|
|
|
|
|
here is my code:
<br />
void CChildView::SortData(LPCTSTR pszData)<br />
<br />
ofstream testFile ("test.txt", ios::app);<br />
testFile << pszData;<br />
The Problem is that it saves the pointer address, 0x00421DA8
and what I want it to do is save the character that is recieved by pszData.
How do I do that?
Thanks,
|
|
|
|
|
pszData is a pointer, you must dereference it to use it's contents.
testFile << *pszData;
|
|
|
|
|
I have tried using *pszData. But when I use that, it gives me numbers, a being 97, b 98, c 99, and so on...
pszData is Unicode, I believe. I don't realy understand the string converstions.
|
|
|
|
|
Looks like you have a Unicode string coming in which is trying to be treated as an Ansi string. Do you have UNICODE defined?
|
|
|
|
|
The Value that it saves from *pszData is the Decimal value of the character that is passed on! According to the ASCII table.
Why does it do that? and how can I make it save the character value?
Thanks...
|
|
|
|
|
I have:
#ifdef _UNICODE
That should be enough? or should I add more to it?
I don't understand this string converstion business too much, even so I have read lot's of articles on it...
|
|
|
|
|
A project under Visual C++ can be under many configurations. You have console or win32 application, MFC or ATL or both, etc. You control these configurations by defining values. A unicode project is controlled by the macros _UNICODE and UNICODE. The #ifdef _UNICODE is a preprocessor directive. Like an if, but at a preprocessor level which means if it's not true (evaluated at compile time) the code won't be included in the executable.
Try adding
#define _UNICODE
#define UNICODE
to the top of your stdafx.h before you include all the headers, or set them in the project settings under preprocessor definitions. Now your project will be unicode aware. For instance a possible problem in your case is passing an argument as a LPCTSTR, which under an ansi project (_UNICODE & UNICODE not defined) is a pointer to an ansi string. In a unicode project it's a unicode string.
|
|
|
|
|
I have added the following lines
Mark Petrik Sosa wrote:
#define _UNICODE
#define UNICODE
to the main.cpp file, don't work. and to stdafx.h file and don't work.
The result is still the same.
What do you think about converting the pszData into another variable such as buffer that is a wide string for example?
I have tried it, but I can't get it to work.
|
|
|
|
|
Try changing ofstream to wofstream.
void CChildView::SortData(LPCTSTR pszData)<br />
<br />
wofstream testFile ("test.txt", ios::app);<br />
testFile << pszData;
|
|
|
|
|
testFile << std::string (pszData);
This will work, but I doubt it is the best way of doing it. I'm not a fan of iostreams (slow and bloated), so I don't have the depth of knowledge that others will have.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I have tried
Tim Smith wrote:
File << std::string (pszData);
but it comes up with 2 errors:
std - is not a class or namespace name
string - undeclared identifier
|
|
|
|
|
You need to include <string> to use the string class.
|
|
|
|
|
Hello,
suppose i get an argument which gives me a string where the element is stored eg (root) (child)(grandchild)then how do i parse the xml file to travel to that particular node and then add the value of the attributes of grandchild to an array and return it
thanks
|
|
|
|
|
72arpita wrote:
how do i parse the xml file...
Use the IXMLDocument interface.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi,
I want to draw a rectangle in a Rich Edit Text control (CRichEditCtrl) which is embedded on a Tab Control.
I am using CFormView (form as my container to place all my controls TabCtrl, RichEditCtrl, etc.) I need to get the correct Device Context to do the drawing in my CFormView::OnDraw(CDC* pDC) method.
Can someone help me out?
Thanks in advance,
Ahmed Kabir
|
|
|
|