|
Hi im creating a popup menu but i only want it to show up when the user right clicks on a tree ctrl in a dialog i mapped the tree controls onrightclick but i dont know how to get the mouse coordinates what is the best way to handle a popup menu for a tree control within a dialog
|
|
|
|
|
It would be better to use WM_CONTEXTMENU instead of the right-click. The reason for this is that OnContextMenu() also catches Shift+F10, which is the Windows standard shortcut key for context menus (try it in the Explorer). But to catch right-clicks with OnContextMenu(), you also have to have a handler for ON_WM_RBUTTONDOWN - otherwise, the tree control will think you are starting a drag operation. One final thing: if OnContextMenu gets called because of Shift+F10, the point will always be -1, -1. Therefore, always use GetCursorPos() to get the actual point.
Here is an example (it assumes you have derived a minimal CMyTreeCtrl from CTreeCtrl):
void CMyTreeCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
}
void CMyTreeCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
{
CPoint pos;
GetCursorPos(&pos);
ScreenToClient(&pos);
UINT flags = 0;
HTREEITEM hItem = HitTest(pos, &flags);
SetFocus();
if (hItem != NULL)
{
SelectItem(hItem);
CMenu menu;
menu.CreatePopupMenu();
VERIFY(menu.AppendMenu(MF_STRING, ID_MYID, "My Selection"));
GetCursorPos(&pos);
VERIFY(menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, pos.x, pos.y, this));
}
else
{
TRACE("not on item\n");
}
}
HPS HwndSpy - GUI developer's aid to visually
locate and inspect windows. For the month of August
only, use coupon code CP-81239 for 30% off.
|
|
|
|
|
I readed this topic and I tested it. HitTest() and SelectItem() dosen't exist when i try to complie it. Do I have to include header files or something?
|
|
|
|
|
void CTestView::OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu *pMenu,oMenu;
oMenu.LoadMenu(IDR_TESTMFTYPE);
pMenu = oMenu.GetSubMenu(0);
pMenu->EnableMenuItem(ID_FILE_NEW,MF_DISABLED | MF_GRAYED);
pMenu->TrackPopupMenu(0,point.x,point.y,this);
}
|
|
|
|
|
Hi,
I writing a small program what read a file, say has 600000000 ip addresses, and output to different smaller files (each contains 2000 ip addresses)as such file1.txt, file2.txt, file3.txt.,, so on. I am stuck at the part of how to name the output files.
Can anyone help me?
Thank you very much.
|
|
|
|
|
for ( int i = 1; i <= 2000; i++ )
{
ostringstream strmName;
strmName << "file" << i << ".txt" << ends;
ofstream outfile ( strmName.str().c_str() );
}
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
Micheal, Thank you very much.
Tomss.
|
|
|
|
|
I have used the following code, but feel uncomfortable about it, if you could make any suggestions as to how to better it, I would appreciate it.
char* pTmpBuf = new char[filename.GetLength()+1];
ZeroMemory(pTmpBuf, filename.GetLength()+1);
CopyMemory(pTmpBuf, filename, filename.GetLength());
GetParent()->SendMessage(LVN_ADDFILE, filename.GetLength(), (LONG)pTmpBuf);
delete[] pTmpBuf;
Thats the code that send the message obviously
void MyDialog::MyFunc(WPARAM wParam, LPARAM lParam)
{
CString buff="";
CopyMemory(buff.GetBuffer(wParam), (void*)lParam, wParam);
AfxMessageBox(buff);
}
The main question I have...is it safe to delete the temp buffer after the message has been sent? Or should I leave deletion of the pointer to the client programmer inside MyFunc
I'm drinking triples, seeing double and acting single
|
|
|
|
|
As long as you are using SendMessage, which is Synchronous, you are fine to delete pTmpBuf after the call to SendMessage. SendMessage won't return until the message is completely processed.
If on the other hand, you were using PostMessage, which is Asynchronous, you would have to delete pTmpBuf inside your MyDialog::MyFunc instead, because PostMessage will almost certainly return before your message is processed.
Chris Richardson Terrain Software
|
|
|
|
|
Chris Richardson wrote:
As long as you are using SendMessage, which is Synchronous, you are fine to delete pTmpBuf after the call to SendMessage. SendMessage won't return until the message is completely processed.
Thats all I wanted to know...
Thanks a bunch
I'm drinking triples, seeing double and acting single
|
|
|
|
|
Unless I'm missing something, you're making it way too complicated. The SendMessage can be:
GetParent()->SendMessage(LVN_ADDFILE, (WPARAM)(LPCTSTR) filename); Then the message handler can do:
void MyDialog::MyFunc(WPARAM wParam, LPARAM lParam)
{
AfxMessageBox ( (LPCTSTR) wParam);
}
--Mike--
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--=
NO CARRIER
|
|
|
|
|
Hi, I want to find a file that could be in any directory in any of the local disks. CFileFind find relies on specific directories. Is there an easy way to do this, or do I need to hack something up? If I need to hack something, does anybody know how to get a list of the drives?
Cheers
|
|
|
|
|
|
Hello all
I'm trying to establish OLDEB connection to sql server using vc++. As I'm new to using database connection, finding it hard to implement it in my application. I gone through msdn but finding it difficult to comprehend.
Can any one help me in this? Can any one tell the function calls I need to use to establish OLEDB connection. If any one knows how to do this,pls help me with an example if possible.
thanks for your help.
Hari.
|
|
|
|
|
There are times when I have several versions of a file. This allows me to make changes and freeze what I have done up to a point. If subsequent changes start acting crazy, I can always go back to one of the previous versions and start over from there.
AppWizard doesn't seem to like this because although the different version files all have the same name (in a separate directory), deleting one from the Workspace and then do Project->Add to Project->Files, does not get me changes indicative of a specific version I might be trying to bring in (which is how I know I don't have the correct version I am trying to add to the Workspace) in the Workspace.
To delete the ".dsw" or the ".dsp" file would only get me in deeper trouble.
Is there a safe way to accomplish what I'm trying to do?
Thanks.
William
Fortes in fide et opere!
|
|
|
|
|
I would try to help, but that second sentence/paragraph makes it way too difficult to understand what is happening.
Chris Richardson Terrain Software
|
|
|
|
|
Ok...I think I see what you are trying to do, and why it's not working. When you say AppWizard do you really mean ClassWizard (the one that allows you to add functions to classes)? If so, then you should delete the YOUR_PROJECT_NAME_HERE.clw file after you add the new file in. Then try to load the class wizard again, and it will rebuild the .clw file for you.
Otherwise, if that's not the case, maybe it's something with the build system that you are talking about? So, say you have two versions of a file called MyFile.cpp and they reside in different directories. You are trying to remove the first "MyFile.cpp" from the project, add in the second "MyFile.cpp", rebuild, and hope everything works right? If this is the case, what I would suggest doing is either doing a clean before you build (or rebuild all), or else manually deleting MyFile.obj in the intermediate directory. You'll only have to do this one time after you add the new file, so it's not a big deal.
If I was completely off base with either scenarios, feel free to correct me, and I can try to be of more help.
Chris Richardson Terrain Software
|
|
|
|
|
Thank you for your reply.
No, it's not ClassWizard I'm talking about, and it's not AppWizard in the sense that I'm creating a new application using that tool. It's AppWizard in the sense that it was that tool I used when I first created the application, which now that I'm trying to do the file substitution thing, I realized at the time it was created, AppWizard must have done something peculiar to it that causes the Workspace to reject the switching of files that I'm trying to acomplish.
I know when you use AppWizard to create an application, it does quite a bit of secret things behind the scene to the application you're creating, in effort to maintain the framework. It is one of those secret things I believe I might be running up against.
I am not looking to violate any of AppWizard's rules. I am trying to understand them so as to comply with them even as I am trying to benefit from the switching of files with the same names. AFAIC, this shouldn't be thought of as a change in the environment. The content of the files are only what is different, which shouldn't matter to the IDE.
William
Fortes in fide et opere!
|
|
|
|
|
I think I may have found a way. I am not too sure, but if after using the technique for a while and it holds up every time, then I'll know I will have truly found a way.
Thanks for your thoughts and other efforts. I appreciate it.
William
Fortes in fide et opere!
|
|
|
|
|
Is there any controls like already availble?
I've hacked togather a control which uses about 3-4 different articles(and their code) to create a list control much like the one found in windows explorer. I always find a need for a listview with all the functionality found in explorer (drag n' drop, sort, image lists) does anything like this already exist?
Thanks
I'm drinking triples, seeing double and acting single
|
|
|
|
|
Hi,
I am using VC++ to connect/transfer files from my Web page, sometimes even I connect then disconnect the Web connection in every 3 seconds ... I still have this error message The connection with the server was reset
1) Before I transfer files, I do verify to see the connection is successful
2) After transfer files, I close the connection with the Web
3) Then wait 3 seconds to do over the same task
I would like to know why I have that error message & what can I do to avoid this problem
I appreciate any help here
Thanks
|
|
|
|
|
is this really a visual c++ coding question?
Don't try it, just do it!
|
|
|
|
|
If he is making his program using C(++), then Yes!
- Anders
Money talks, but all mine ever says is "Goodbye!"
http://SourceLocker.net[^] SourceControl and DefectTracker Project.
nsms@spyf.dk <- Spam Collecting
|
|
|
|
|
Hi,
Yes it is! And it is working fine if the Web-Site is not very busy!
Regards
|
|
|
|
|
Hi all,
I've simple file manager, in which I display icons for EXE files using ExtractIconEx() this way:
ExtractIconEx (pathToEXEFile, 0, &bigIcon, &smallIcon, 1);
It works fine. But I also found EXE files, for which this function takes much more time than normally.
One example of such file is RLUninstall.exe, located in WINNT directory.
Doesn't some know how is this possible or how to bypass it?
Thank you for any suggestion.
|
|
|
|
|