|
I have a dialog based app, no doc/view, in which I have a listview control, and I want to add a context menu, so that when the user right clicks in the list view, a context menu pops up, and the user can choose to add, delete, etc. an entry. Do you have to have doc/view in order to have a context menu? If so, is there a way around this?
|
|
|
|
|
You can do this quite easily. First Create a menu resource
MyPopup->Item 1
Item 2
...
Then handle the NM_RCLICK message for the list control and add code such as this
CMenu menu ;
CMenu *pPopup ;
CPoint point ;
int item_selected ;
GetCursorPos(&point) ;
menu.LoadMenu(IDR_MENU_RESOURCE_ID) ;
pPopup = menu.GetSubMenu(0) ;
item_selected = ::TrackPopupMenuEx(pPopup->m_hMenu, TPM_RETURNCMD | TPM_NONOTIFY, point.x, point.y, m_hWnd, NULL) ;
switch (item_Selected)
{
case ID_MENU_ITEM1 :
...
break ;
}
You use the TPOM_RETURNCMD flag so that you don;t have to handle the command as WM_COMMAND message. This allows you to keep all the code together for the different menu options in one place. You also don;t have to write all the ON_COMMAND macros and function prototypes
Enjoy
Roger Allen
Sonork 100.10016
|
|
|
|
|
Hi everyone,
I've posted a thread regarding the retrieval of sound and graphics card info such as driver name, manufacturer and version.
Many of the answers I have received all boils down to using WMI (Windows Management Instrumentation) but after using it I realize it's an enormous overkill for my simple needs and that it is not supported for win 95/98 unless you install it yourself.
There must be another, more standard way to get the display and sound info, right...?
If you know how or can point me in the right direction, I'd be VERY grateful!
/Tommy
|
|
|
|
|
I built an application using Micro. visual c++. When in debug run it turns nothing...but when I compile/build in Win32 Release n try to execute this error occur in the message box in windows 2000
"The instruction at "0x00430432" reference memory at "0x0000000c". The memory could not be "read" ".
n I click ok
again it emerge with different error message box,
"The instruction at "0x0042377c" reference memory at "0x00000004". The memory could not be "read" ".
any idea what is this error
|
|
|
|
|
i can't really help you... but this article may help...
http://www.codeproject.com/debug/survivereleasever.asp
hope this helps
bernhard
"There are three roads to ruin: women, gambling and technicians. The most pleasant is with women, the quickest is with gambling, but the surest is with technicians." Georges Pompidou
|
|
|
|
|
Hi Guys,
Did it ever happened to you that you wanted to send some big files to a friend in small pieces by mail and you needed to do all the hard work of using one application to split it and then attach the pieces your self...
I had this problem and I found an application that does this for you and more and I want to recommend it.
It is called "Moving" application and it can be downloaded from the site:
http://www.domoving.com
It does the above in a very easy way and you can also ask for confirmation that the reciever who got your pieces succeeded in opening them.
It also bypass firewalls so I can send exe,mp3,etc. files to friends that are "blocked" and can get this kind of mail.
Eran
|
|
|
|
|
10x for your recommendation,
this a really cool tool, one of the best I bump into lately.
|
|
|
|
|
I need to draw an image onto a part of the Desktop!If anybody knows how to do it please help me with a a sample!
Thanks in advance!!
|
|
|
|
|
You can get a handle to the screen like this:
CDC dc ;
dc.Attach(::GetDC(NULL)) ;
... drawing code
dc.ReleaseDC() ;
Roger Allen
Sonork 100.10016
|
|
|
|
|
Hi
I have a MFC based Modeless dialog application [A], developed in VC++ 6.0.
I have also a MFC regular dll [B], in which I have one modeless dialog as a resource.
I am loading this MFC regular dll [B] from my application [A],{ Using LoadLibrary() } and displaying its modeless dialog resource. This call to dll is made on some button click of my application [A].
Also, I have overridden CWinApp::OnIdle in my MFC regular dll [B].
But the problem is Dll's OnIdle is NOT called.
What could be the problem ????
One thing I have noted is when I override CWinApp::OnIdle
in my MFC dialog application [A], then this function is called. So, why NOT the Dll's OnIdle function called ?
Can anyone there help me get rid of this problem ?
Regards,
Prasad G.
|
|
|
|
|
Probably because OnIdle() is called when no messages are waiting in the app's message queue. Since it's the EXE that has the queue, the EXE's OnIdle() is called.
--Mike--
http://home.inreach.com/mdunn/
While I can't be correct on all matters, I can make the reassuring claim that where I am inaccurate, I am at least definitively inaccurate.
your with and
Sonork ID - 100.10414 AcidHelm
|
|
|
|
|
I'm new to Visual C++ and MFC. I have just converted a DOS-based C program to MFC using MDI interface. I hope someone can help explain these 3 problems I can't seem to fix so far:
1. How do I create a maximised child window? I have tried WS_MAXIMISE in CChildFrame::PreCreateWindow but it doesn't work.
2. In one Dialog, my program can spend up to 5 minutes doing some data conversion and writing to disk. During this time, all buttons except Cancel are disabled. But the Cancel button refuse to appear as the default although I've set
m_cancel.SetButtonStyle(BS_DEFPUSHBUTTON);
m_cancel.SetFocus();
3. During this 5 minutes, the Cancel remain unclickable.
By the way, is it easier to program with Borland C++ Builder?
|
|
|
|
|
1/ Override OnInitialUpdate in the view and add this line:
GetParemtFrame()->ShowWindow(SW_SHOWMAXIMISED);
2/ Why don't you make cancel the default button in the resource editor instead ?
3/ That's because your task is taking up all of the time slice. You need to do the writing in a worker thread and then your main (UI) thread will become responsive.
I doubt it, if that were the case, why does no-one use it ?
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
Hello all,
I was wondering about the scope of try...catch constructions over threads.
An example (very simplified example of existing code, where the Main_thread acts like a scheduler and the Worker_Threads are the 'processes'):
Main_thread
{
try {
}
catch( ... ) {
}
}
Worker_thread
{
try {
}
catch( condition ) {
}
catch( ... ) {
throw( something );
}
}
Is it possible to (or 'how to') catch the last throw from the Worker_thread into the Main_thread?
What is the nice way to do this?
Thanks in advance,
EiSl
|
|
|
|
|
Is it possible to (or 'how to') catch the last throw from the Worker_thread into the Main_thread?
The short answer is no you can't. Exceptions are intrinsically attached to the thread where they're produced, as are the mechanisms of stack unwinding involved.
An uncaught exception is simply swallowed by the system (though it is no good practice to let this happen).
An approach to having uncaught exceptions somewhat notified to the main thread is having a grand wrap-all try-catch in the worker thread that intercepts otherwise uncaught exceptions, translates this to a DWORD and return that result code, which the main thread can access with GetExitCodeThread() .
How do you translate exceptions to DWORD s? Depends on what kind of exceptions you're dealing with:
- If you don't have any a priori idea about the exceptions the worker thread can throw, then there's little you can do except perhaps returning 0 as "everything OK" and some other code for "some exception thrown".
- If the exceptions are derived from C++
std::exception , which provide a description with method what() , you can store this message in some global table and return a pointer to it.
- If the exceptions are copyable, you can store the exception objet itself in a table an return a pointer to it. Please note that this requires that the exceptions be of an exact known type, as derived types objects are not handled correctly (they're sliced).
- Some other ad hoc mechanism. You name it.
Hope this helped.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
IMHO it's not possible.
You have to do some thread syncronization between the Main_thread and Worker_thread.
----
Rui Lopes
|
|
|
|
|
Can I use CFileFind to search for a specific file on my computer?
I've seen that the class has to do with the CGopherFileFind and CFtpFileFind. So I guess it's perhaps impossible?
I've tried this but nothing appears:
void CFopiacjeDlg::OnButton1()
{
CFileFind finder;
BOOL bWorking = finder.FindFile("Fcc32.exe");
while (bWorking)
{
bWorking = finder.FindNextFile();
AfxMessageBox(finder.GetFilePath());
}
}
|
|
|
|
|
Findfile like that is only searching your current directory. (doth it search the PATH too? I can't remember.). But it isn't going to search your entire drive as you would want it to.
I use findfile in a self recursive function (it calls itself). Like this,
If you don't want the tree just chop those bits out.
This is a version that fills a tree with directories.
void CExIncView::FillDirTree()
{
char DRIVES[33];
DWORD DriveNumbers;
DWORD j;
int k,Image,ImageSelected;
CString lString;
HTREEITEM ParentList[33];
unsigned lDriveType;
m_Messages = " ";
UpdateData(FALSE);
//For each drive collect all directories
DriveNumbers = GetLogicalDrives();
j=1;
for(j=1,k=0;k<32;k++,j*=2)
{
if( DriveNumbers & j )
{
DRIVES[k] = 'A' + k;
}
else
{
DRIVES[k] = ' ';
}
}
//TEMP Put drives into tree
for(k=0;k<32;k++)
{
if( DRIVES[k] != ' ')
{
lString.Format("%c:",DRIVES[k]);
lDriveType = GetDriveType(lString);
switch(lDriveType)
{
case DRIVE_UNKNOWN ://The drive type cannot be determined.
Image = 2;
ImageSelected = 3;
break;
case DRIVE_NO_ROOT_DIR ://The root directory does not exist.
Image = 2;
ImageSelected = 3;
break;
case DRIVE_REMOVABLE ://The disk can be removed from the drive.
Image = 0;
ImageSelected = 1;
break;
case DRIVE_FIXED ://The disk cannot be removed from the drive.
Image = 2;
ImageSelected = 3;
break;
case DRIVE_REMOTE ://The drive is a remote (network) drive.
Image = 2;
ImageSelected = 3;
break;
case DRIVE_CDROM ://The drive is a CD-ROM drive.
Image = 4;
ImageSelected = 5;
break;
case DRIVE_RAMDISK ://The drive is a RAM disk.
Image = 2;
ImageSelected = 3;
break;
default:
Image = 2;
ImageSelected = 3;
break;
}
//ParentList[k] = m_pDirTree.InsertItem(lString,TVI_ROOT,TVI_SORT);
ParentList[k] = m_pDirTree.InsertItem(lString,Image,ImageSelected,TVI_ROOT,TVI_LAST);
m_pDirTree.SetItemData( ParentList[k], (DWORD) 50 );
}
else
{
ParentList[k] = NULL;
}
}
//For each parent traverse directory tree
for(k=0;k<32;k++)
{
if(ParentList[k] != NULL)
{
lString.Format("%c:",DRIVES[k]);
SearchDir(lString,ParentList[k]);
}
}
}
SearchDir is the self recursive function.
void CExIncView::SearchDir(CString sPath)
{
CString sFind,sTemp;
CString sBase,sBase2;
int Done;
WIN32_FIND_DATA lpFindFileData;
HANDLE SearchHandle;
sBase = sPath;
sFind.Format("%s\\*.*",sBase);
SearchHandle = FindFirstFile(sFind,&lpFindFileData);
if( SearchHandle != INVALID_HANDLE_VALUE)
Done = 0;
else
Done = 1;
while( !Done )
{
do
{
if( lpFindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY )
{
sTemp = lpFindFileData.cFileName;
if( (sTemp.Find("..") != -1) || (sTemp.GetLength()==1) )
;
else
{
sBase2.Format("%s\\%s",sBase,lpFindFileData.cFileName);
SearchDir(sBase2);
}
}
else
{
sTemp = lpFindFileData.cFileName;
if( sTemp.Find(m_FindThis ) != -1 )
{
if( m_iFind == 0 )
m_DatabaseLocation = sBase;
else
m_SourceFileDir = sBase;
}
}
}
while(FindNextFile(SearchHandle,&lpFindFileData));
Done = 1;
}
}
This FindFile can now be used to search for particular files (in this case on C
bool CExIncView::FindFile(CString &FName)
{
CString lString;
m_FindThis = FName;
lString.Format("C:");
SearchDir(lString);
return TRUE;
}
We do it for the joy of seeing the users struggle.
|
|
|
|
|
Hello All!
I have a custom draw list control, but it scroll bars has a standart look. Does anybody know how can I draw this scroll bars (I think it windows
style scroll bars, not controls) by my own? Or how can I replace this scroll bars by my custom draw controls without writing my own scrolling code?
|
|
|
|
|
I havn't done this myself, but I guess you can change color by overriding OnCtlColor. Check for CTLCOLOR_SCROLLBAR in msdn.
If you would like a more custom draw get the scrollbars from the window using GetScrollBarCtrl and subclass them to your own derivation of CScrollBar.
/moliate
|
|
|
|
|
Yes, I`m want a more custom draw, but GetScrollBarCtrl returns NULL for windows style scrollbars
I would like to know, how can I subclass this scrollbars?
|
|
|
|
|
Hello, I want to display a clock on a dialog box. I want to do both an "analog clock" as well as a "digital clock". If you can help me as to resources to help me do this I would appreciate it.
Thanks.
|
|
|
|
|
You'll probably have to code an analog clock yourself, but how you would go about doing this would be to create a TIMERPROC, using SetTimer, that is updated every 1000 milliseconds or 1 second, then you would draw the analog clock every time the timer is executed according to the time provided by GetSystemTime. If you wanted the digital equivlant you would of course, just use GetTimeFormat, and print it out to the screen.
For a digital type look try :
http://www.codeproject.com/staticctrl/cstatictime.asp
Try MSDN for information on the stuff listed above.
Nathan
modified on Sunday, April 19, 2009 12:26 AM
|
|
|
|
|
Thanks, that is what I figured I would have to do. Thanks for your input.
|
|
|
|
|
To draw the clock face you'll probably have to resort to trigonomentry. You might be able to precalculate some values, though I doubt it.
If you want something more complicated than simple lines you have to create a vector image then rotate the points. I think Joseph M Newcomer has written an article on this.. but it's late so I'll leave you to find it .
Remember -
sin x = OPP/HYP
cos x = ADJ/HYP
tan x = OPP/ADJ. You can use the radius of your clock minus some value (to get the correct size so you don't draw over the numbers of the clockface) for the length of the hypotenuse (sic?).
--
Andrew.
|
|
|
|