|
Just wondering, how do you check if a USB Stick is inserted? Can you recommend some reading or maybe you can post the code. Thanks!
|
|
|
|
|
Look into the
RegisterDeviceNotification API call
You can set the filter level based on the type of device
Typically u can set a filter for type GUID_CLASS_USB_DEVICE
Now any Window class has an OnDeviceChange handler that provides a notification mechanism and inside u can check for the type ( typically GUID type) to see if its a Mass Storage Device class
Engineering is the effort !
|
|
|
|
|
|
Iain Clarke wrote: Have you tried looking on a well know site full of programming articles? Perhaps in the system section?
That's about as useful as suggesting to look in the phone book under "tire repair" when you get a flat tire on your car. It would be more comprehensive, and a lot less tiring, to call the first name in the As and ask them what to do.
"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
|
|
|
|
|
Method 1:
CMyDialog mMyDialog;
mMyDialog.Create(CMyDialog::IDD, this);
Method 2:
CMyDialog* mptrMyDialog;
mptrMyDialog = new CMyDialog;
mptrMyDialog -> Create(CMyDialog::IDD, this);
In method 2, I have to call delete mptrMyDialog before closing, but in method 1, mMyDialog will be destroyed when its parent is closed, correct?
So why is method 2 generally the preferred way? Method 1 seems to me like the simpler way because you don't have to worry about deallocating.
|
|
|
|
|
acerunner316 wrote: So why is method 2 generally the preferred way?
It all depends on the individual (and where they may have copied their code from).
"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
|
|
|
|
|
acerunner316 wrote: in method 1, mMyDialog will be destroyed when its parent is closed, correct?
The windows object (HWND) will be destroyed when the parent is destroyed.
The CMyDialog object is destroyed when it goes out of scope. If it goes out of
scope while its wrapped HWND is valid, the Windows object (HWND) will be destroyed
as well.
I suppose which method you use (in addition to DavidCrow's reply) depends on the
desired scope of the object and/or whether you want it on the stack or the heap.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
acerunner316 wrote: In method 2, I have to call delete mptrMyDialog before closing
wrong. after !!!
otherwise, you delete a dialog still being displayed !
|
|
|
|
|
acerunner316 wrote: So why is method 2 generally the preferred way?
I never heared this before ... the 2 methods are exactly the same for me.
The only difference that I can see is that using pointers you can pass the pointer from function to function, or, in a class, you can store the dialog pointer on a member variable of that class.
Russell
|
|
|
|
|
method 2 is preferred because the purpose of Create is to create a modeless dialog
so imagine you have this function somewhere
<br />
void OpenMyModelessDialog()<br />
{<br />
CMyDialog mMyDialog;<br />
mMyDialog.Create(CMyDialog::IDD, this);<br />
}<br />
as soon as the function returns the modeless dialog will be destroyed OOPS!!!
|
|
|
|
|
VC++,CClientDC and OnDraw's CDC
What is the difference of drawing a geomtric shape in the CClientDC and OnDraw's CDC?
|
|
|
|
|
OnDraw's CDC is a CPaintDC - a DC obtained through the BeginPaint() API in response to WM_PAINT.
CClientDC is obtained with GetDC.
OnDraw's DC will have a clipping region selected into it which excludes areas outside the area that
needs repainting. With a CClientDC, you'd need to do that yourself.
They draw to the same place though
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a C++ Program which in which I have to read a XML file contents. The code is
#include "fstream.h"
#include "string.h"
#import "msxml2.dll" named_guids raw_interfaces_only
using namespace MSXML2;
using namespace std;
void main()
{
IXMLDOMDocumentPtr m_pXmlDoc;
IXMLDOMNodePtr m_pProductNode;
HRESULT hr = m_pXmlDoc.CreateInstance(MSXML2::CLSID_DOMDocument);
_variant_t vtFileName("my_xml.xml");
VARIANT_BOOL vtRetVal;
m_pXmlDoc->load(vtFileName,&vtRetVal);
}
The CreateInstance() call fails and m_pXmlDoc is NULL.
Why am I not getting the instance? What is wrong in this piece of code?
|
|
|
|
|
koumodaki wrote: The CreateInstance() call fails...
And the value of hr would be what?
"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
|
|
|
|
|
On my PC hr = -2147221008 while debugging......guess its some junk value
|
|
|
|
|
It appears you have failed to call CoInitialize() .
"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
|
|
|
|
|
Thanks David. I had not called CoInitialize(). It works now.
|
|
|
|
|
You have guessed wrong. Use the Error Lookup tool to get the description of that error.
|
|
|
|
|
Michael Dunn wrote: You have guessed wrong.
Well that hardly ever happens.
|
|
|
|
|
Try
HRESULT hr = m_pXmlDoc.CreateInstance( __uuidof(MSXML2::DOMDocument40));
This way, you ask explicitly for a DOM document version 4.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
I get an error while compiling.
error C2039: 'DOMDocument40' : is not a member of 'MSXML2'
error C2065: 'DOMDocument40' : undeclared identifier
Could you please tell me th eproper file to include?
|
|
|
|
|
*I* do
#import "../thirdparty/msxmlbase/msxmlinclude/msxml2.tlb" named_guids but the path will be totally different for you.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
I'm building an SDI app in VC++6. From Document, user can click on a button which opens a Dialog. Dialog has a CComboBox. The values of the CComboBox are populated from a dynamic array (~200 items) stored in the Document.
I figured out how to populate the CComboBox with static values using AddString in the InitDialog method of the Dialog.
BOOL CMslDatabase::OnInitDialog() <br />
{<br />
CDialog::OnInitDialog();<br />
m_msl_list.AddString("ICBM");<br />
m_msl_list.AddString("SRBM");<br />
return TRUE;<br />
}
Here's my problem. How do I pass the array to the Dialog so I can use AddString to populate the ComboBox with ~200 dynamic values?
|
|
|
|
|
penny black wrote: Here's my problem. How do I pass the array to the Dialog
You can do it when constructing the CMslDatabase object, or after by calling a CMslDatabase method. If you opt for the latter, be sure and do it before calling DoModal() .
penny black wrote: m_msl_list.AddString("ICBM");
Missles, eh?
"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
|
|
|
|
|
from where you call the dialog, something like (pseudo c++ code):
...
CMslDatabase dlg;
dlg.SetArray( m_YourArray );
dlg.DoModal();
...
class CMslDatabase
{
void SetArray ( std::vector& v ){ m_vector = v;};
std::vector< std::string > m_vector;
};
BOOL CMslDatabase::OnInitDialog()
{
CDialog::OnInitDialog();
std::vector< std::string >::iterator it = m_vector.begin();
while ( it != m_vector.end()
{
std::string aString = *it;
m_msl_list.AddString( aString.c_str() );
++it;
}
return TRUE;
}
|
|
|
|