CRazY ABouT/programming

[Delphi] UAC(User Account Control) Drag and Drop

띵스 2017. 12. 21. 10:16

윈도우에서 사용자 권한에 의해 윈도우 메시지를 못 받는 경우가있다.

임의로 추가하여 처리해 주어야 함.


Drag and Drop 예제

- 소스내 주석으로는 2004년에 Peter D Johnson라는 사람이 올린 소스를 수정하였음.



중요한 것은 권한 추가!

아래 함수를 추가하면 된다.


procedure SetDragAndDropOnSystemsWIthUAC(Wnd: HWND; IsEnabled: boolean);


procedure TForm1.SetDragAndDropOnSystemsWIthUAC(Wnd : HWND; IsEnabled : boolean);

type

  TChangeWindowMessageFilter = function(Msg : Cardinal; Action : Word) : Bool; stdcall;

const

  Msg_Add = 1;

  WM_COPYGLOBALDATA = $49;

var

  DllHandle : THandle;

  ChangeWindowMessageFilter : TChangeWindowMessageFilter;

begin

  DllHandle := LoadLibrary('user32.dll');

  if DllHandle > 0 then

  begin

    ChangeWindowMessageFilter := GetProcAddress(DllHandle, 'ChangeWindowMessageFilter');

    if Assigned(ChangeWindowMessageFilter) then

    begin

      DragAcceptFiles(Wnd, IsEnabled);

      ChangeWindowMessageFilter(WM_DROPFILES, Msg_Add);

      ChangeWindowMessageFilter(WM_COPYGLOBALDATA, Msg_Add);

    end;

  end;

end;


procedure TForm1.FormCreate(Sender: TObject);

begin

  // Tell windows we accept file drops

  SetDragAndDropOnSystemsWIthUAC(Self.Handle, True);

end;


procedure TForm1.FormDestroy(Sender: TObject);

begin

  // Cancel acceptance of file drops

  SetDragAndDropOnSystemsWIthUAC(Self.Handle, False);

end;


DragAndDropWithUAC.7z