Drive combination box

zhaozj2021-02-11  169

I believe that people who have used VB are interested in those drives, directories, and file list controls. There is no in the VC, I have to do it yourself. Here is the drive combination box control code I wrote.

/// DriveBox.h class CDriveBox: public CComboBoxEx {public: CDriveBox (); virtual ~ CDriveBox (); // Generated message map functionsprotected: // {{AFX_MSG (CDriveBox) afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct); //} } AFX_MSG DECLARE_MESSAGE_MAP () public: int GetSelDrive (); bool SetSelDrive (char drive); void Initialize (); private: void AddItem (char * path, int index); CImageList m_img; char m_drivers [50];}; // DriveBox.cpp: implementation file // #include "stdafx.h" #include "DriveBox.h" CDriveBox :: CDriveBox () {} CDriveBox :: ~ CDriveBox () {} BEGIN_MESSAGE_MAP (CDriveBox, CComboBoxEx) // {{AFX_MSG_MAP (CDriveBox) ON_WM_CREATE () //}} AFX_MSG_MAPEND_MESSAGE_MAP () /// CDriveBox message handlers int CDriveBox :: OnCreate (lPCREATESTRUCT lpCreateStruct) {if return -1 (CComboBoxEx :: OnCreate (lpCreateStruct) == -1); // TODO : Add your specialized creation code Here initialize (); return 0;} void cdrivebox :: initialize () {m_img.create (GetSystemMetrics), GetSystemMetrics (S M_CYSMICON), ILC_MASK | ILC_COLORDDB, 50, 50); m_img.SetBkColor (GetSysColor (COLOR_WINDOW)); SetImageList (& m_img); char * ptr, drivename [500]; GetLogicalDriveStrings (500, drivename); ptr = drivename; int index = 0; While (* ptr) {m_drivers [index] = * ptr; additem (ptr, index ); PTR = Strlen (PTR) 1;} setSeldrive ('c');} void cdrivebox :: additem (char * path , int index) {SHFILEINFO pathInfo, path_SelInfo; SHGetFileInfo (path, NULL, & pathInfo, sizeof (pathInfo), SHGFI_DISPLAYNAME | SHGFI_ICON | SHGFI_SMALLICON); SHGetFileInfo (path, NULL, & path_SelInfo, sizeof (path_SelInfo), SHGFI_DISPLAYNAME | SHGFI_ICON | SHGFI_OPENICON | SHGFI_SMALLICON INT icon =

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

New Post(0)