Mfc usb flash drive detection)

Source: Internet
Author: User
Mfc usb flash drive detection (transfer)

15:13:13 | category: Technical miscellaneous | font size subscription

There are only two or three lines on the road, so it is useless.

I thought how difficult the program was to detect the insertion of a USB flash drive. It turned out that it was so simple. A message ing of MFC could be done. I really couldn't think of it. Let's just talk about it.

First, we can see this stuff

Statement:

Afx_msg bool onDevicechange (uint neventtype, DWORD dwdata );

Implementation:

Bool CXXX: OnDevicechange (uint neventtype, DWORD dwdata)

Let's look at the Declaration first. It is obviously a message response function. I searched the whole application and did not find the message macro corresponding to it, which is so depressing. this .. this does not challenge my understanding of MFC.

Come up with the sword msdn. Look at how you run it!

Msdn says:

The framework callthis member function to operate y an application or device driver of a change
The hardware configuration of a device or the computer framework calls this function to notify the application or device driver that the hardware configuration or computer configuration has been changed.

I did not think that the framework was calling it! Unexpectedly, such a function that does not find macro-ming macro is actually the essence! Another look is the cwnd member function. I really want to slap myself! Cwnd has read it for n times and has never seen it .!

But .... But... Stop! Although the framework is being called, it also needs to be mapped. This is common sense. Can't it always challenge my common sense? Wm_paint is also a system call, and it has a macro ing!

I continued to look for. I looked for. on_wm_devicechange (). After reading N for a long time, I finally saw it. But why did I not see this message in the message? Ignore it and test it in the applet.

For a message, first, it is a system call, so don't worry about it.

Second, the message is nothing more than the three things. Declaration, ing, implementation.

Once again, all three of them can be responded to in any MFC!

Therefore, the following are extracted:

Begin_message_map (ogrgfrmrepair, cdialog)

// {Afx_msg_map (ogrgfrmrepair)

//} Afx_msg_map

On_wm_devicechange () // This is the essence

End_message_map ()

Bool ogrgfrmrepair: OnDevicechange (uint neventtype, DWORD dwdata)

{

// Here, you can test the status of the USB flash drive or other hardware. The key is the on_wm_devicechange message. different States can be determined based on the neventtype value. this message corresponds to this processing function, so you can do what you want here. haha... Let's take a look at msdn. The above is much clearer than I said.

If (neventtype = dbt_deviceremovecomplete)

{

// Do something

}

For the following statement, msdn says: a device has been inserted and is now available (a device is inserted and available now... Isn't that a USB flash drive?

If (neventtype = dbt_devicearrival)

{

// Do something

}

}

Afx_msg bool onDevicechange (uint neventtype, DWORD dwdata );

It has been tested and proved that it is in the detection of the U disk status. The specific msdn instructions are as follows:Devicechange can be found as a keyword.

However, it is strange that there is no response to this message to complete the message mechanism in a forward manner .? Is msdn correct or is it not public? Wait for the answer to be revealed.

Answer on the network:

It is a hidden windows message and cannot be seen in classwizard!

Ms is too unfriendly!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.