Guest User

get_directory(dname)

a guest
Mar 15th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void ClientResize(HWND hWnd, int nWidth, int nHeight)
  2. {
  3.     RECT rcClient, rcWind;
  4.     POINT ptDiff;
  5.     GetClientRect(hWnd, &rcClient);
  6.     GetWindowRect(hWnd, &rcWind);
  7.     ptDiff.x = (rcWind.right - rcWind.left) - rcClient.right;
  8.     ptDiff.y = (rcWind.bottom - rcWind.top) - rcClient.bottom;
  9.     MoveWindow(hWnd, rcWind.left, rcWind.top, nWidth + ptDiff.x, nHeight + ptDiff.y, TRUE);
  10. }
  11.  
  12. static UINT APIENTRY OFNHookProcOldStyle(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  13. {
  14.     if (uMsg == WM_INITDIALOG)
  15.     {
  16.         ClientResize(hWnd, 424, 255);
  17.  
  18.         RECT rect;
  19.         GetWindowRect(hWnd, &rect);
  20.         MoveWindow(hWnd, (GetSystemMetrics(SM_CXSCREEN) / 2) - ((rect.right - rect.left) / 2), (GetSystemMetrics(SM_CYSCREEN) / 2) - ((rect.bottom - rect.top) / 2), rect.right - rect.left, rect.bottom - rect.top, true);
  21.  
  22.         HWND bttn1 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, NULL, "Button", "OK")));
  23.         HWND bttn2 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, NULL, "Button", "Cancel")));
  24.         HWND list1 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, NULL, "ListBox", NULL)));
  25.         HWND list2 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, list1, "ListBox", NULL)));
  26.         HWND label1 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, NULL, "Static", "File &name:")));
  27.         HWND label2 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, NULL, "Static", "&Folders:")));
  28.         HWND label3 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, NULL, "Static", "List files of &type:")));
  29.         HWND label4 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, NULL, "Static", "Dri&ves:")));
  30.         HWND label5 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, label2, "Static", NULL)));
  31.         HWND cmbbx1 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, NULL, "ComboBox", NULL)));
  32.         HWND cmbbx2 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, cmbbx1, "ComboBox", NULL)));
  33.         HWND txtbx1 = GetDlgItem(hWnd, GetDlgCtrlID(FindWindowEx(hWnd, NULL, "Edit", NULL)));
  34.  
  35.         SetWindowText(label1, "&Files: (*.*)");
  36.         SetWindowText(label2, "&Directories:");
  37.         SetWindowText(label3, "Directory &Name:");
  38.         SetWindowText(label4, "D&rives:");
  39.         EnableWindow(list1, FALSE);
  40.         DestroyWindow(cmbbx1);
  41.         DestroyWindow(txtbx1);
  42.  
  43.         MoveWindow(bttn1, 257, 225, 74, 27, true);
  44.         MoveWindow(bttn2, 341, 225, 74, 27, true);
  45.         MoveWindow(label1, 232, 56, 72, 16, true);
  46.         MoveWindow(label2, 8, 56, 72, 16, true);
  47.         MoveWindow(label3, 8, 8, 93, 16, true);
  48.         MoveWindow(label4, 232, 176, 50, 16, true);
  49.         MoveWindow(label5, 8, 24, 409, 16, true);
  50.         MoveWindow(list1, 232, 72, 185, 93, true);
  51.         MoveWindow(list2, 8, 72, 213, 123, true);
  52.         MoveWindow(cmbbx2, 232, 192, 185, 19, true);
  53.  
  54.         ShowScrollBar(list1, SB_BOTH, FALSE);
  55.         ShowScrollBar(list2, SB_BOTH, FALSE);
  56.     }
  57.  
  58.     if (uMsg == WM_COMMAND && HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDOK)
  59.     {
  60.         PostMessage(hWnd, WM_COMMAND, IDABORT, 0);
  61.         return TRUE;
  62.     }
  63.  
  64.     return FALSE;
  65. }
  66.  
  67. DLL char *get_directory(char *dname)
  68. {
  69.     OPENFILENAMEW ofn;
  70.  
  71.     HWND SitehWnd;
  72.     SitehWnd = GetAncestor(GetActiveWindow(), GA_ROOTOWNER);
  73.  
  74.     string str_dname = dname;
  75.  
  76.     tstring tstr_filter = widen("*.*|*.*|");
  77.     replace(tstr_filter.begin(), tstr_filter.end(), '|', '\0');
  78.     tstring tstr_dname = widen(str_dname);
  79.     tstring tstr_title = widen("Select Directory");
  80.  
  81.     WCHAR wstr_dname[MAX_PATH];
  82.     wcsncpy_s(wstr_dname, tstr_dname.c_str(), MAX_PATH);
  83.  
  84.     ZeroMemory(&ofn, sizeof(ofn));
  85.     ofn.lStructSize = sizeof(ofn);
  86.     ofn.hwndOwner = SitehWnd;
  87.     ofn.lpstrFile = wstr_dname;
  88.     ofn.nMaxFile = MAX_PATH;
  89.     ofn.lpstrFilter = tstr_filter.c_str();
  90.     ofn.nFilterIndex = 0;
  91.     ofn.lpstrTitle = tstr_title.c_str();
  92.     ofn.lpstrInitialDir = NULL;
  93.     ofn.Flags = OFN_NONETWORKBUTTON | OFN_ENABLEHOOK | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_LONGNAMES;
  94.     ofn.lpfnHook = OFNHookProcOldStyle;
  95.    
  96.     GetOpenFileNameW(&ofn);
  97.    
  98.     DWORD attrib = GetFileAttributesW(wstr_dname);
  99.  
  100.     if (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY))
  101.     {
  102.         static string result;
  103.         result = shorten(wstr_dname);
  104.         return (char *)result.c_str();
  105.     }
  106.  
  107.     return (char *)"";
  108. }
Add Comment
Please, Sign In to add comment