Increases processing method without columns in ClassWizard

zhaozj2021-02-16  51

Increased in ClassWizard's handling method to do a small program today, use the WM_DEVICECHANGE message and the corresponding AFX_MSG Bool OnDeviceChange (Uint NeventType, DWORD DWDATA) function, and the result is found that this function is not listed in ClassWizard, even I changed to Windows in ClassWizard's Class Info tab, and there is no message. In fact, the function in ClassWizard has only columnized some of the most commonly used parts, not all (because all messages are too much), so to deal with WM_DeviceChange message You can only add code by manual, and finally I finally discovered the process of processing. It is basically divided into three steps: 1. Add a member function in the class declaration PROTECTED: AFX_MSG BOOL OONDEVICECHANGE (Uint NeventType, DWORD DWDATA);

2. Add function body BOOL OnDeviceChange (UINT, DWORD) in the respective cpp files; BOOL CXXXXX :: OnDeviceChange (UINT nEventType, DWORD dwData) {if (nEventType == DBT_DEVICEARRIVAL) MessageBox ( "CD arrival", "Note" , MB_OK MB_ICONITIONFORMATION; RETURN TRUE;}

3. Was added BEGIN_MESSAGE_MAP (CXXXXXX, CDialog) message map macro // {{AFX_MSG_MAP (CTest031Dlg) ON_WM_SYSCOMMAND () ON_WM_PAINT () ON_WM_QUERYDRAGICON () //}} AFX_MSG_MAP ON_WM_DEVICECHANGE () // sentence is added to the map NOTE: Be sure to Put this sentence in two AFX_MSG_MAP END_MESSAGE_MAP () In general, the corresponding message mapping mutual statement is similar to the message itself, as long as the corresponding message is added to ON_ and suffix (), for example: for WM_Something Message, its corresponding message mapping macro statement is ON_WM_Something (), if you want to confirm, you can find verifications in the MSDN correctly.

转载请注明原文地址:https://www.9cbs.com/read-27361.html

New Post(0)