|
it works!!!!!!!!!!!!!!!!!
GREAT!!!!!!!!!!!!!
THANKS!!!!!!!!!!
|
|
|
|
|
This one is just kicking me hard......Maybe someone can help......I'm trying to get completely dynamic context menus to work.....What's strange is these approaches work in debug mode, but never work in release mode....The way it fails in release mode is that the menu is not displayed, and the result is always zero.
What gives?
The following snippettes work in debug mode, but NOT in release mode:
// snip #1
CMenu oMenu;
ASSERT( oMenu.CreatePopupMenu() );
// i have a collection of menu command items that I add to the
// dynamic menu here
//
CONTEXT_COMMANDS_ITER oMenuCommandsIter;
for ( oMenuCommandsIter = poCommands->begin();
oMenuCommandsIter != poCommands->end();
oMenuCommandsIter++ )
{
oMenu.AppendMenu( MF_STRING,
(*oMenuCommandsIter).first,
(*oMenuCommandsIter).second.c_str() );
}
ClientToScreen( &oPoint );
DWORD dwResult;
dwResult = oMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON |
TPM_NONOTIFY | TPM_RETURNCMD,
oPoint.x,
oPoint.y,
this );
// end snip #1
// snip #2
CMenu oMenu;
CMenu oPopup;
ASSERT( oMenu.CreateMenu() );
ASSERT( oPopup.CreatePopupMenu() );
oMenu.AppendMenu( MF_STRING, 0, "Ignored" );
oMenu.AppendMenu( MF_POPUP, (UINT)oPopup.m_hMenu, "Ignored" );
// i have a collection of menu command items that I add to the
// dynamic menu here
//
CONTEXT_COMMANDS_ITER oMenuCommandsIter;
for ( oMenuCommandsIter = poCommands->begin();
oMenuCommandsIter != poCommands->end();
oMenuCommandsIter++ )
{
oPopup.AppendMenu( MF_STRING,
(*oMenuCommandsIter).first,
(*oMenuCommandsIter).second.c_str() );
}
ClientToScreen( &oPoint );
DWORD dwResult;
dwResult = oPopup.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON |
TPM_NONOTIFY | TPM_RETURNCMD,
oPoint.x,
oPoint.y,
this );
// end snip #2
The following approach works in debug and release mode, but I don't like it because it creates a dependancy on the resource fork.
CMenu oMenu;
VERIFY( oMenu.LoadMenu( IDR_MENU_HIGHLIGHTS ) );
CMenu* poPopup = oMenu.GetSubMenu( 0 );
ASSERT( poPopup != NULL );
int iCount = poPopup->GetMenuItemCount();
// since I loaded a menu from a resource, throw all the stuff away
// i don't want/need here
//
for ( int iLoop = 0; iLoop < iCount; iLoop++ )
{
poPopup->RemoveMenu( iLoop, MF_BYPOSITION );
}
// add the commands I want on the menu
//
CONTEXT_COMMANDS_ITER oMenuCommandsIter;
for ( oMenuCommandsIter = poCommands->begin();
oMenuCommandsIter != poCommands->end();
oMenuCommandsIter++ )
{
poPopup->AppendMenu( MF_STRING,
(*oMenuCommandsIter).first,
(*oMenuCommandsIter).second.c_str() );
}
ClientToScreen( &oPoint );
DWORD dwResult;
dwResult = poPopup->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON |
TPM_NONOTIFY | TPM_RETURNCMD,
oPoint.x,
oPoint.y,
this );
ASSERT( oMenu.DestroyMenu() );
I've even tried to go so far as to use CreateMenuIndirect() from a memory template, which just seems like too much for what I'm trying to do...
Anyone have any hints for me?
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Just in case anyone is at all curious...here is the fix. The trouble seems to be that even though a popup menu is created, it must be stored in a containing menu object, and then refetched from that container.....very wierd.....
// first create the popup menu
//
CMenu oPopup;
VERIFY( oPopup.CreatePopupMenu() );
// now add all the commands to it from the command/prompt list
//
CONTEXT_COMMANDS_ITER oMenuCommandsIter;
for ( oMenuCommandsIter = poCommands->begin();
oMenuCommandsIter != poCommands->end();
oMenuCommandsIter++ )
{
oPopup.AppendMenu( MF_STRING,
(*oMenuCommandsIter).first,
(*oMenuCommandsIter).second.c_str() );
}
// create the container menu and insert the popup into it
//
// see: MSDN: Q75254
// PRB: TrackPopupMenu() on LoadMenuIndirect() Menu Causes UAE
//
CMenu oMenu;
VERIFY( oMenu.CreateMenu() );
oMenu.InsertMenu( 0, MF_POPUP, (UINT)oPopup.m_hMenu, "Ignored" );
// now have to pull the popup menu back out of the containing menu
// I know its strange, but this is how it works......
//
CMenu* poPopup = oMenu.GetSubMenu( 0 );
ASSERT( poPopup != NULL );
ClientToScreen( &oPoint );
DWORD dwResult = poPopup->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON |
TPM_NONOTIFY | TPM_RETURNCMD,
oPoint.x,
oPoint.y,
this );
ASSERT( oMenu.DestroyMenu() );
ASSERT( oPopup.DestroyMenu() );
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Hello, didn't read it too closely, but I think your looking at the wrong area for the problem completely:
In snip 1 there is a problem with your ASSERT statement. In a release build the ASSERT statement is going to translate to nothing so CreatePopupMenu will never get called.
ASSERTs are only compiled into the executable in a debug build.
VERIFY on the other hand which you used in the final example *is* compiled into the release code and will do the check but if it's a release version it will never report an error as it only reports an error in debug builds.
This means that any code inside an ASSERT is basically gone when you do a release build, any code inside a VERIFY is still there and will execute but will not report an error no matter what the result of the check.
What you should do instead of this:
RedZenBird wrote:
CMenu oMenu;
ASSERT( oMenu.CreatePopupMenu() );
Is something like this:
CMenu oMenu;<br />
BOOL BResult=FALSE;<br />
BResult=oMenu.CreatePopupMenu();<br />
ASSERT(BResult);
That way your function executes debug or release.
If it was release code and you thought there was any chance of that function failing you would want to add some form of error handling based on the BResult status after calling CreatePopupMenu().
|
|
|
|
|
You are right...So, I was driving the train all around the mountain and not even seeing the track in front of me.....gads!!!!
Once again proving: "Preoccupation clouds the mind" .....
Thank you for the feedback nonetheless
Just trying to keep the forces of entropy at bay
|
|
|
|
|
I know I've seen it some place, but can't remember...
How do you change the starting index value? It defaults as 0 to x, I'd like to use something like 3 to x.
Thanks for any help or direction.
|
|
|
|
|
One solution is to derive your own CComboBox.
Kuphryn
|
|
|
|
|
I thought there was an option to set the starting index...
|
|
|
|
|
Sendmessage(hwnd, CB_SETCURSEL ...) should do it in Win32. I don't remember which PARAM is the the index value but a search on MSDN should help you out.
|
|
|
|
|
Dear All,
Can anyone help? I'm developing a file manager application (Visual Studio C++) and am looking for a suitable files/folders selection control. It would operate similar to the way anti-virus software products work i.e. allowing the user to select files and/or folders via pick-boxes next to each file/folder name in a Windows Explorer-style tree. The control would also 'remember' which files/folders were selected last time therefore effectively 'managing' the file/folder list.
Does anyone know of a professional control that would help with this task? any help or recommendations are greatly appreciated. Thanks.
James Wood
|
|
|
|
|
hi everybody,
i'm working on a project that reads in a .csv file(comma delimited).. i was wondering is there a premade library for reading .csv, ie parse everything nicely? i want to find out if there is one before i write one for myself.. btw, i'm running winxp pro, using vc++ and having ms office xp installed.
thank you!
|
|
|
|
|
If you took a lookie in the Files and Folders section, I'm sure you would have stumbled onto my article: http://www.codeproject.com/file/CDataFile.asp[^]
I just submitted an update that implements write/create methoda as well as statistical analysis. If you are reading text only and not numerical data, you can just change the CNamedVariable member vData from std::vector<double> to std::vector<CString> if you'd like. Just remember to strip out the atof() call in the read method, and don't use any of the math calls in the new version.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Hello,
INTRODUCTION
As I use Paul DiLascia's HTMLCtrl (it's completely the same than CHTMLView but it can be placed in dialogs) I've spent some days trying to send directly HTML code to the control in order not to need to write a file each time the information to show changes.
Finally I got it...
But as it is based in getting the HTMLDocument and at the beggining it doesn't exist, I've used the "about:" protocol in order to force the creation of a document. (I know that it must be another way of doing it...)
but the fact is that it works almost well.
QUESTION
I "reload" (I should say re-send) the HTML each time the user changes his/her selection in a ListCtrl and everything goes OK except the first time, that nothing is shown.
Here's the code used:
-----------------------------------------------------------------
In the OnInitDialog and in order to force a document...
-----------------------------------------------------------------
<br />
this->m_HTMLCtrl.Navigate("about:<html><body bgcolor=\"7AA1E6\" leftmargin=\"0\" topmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\" oncontextmenu=\"return false\"></html>");
-----------------------------------------------------------------
-----------------------------------------------------------------
In the HTML refresh function...
-----------------------------------------------------------------
<br />
IHTMLDocument2* pHTMLDocument2;<br />
LPDISPATCH lpDispatch;<br />
IHTMLElement* pBody;<br />
BSTR bstr;<br />
HRESULT hr;<br />
<br />
lpDispatch = this->m_HTMLCtrl.GetHtmlDocument();<br />
<br />
if (lpDispatch)<br />
{<br />
hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pHTMLDocument2);<br />
lpDispatch->Release();<br />
<br />
hr = pHTMLDocument2->get_body(&pBody);<br />
<br />
bstr = csCodiHTML.AllocSysString();<br />
<br />
if (pBody)<br />
{<br />
pBody->put_innerHTML(bstr);<br />
pBody->Release();<br />
} <br />
<br />
SysFreeString(bstr);<br />
}<br /> -----------------------------------------------------------------
Could you tell me what is happening here?
Why it works OK the second time and not the first one?
Thank you in advance
|
|
|
|
|
I've also started using the "about:" trick someone recently mentioned on CP. It works fine for me the first time. Here's how I use the HTML control:
CString strUrl = "about:<html><body> ... </body></html>";
m_htmlCtrl.SetSilent (FALSE);
m_htmlCtrl.Navigate (strUrl, navNoReadFromCache);
Hope this helps!
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Yes, it also worked for me...
but my problem is that the web page that I show to the user has a lot of text, and I can't use "about:" protocol because it has a limitation and my page exceeds it...
Then I've searched in order to write as many information (without chars limitation) to the HTMLCtrl.
In order to do that I've done what's in my previous post...
And it works fine... (almost)...
I need a HTMLDocument pointer in order to write data to it, but my function is not capable to get that pointer the first time, the other ones it works perfectly... I'm wondering if I'm trying to select the document before it has been able to be created...
And I would like to get the way to create and only create a HTMLDocument into a CHtmlView. Because I think that the "about:" protocol must not be the right solution...
thank you for your interest!
|
|
|
|
|
Ah. How about first seeding the control with "about:blank" and then getting the (valid) HTMLDocument pointer? It would be great if that works!
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Yes, it works always, but not the first time... And I don't know why...
I'm doing the same the first and the second and all times... but the document seems to be created only the second time...
You can try it, it's so easy...
All the code used is what I've posted in the first post...
And if you want you can download Paul Di Lascia's HTML Ctrl from this link:
http://www.microsoft.com/msj/0100/c++/c++0100.asp[^]
|
|
|
|
|
I don't understand why I must send (in the about clause) the margins that I'll use in the web page because if I don't do it sending HTML directly don't gets placed in the right position even if the directives (margins...) are written.
Then I'm passing to the "about:" the margins and the background color only...
and I must only know how to get that document created the first time...
|
|
|
|
|
Hello everybody:
Everytime that I call the function CFileDialog::DoModal I'm getting an Assert error. This is what I have in my code:
<br />
if (lastFileOpenPath.GetLength() > 0)<br />
{<br />
openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath;<br />
}<br />
<br />
int nResult = openDlg.DoModal();
Is there something that I'm missing? Is any of you guys had this problem before? Any answer is more than welcome.
Have a good day!!!
Luis E. Cuadrado
)
|
|
|
|
|
are u sure it is getting into the if loop..if so, is lastFileOpenPath pointing to a existing directory on the machine ??
There are no failures; there are only extended learning opportunities.
|
|
|
|
|
By the if...loop you mean the following?
if (lastFileOpenPath.GetLength() > 0)
{
openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath;
}
If so, yes. I did a step over and I was able to see it being executed. After it comes out of the if then the DoModal function throws and assert error.
About lastFileOpenPath, yes is pointing to a directory in the machine. I'm able to open the file selected by the open file dialog. But I have to click Ignore when I get the assert error.
Thanks,
Luis E. Cuadrado
)
|
|
|
|
|
wait a minute ! u r assigning a CString to a LPCTSTR (openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath)..i guess u have to do a casting to do that ??
There are no failures; there are only extended learning opportunities.
|
|
|
|
|
What is it ASSERTing on?
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
It is ASSERTing in the DoModal function in the DLGFILE.CPP. The ASSERT comes out after selecting a file from the Open Dialog.
This is where is ASSERTing on in the DLGFILE.CPP:
if (nResult)
ASSERT(pThreadState->m_pAlternateWndInit == NULL); <-- HERE
pThreadState->m_pAlternateWndInit = NULL;
when I check the Developer Studio's call stack, it's comming from here:
if (lastFileOpenPath.GetLength() > 0)<br />
{<br />
openDlg.m_ofn.lpstrInitialDir = lastFileOpenPath;<br />
}
int nResult = openDlg.DoModal(); <--- HERE
I hope this helps.
Thanks,
Luis E. Cuadrado
)
|
|
|
|
|
This is probably a dumb request, but can you post the declaration of the openDlg variable?
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|