Qstring filedialogutils: getsavefiledir (const qstring & Tips/* = qstring () */, qwidget * parent/* = 0 */) {qstring result; browseinfo Bi = {0 }; if (! Tips. isempty () {Bi. lpsztitle = tips. UTF16 ();} If (parent) {Bi. hwndowner = (hwnd) parent-> winid ();} // bif_browseincludefiles | // used to display file bi. ulflags = bif_returnonlyfsdirs | bif_newdialogstyle; bi. lpfn = browsecallbackproc; // callback function lpitemidlist pidl = shbrowseforfolder (& BI); If (pidl! = NULL) {// else, user canceled tchar szpath [max_path]; If (shgetpathfromidlist (pidl, szpath) {result = qstring: fromutf16 (szpath );}} return result;} int callback browsecallbackproc (hwnd, uint umsg, lparam LP, lparam pdata) {lpitemidlist TMP = (lpitemidlist) pdata; qstring result; Switch (umsg) {case when: // sendmessage (hwnd, bffm_setselection, true, (lparam) szdir); break; Case Bffm_selchanged: // set the status window to the currently selected path. If (TMP! = NULL) {// else, user canceled tchar szpath [max_path]; If (shgetpathfromidlist (TMP, szpath) {result = qstring: fromutf16 (szpath );}} break;} return 0 ;}
Select file or folder dialog box --- With callback function