|
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
|
|
|
|
|
Perhaps you want to subclass your CRichEditCtrl and override OnPaint()
|
|
|
|
|
Hi !
My C++ app needs to read an external text file and display it on screen. But, this text file can contain specific commands to change what has to be displayed by my app.
For instance, the text file could be :
Hello
[if foo]
Foo
[else]
Bar
[endif]
and my app should display (depending of foo) : Hello Foo.
The problem is that I don't know where to start. Should I just parse the text file and just check each [] ? Should I write a real interpreter (I have no idea how to do this). Can I reuse something existing ?
Any help, suggestions or idea are welcome !
THanks !
Jerome
|
|
|
|
|
|
Hi,
I'm working on an SDI application using MFC.
I'd like to change the background of titlebar and toolbar by adding a small bitmap image which looks like a short vertical line.
I found some source codes to change background color of titlebar.
But I don't know how to change the background of titlebar by a bitmap image.
Please let me know how to add the bitmap image as a background.
|
|
|
|
|
Look into WM_NCPAINT, LoadImage and BitBlt.
|
|
|
|
|
Hi
I am doing a project on image processing with VC++. When I try to display the bitmap(8 bit) on the screen using SetDIBitsToDevice() the actual color is not mapped correctly. The same code works fine with 24 bits bitmap.
Pls help
Thanks in advance
|
|
|
|