Advertisement
HEX0x29A

Создать папку в текущей папке проводника

Dec 31st, 2019
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.53 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     procedure FormDestroy(Sender: TObject);
  12.     procedure FormCreate(Sender: TObject);
  13.   private
  14.     MyHotKey: WORD;
  15.     procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
  16.   public
  17.     { Public declarations }
  18.   end;
  19.  
  20. var
  21.   Form1: TForm1;
  22.  
  23. implementation
  24.  
  25. {$R *.dfm}
  26. //https://otvet.mail.ru/question/217917260
  27. const
  28.   DirName = 'Q217917260';
  29.  
  30. function ExplorerDir(): string;
  31. var
  32.   Buf: PWideChar;
  33.   hWin: HWND;
  34.   n: Integer;
  35. begin
  36.   hWin := FindWindowW('CabinetWClass', nil);
  37.   if hWin = 0 then
  38.     Exit;
  39.   n := GetWindowTextLengthW(hWin);
  40.   if n > 0 then
  41.   try
  42.     Inc(n);
  43.     GetMem(Buf, n);
  44.     ZeroMemory(Buf, n);
  45.     n := GetWindowTextW(hWin, Buf, n);
  46.     Result := Copy(Buf, 1, n);
  47.   finally
  48.     FreeMem(Buf);
  49.   end;
  50. end;
  51.  
  52. procedure TForm1.WMHotKey(var Msg: TWMHotKey);
  53. var
  54.   DN: WideString;
  55. begin
  56.   if Msg.HotKey = MyHotKey then
  57.   begin
  58.     try
  59.       DN := ExplorerDir + '\' + DirName;
  60.       CreateDirectoryW(PWideChar(DN),  nil);
  61.     except
  62.       on E: Exception do
  63.         E.CreateFmt('Error: ', [E.Message]);
  64.     end;
  65.   end;
  66. end;
  67.  
  68. procedure TForm1.FormDestroy(Sender: TObject);
  69. begin
  70.   UnRegisterHotKey(Handle, MyHotKey);
  71.   GlobalDeleteAtom(MyHotKey);
  72. end;
  73.  
  74. procedure TForm1.FormCreate(Sender: TObject);
  75. begin
  76.   MyHotKey := GlobalAddAtom('CTRL+L');
  77.   RegisterHotKey(Handle, MyHotKey, MOD_CONTROL, Ord('L'));
  78. end;
  79.  
  80. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement