Advertisement
Guest User

get_directory(dname)

a guest
Mar 18th, 2018
131
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. WCHAR wstr_dname[MAX_PATH];
  13.  
  14. UINT APIENTRY OFNHookProcOldStyle(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  15. {
  16.     if (uMsg == WM_INITDIALOG)
  17.     {
  18.         ClientResize(hWnd, 424, 255);
  19.  
  20.         RECT rect;
  21.         GetWindowRect(hWnd, &rect);
  22.         MoveWindow(hWnd,
  23.             (GetSystemMetrics(SM_CXSCREEN) / 2) - ((rect.right - rect.left) / 2),
  24.             (GetSystemMetrics(SM_CYSCREEN) / 2) - ((rect.bottom - rect.top) / 2),
  25.             rect.right - rect.left, rect.bottom - rect.top, TRUE);
  26.  
  27.         HWND bttn1 = GetDlgItem(hWnd, IDOK);
  28.         HWND bttn2 = GetDlgItem(hWnd, IDCANCEL);
  29.         HWND list1 = GetDlgItem(hWnd, 1120);
  30.         HWND list2 = GetDlgItem(hWnd, 1121);
  31.         HWND label1 = GetDlgItem(hWnd, 1090);
  32.         HWND label2 = GetDlgItem(hWnd, 65535);
  33.         HWND label3 = GetDlgItem(hWnd, 1089);
  34.         HWND label4 = GetDlgItem(hWnd, 1091);
  35.         HWND label5 = GetDlgItem(hWnd, 1088);
  36.         HWND cmbbx1 = GetDlgItem(hWnd, 1136);
  37.         HWND cmbbx2 = GetDlgItem(hWnd, 1137);
  38.         HWND txtbx1 = GetDlgItem(hWnd, 1152);
  39.  
  40.         SetWindowText(label1, "&Files: (*.*)");
  41.         SetWindowText(label2, "&Directories:");
  42.         SetWindowText(label3, "Directory &Name:");
  43.         SetWindowText(label4, "D&rives:");
  44.         DestroyWindow(cmbbx1);
  45.         DestroyWindow(txtbx1);
  46.  
  47.         MoveWindow(bttn1, 256, 224, 77, 27, TRUE);
  48.         MoveWindow(bttn2, 340, 224, 77, 27, TRUE);
  49.         MoveWindow(label1, 232, 56, 72, 16, TRUE);
  50.         MoveWindow(label2, 8, 56, 72, 16, TRUE);
  51.         MoveWindow(label3, 8, 8, 93, 16, TRUE);
  52.         MoveWindow(label4, 232, 176, 50, 16, TRUE);
  53.         MoveWindow(label5, 8, 24, 409 * 100, 16, TRUE);
  54.         MoveWindow(list1, 232, 72, 185, 93, TRUE);
  55.         MoveWindow(list2, 8, 72, 213, 123, TRUE);
  56.         MoveWindow(cmbbx2, 232, 192, 185, 19, TRUE);
  57.  
  58.         DlgDirListW(hWnd, wstr_dname, 1120, 1088, DDL_ARCHIVE | DDL_READWRITE | DDL_READONLY);
  59.         PostMessageW(hWnd, WM_SETFOCUS, 0, 0);
  60.     }
  61.  
  62.     if (uMsg == WM_COMMAND && HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDOK)
  63.     {
  64.         HWND label1 = GetDlgItem(hWnd, 1090);
  65.         HWND label2 = GetDlgItem(hWnd, 65535);
  66.         HWND label3 = GetDlgItem(hWnd, 1089);
  67.         HWND label4 = GetDlgItem(hWnd, 1091);
  68.         HWND label5 = GetDlgItem(hWnd, 1088);
  69.  
  70.         GetDlgItemTextW(hWnd, 1088, wstr_dname, MAX_PATH);
  71.         PostMessageW(hWnd, WM_COMMAND, IDABORT, 0);
  72.         return TRUE;
  73.     }
  74.  
  75.     if (uMsg == WM_COMMAND && HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDCANCEL)
  76.     {
  77.         tstring tstr_dname = widen("");
  78.         wcsncpy_s(wstr_dname, tstr_dname.c_str(), MAX_PATH);
  79.         PostMessageW(hWnd, WM_COMMAND, IDABORT, 0);
  80.         return TRUE;
  81.     }
  82.  
  83.     if (uMsg == WM_CLOSE)
  84.     {
  85.         tstring tstr_dname = widen("");
  86.         wcsncpy_s(wstr_dname, tstr_dname.c_str(), MAX_PATH);
  87.         PostMessageW(hWnd, WM_COMMAND, IDABORT, 0);
  88.         return TRUE;
  89.     }
  90.  
  91.     return FALSE;
  92. }
  93.  
  94. DLL char *get_directory(char *dname)
  95. {
  96.     OPENFILENAMEW ofn;
  97.  
  98.     HWND SitehWnd;
  99.     SitehWnd = GetAncestor(GetActiveWindow(), GA_ROOTOWNER);
  100.  
  101.     string str_dname = dname;
  102.  
  103.     tstring tstr_filter = widen("*.*|*.*|");
  104.     replace(tstr_filter.begin(), tstr_filter.end(), '|', '\0');
  105.     tstring tstr_dname = widen(str_dname);
  106.     tstring tstr_title = widen("Select Directory");
  107.     tstring tstr_empty = widen("");
  108.  
  109.     if (tstr_dname == tstr_empty)
  110.         GetCurrentDirectoryW(MAX_PATH, wstr_dname);
  111.     else
  112.         wcsncpy_s(wstr_dname, tstr_dname.c_str(), MAX_PATH);
  113.  
  114.     ZeroMemory(&ofn, sizeof(ofn));
  115.     ofn.lStructSize = sizeof(ofn);
  116.     ofn.hwndOwner = SitehWnd;
  117.     ofn.lpstrFile = NULL;
  118.     ofn.nMaxFile = MAX_PATH;
  119.     ofn.lpstrFilter = tstr_filter.c_str();
  120.     ofn.nFilterIndex = 0;
  121.     ofn.lpstrTitle = tstr_title.c_str();
  122.     ofn.lpstrInitialDir = wstr_dname;
  123.     ofn.Flags = OFN_NONETWORKBUTTON | OFN_ENABLEHOOK | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_LONGNAMES;
  124.     ofn.lpfnHook = OFNHookProcOldStyle;
  125.  
  126.     GetOpenFileNameW(&ofn);
  127.  
  128.     DWORD attrib = GetFileAttributesW(wstr_dname);
  129.  
  130.     if (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY))
  131.     {
  132.         static string result;
  133.         result = shorten(wstr_dname);
  134.         return (char *)result.c_str();
  135.     }
  136.  
  137.     return (char *)"";
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement