|
Thanks, It is definitely possible although I can't gaurentee reliability especially in the presence of many and varied dodgy USB devices and exotic drive configurations. USB is such a mess.
I had to implement this and a bit more to auto detect USB drives inserted in a PC and show them by Drive letter. Explorer does this all the time so it should be trivial
Microsoft do so like to make our lives interesting though
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
This has got me interested!
Explorer doesn't need to go through these conniptions. It just monitors WM_DEVICECHANGE. I just made a quickie MFC app, and added a few lines which detect drives being added and removed:
#include <dbt.h>
...
ON_WM_DEVICECHANGE ()
...
BOOL CMainFrame::OnDeviceChange( UINT nEventType, DWORD dwData )
{
BOOL bReturn = CWnd::OnDeviceChange (nEventType, dwData);
TRACE1("Event %i\n", nEventType);
DEV_BROADCAST_VOLUME *volume = (DEV_BROADCAST_VOLUME *)dwData;
if (nEventType == DBT_DEVICEARRIVAL)
{
if (volume->dbcv_devicetype == DBT_DEVTYP_VOLUME)
{
for (int n = 0; n < 32; n++)
{
if (IsBitSet (volume->dbcv_unitmask, n))
{
TRACE1("Drive %c: Inserted\n", n + 'A');
}
}
}
}
if (nEventType == DBT_DEVICEREMOVECOMPLETE)
{
if (volume->dbcv_devicetype == DBT_DEVTYP_VOLUME)
{
for (int n = 0; n < 32; n++)
{
if (IsBitSet (volume->dbcv_unitmask, n))
{
TRACE1("Drive %c: Removed\n", n + 'A');
}
}
}
}
return bReturn;
}
Which works nicely. I tested on a memory stick which actually adds two partitions. Either yaking it out, or nicely removing using the gizmo on the systray works nicely.
I think I may just turn this into a mini article!
Iain.
|
|
|
|
|
|
Splitters seem like a popular topic. I have found several examples here, elsewhere, and in the forums. But I can't seem to find any which answer my question.
I am converting a Borland C++ application to MFC. The application has a split window with a Tree on the left side, and multiple windows on the other. Basically, the right side is similar to MDI allowing for multiple windows to display at one time.
From all my research today, it seems like splitters allow for only a single window at a time and the window will fill/maximize the entire split window. Is there some way to get multiple windows within a split window?
I may start looking at Borland's internal code to find out how they do it. Or my boss may end up deciding to scrap the multiple window idea. I suspect it is not really a major feature as most people probably maximize the window anyway.
Thanks in advance for help or pointers.
|
|
|
|
|
I think I may have found what I need. I don't believe what I'm asking is possible. I finally found a thread over on MSDN[^] with someone asking a very similar question.
I am now going to take the approach of using a CDialogBar[^].
Still open to suggestions, though.
|
|
|
|
|
After reading your message, CDialogBar is exactly what I would suggest for you. It'll work, and it will be nice and easy to implement.
Glad to see you found your own solution!
Iain.
|
|
|
|
|
Thanks for the feedback. I spent all day at work trying to figure this out and found it last night while continuing my search at home.
As a sidenote, Borland OWL separates the MDIFrame from the MDIClient with distinct classes. MFC does not have this distinction, so I am having to combine the two Borland classes we have into a single CMDIFrameWnd derived class.
|
|
|
|
|
You can create another splitters in first splitter right pane and and put your windows here - vertical or horizontal or some other layout you like
|
|
|
|
|
Hi All,
I have to open a binary file and read the line. then compare the line with some string.
My code is:
<br />
ifstream aBinaryfile; <br />
string sinfo; <br />
aBinaryfile.open(fName,ios::in|ios::binary );
getline(aBinaryfile,sinfo);
CString info(sinfo.c_str());
<br />
if(info.CompareNoCase(TEXT("FirstLine"))==0<br />
{<br />
AfxMessageBox("Match"); <br />
}<br />
else <br />
{<br />
AfxMessageBox("not Match");<br />
}<br />
The result suppose to be display "Match" but right now I'm getting "not Match" eventhough content of info is "FirstLine".
Why they both are not equal when both are suppose to be equal?
Is it because I was reading the binary file?
Thank you.
|
|
|
|
|
It doesn't make sense to open a file in binary mode and then use getline, which (sorta) by
definition, is a text-mode method.
I'm pretty sure the string you read has the newline character at the end, which is NOT a match to
your compare string.
if you remove the ios::binary flag it should work
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
The file contains eastern chars in the file.
In order to read the eastern chars I think I do need to open it in binary mode, dont' I?
thanks.
|
|
|
|
|
The file that I have to read is UTF-8 text file. And it contains file name that is in eastern characters like Chinese, Japanese, Jew, etc. as shown in following;
[begin file names]
file1 : c:\temp\פסטיבל סגול ה- 11 - למדיטציה ואהבה.txt
file2 : c:\temp\sampleDocument.doc
file3 : c:\temp\日本側とのアレン.jpg
[/begin file names]
I need to store those info, file name, in the same way they appear in the text file.
then I have to open those files after I got the name of the file with path from the UTF-8 text file. Therefore, I tried to open the file in the binary mode.
Right now,
1) I read the first line, "[begin file names]", then
2) I have to compare if the string that i just read is "[begin file names]" using CString::CompareNoCase(strRead,"[begin file names]")
3) read the next line, which is "file1 : c:\temp\פסטיבל סגול ה- 11 - למדיטציה ואהבה.txt",
if CompareNoCase return zero.
4) store the file name
.
.
.
etc.
right now I am getting "file1: ?????? 11 ????.txt.
How can I read the UTF-8 file so I can get the information from the file correctly ?
I'm using regular C++.
Thanks
thanks.
|
|
|
|
|
pnpfriend wrote: right now I am getting "file1: ?????? 11 ????.txt
You're getting that where? If you look at the string in binary, are all those question marks
the same multibyte character?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Did you consider setting Breakpoints ?
Set a Breakpoint, and SingleStep through the Code. Make (Mental)notes at what you expect to see. vs what's showing. All of us have to do this All the Time,
It's Called 'Debugging'
LateNightsInNewry
|
|
|
|
|
In addition to the other suggestions, why exactly are you mixing MFC (CString ) with STL (string )? There's no reason to use a CString object just for the sake of comparing.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I tried to use MFC CString becasue there is CompareNoCase().
|
|
|
|
|
bool compareNoCase( const char c1, const char c2 )
{
return toupper(c1) == toupper(c2);
}
...
string str,
strComp("FirstLine");
if (str.size() == strComp.size() &&
equal(str.begin(), str.end(), strComp.begin(), compareNoCase))
{
cout << "The strings are equal." << endl;
}
else
cout << "The strings are not equal." << endl;
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
For example.
typedef [v1_enum] enum _outlinestyle
{
NoOutline = 0,
SolidLine = 1,
Dash = 2,
Dots = 3,
DashDot = 4,
DashDotDot = 5
} OutLineStyles;
Then I have
[propget, id(33), helpstring("Select one of types:No Outline,Solid,Dash,Dots etc.")] HRESULT OutlineType([out, retval] OutLineStyles* pVal);
[propput, id(33), helpstring("Select one of types:No Outline,Solid,Dash,Dots etc.")] HRESULT OutlineType([in] OutLineStyles newVal);
The PropertyGrid will automatically use
OutlineType one the left side and the following as the selections.
NoOutline
SolidLine
Dash
Dots
DashDot
DashDotDot
What is I want the change "OutlineType" to another language in the PropertyGrid? Same for all the selections. I can't really change the function name to another language. How can I saolve this?
Thanks.
|
|
|
|
|
Call me a late bloomer, but I've been maintaining code for MFC 4.2 and 7.1 for a while and I just noticed in the Visual C++ 2003 documentation does not indicate that CObject::operator new throws MFC exceptions.
What happended to CMemoryException from MFC 4.2?
I'm not sure if this new operator (For CObject) throws or returns a NULL pointer in MFC 7.1. Sorry about the silly question.
|
|
|
|
|
Looking at the source code in VS 2003 .NET, CObject::operator new doesn't throw any MFC
exceptions.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I saw the ::operator new in there but it kinda confuses me as to what it does in the Microsoft compiler. (By default, if there is such a thing)
I've been crawling through MSDN for Visual C++ 2003 for a bit and it's really not clear if ::operator new throws or returns a NULL in Visual C++ 2003.
|
|
|
|
|
bob16972 wrote: and it's really not clear if ::operator new throws or returns a NULL in Visual C++ 2003
Have you seen this article?
The new and delete Operators[^]
I didn't say it would be any more clear after reading this article
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Have I Seen this Article before? No,
Reading the Original Question, I had not seen this article either! Sounds quite Drastic,BUT there is only one additional burden, and that is to register an exception handler as early as possible,(i.e Before any NULL Pointer can occur in User Code. InitApp() seems to be a good place.
At the other hand, very many of us spend most of our coding time to write 'if's' and 'but's to deal with faulting. This clutters up the general flow of the code we write. Exception handeling is in practice seldomly used as a mechanism, mainly because it is complex in nature, and not worth the bother.
This suttle change will hopefully be the impetus for people to learn about the syntax of exception handeling, and ultimately make code and program Syntax clearer.
LateNightsInNewry
|
|
|
|
|
Mark Salsbery wrote: I didn't say it would be any more clear after reading this article
I gave both the local MSDN and the latest online one a go earlier today when the subject came up at work and I was thrown off guard when CObject no longer advertised that it could throw in the 2003 MSDN. I came across this article but it left a few questions still hanging.
Mark Salsbery wrote: I didn't say it would be any more clear after reading this article
ain't it the truth.
Thanks for taking the time out to assist.
|
|
|
|
|
It looks like it's documented under "CMemoryException class" and here:
Exception Handling in MFC[^]
For MFC apps, CMemoryException is thrown, even on non-CObject objects.
For non-MFC apps, std::bad_alloc is thrown.
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|