one must use "ChangeWindowMessageFilter". This is not an issue, this is normal UIPI (UAC) behavior.
Here is an example of a listbox that accept one or many dropped files, even if the program run elevated.
Code: Select all
#Define JumpCompiler "<D:\Dev\Free\Compiler\fbc64.exe>" '1.08.0
#Define JumpCompilerCmd "<-s gui -w pedantic "D:\Dev\Free\bas\~~Default.rc">"
'_____________________________________________________________________________
#define unicode
#Include Once "windows.bi"
#Include Once "win\shellapi.bi"
#Define Listbox 101
#Define ButtonExit 201
#Define MSGFLT_ALLOW 1
#Define WM_COPYGLOBALDATA &H0049
Declare Function ChangeWindowMessageFilter Lib "User32.dll" ALIAS "ChangeWindowMessageFilter" _
(BYVAL dwMessage AS DWORD, BYVAL dwFlag AS DWORD) AS LONG
Dim Shared As HINSTANCE hInstance : hInstance = GetModuleHandle(NULL)
'_____________________________________________________________________________
PRIVATE FUNCTION IsUserAdmin() AS BOOLEAN
DIM IsMember AS LONG
DIM AdministratorsGroup AS SID POINTER
DIM ntAuthority AS SID_IDENTIFIER_AUTHORITY = ({0, 0, 0, 0, 0, 5}) 'SECURITY_NT_AUTHORITY
IF AllocateAndInitializeSid(@NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID, _
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, _
@AdministratorsGroup) THEN
IF CheckTokenMembership(NULL, AdministratorsGroup, @IsMember) THEN
FUNCTION = IsMember
END IF
FreeSid(AdministratorsGroup)
END IF
END FUNCTION
'_____________________________________________________________________________
Function WndProc(ByVal hWnd As HWND, ByVal uMsg As UINT, ByVal wParam As WPARAM, ByVal lParam As LPARAM) As Integer
Static hListbox As HWND
Static hButtonExit As HWND
Static hFont As HFONT
Function = 0
Select Case (uMsg)
Case WM_CREATE
'Get Windows default font
Dim LogicalFont AS LOGFONT
SystemParametersInfo(SPI_GETICONTITLELOGFONT, SIZEOF(LOGFONT), @LogicalFont, 0)
hFont = CreateFontIndirect(@LogicalFont)
'Button
hButtonExit = CreateWindowEx(0, "Button", "E&xit", _
WS_CHILD Or WS_VISIBLE Or BS_CENTER Or WS_TABSTOP Or _
BS_NOTIFY Or BS_TEXT Or BS_VCENTER, _
10, 325, 205, 30, _
hWnd, Cast(HMENU, ButtonExit), _
hInstance, NULL)
SendMessage(hButtonExit, WM_SETFONT, Cast(WPARAM, hFont), TRUE)
'Listbox
hListbox = CreateWindowEx(WS_EX_CLIENTEDGE OR WS_EX_ACCEPTFILES, "Listbox", "", _
WS_CHILD OR WS_VISIBLE OR WS_TABSTOP OR _ 'LBS_OWNERDRAWFIXED OR _ LBS_NODATA OR '
LBS_NOTIFY OR WS_TABSTOP OR WS_VSCROLL, _ ' OR WS_HSCROLL
10, 10, 205, 310, _
hWnd, Cast(HMENU, Listbox), _
hInstance, NULL)
SendMessage(hListbox, WM_SETFONT, Cast(UInteger, hFont), TRUE)
Dim sInfo As wString * 64
sInfo = "Drop a file or a group of files on this listbox"
SendMessage(hListbox, LB_ADDSTRING, 0, Cast(lParam, Sadd(sInfo)))
'Accept or refuse drop
'DragAcceptFiles(hListbox, False)
'DragAcceptFiles(hListbox, True)
If IsUserAdmin() Then
'Enable Drop on Elevated Application from a non-elevated application
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ALLOW)
ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ALLOW)
ChangeWindowMessageFilter(WM_COPYGLOBALDATA, MSGFLT_ALLOW)
End If
Case WM_COMMAND
Select Case LoWord(wParam)
Case ButtonExit, IDCANCEL
If HiWord(wParam) = BN_CLICKED Then
PostMessage(hWnd, WM_CLOSE, 0, 0)
Exit Function
EndIf
End Select
Case WM_DROPFILES
Dim DroppedFileCount As Long
Dim FileIndex As Long
Dim wFileName As wString * Max_Path
DroppedFileCount = DragQueryFile(Cast(hDrop, wParam), MAXDWORD, BYVAL 0, 0) 'Get dropped files count
For FileIndex = 0 TO DroppedFileCount - 1
DragQueryFile(Cast(hDrop, wParam), FileIndex, wFileName, Max_Path) 'Get every files
SendMessage(hListbox, LB_ADDSTRING, 0, Cast(lParam, Sadd(wFileName)))
SendMessage(hListbox, LB_SETCURSEL, SendMessage(hListbox, LB_GETCOUNT, 0, 0) - 1, 0) 'Select an item and scroll it to view
Next
'Get control handle from dropped mouse cursor position
'DragQueryPoint(hDrop, CursorPos)
'MapWindowPoints(hWnd, %HWND_DESKTOP, CursorPos, 1)
'hWindowFromPoint = WindowFromPoint(CursorPos)
DragFinish(Cast(hDrop, wParam)) 'Releases memory that Windows allocated for the drag buffer
Case WM_SIZE
If wParam <> SIZE_MINIMIZED Then
Dim As LONG SizeX = LOWORD(LPARAM)
Dim As LONG SizeY = HIWORD(LPARAM)
MoveWindow(hListbox, 10, 10, SizeX - 20, SizeY - 50, TRUE)
MoveWindow(hButtonExit, 10, SizeY - 35, SizeX - 20, 30, TRUE)
End IF
Case WM_DESTROY
DeleteObject(hFont)
PostQuitMessage(0)
Exit Function
End Select
Function = DefWindowProc(hWnd, uMsg, wParam, lParam)
End Function
'_____________________________________________________________________________
Function WinMain(ByVal hInstance As HINSTANCE, ByVal hPrevInst As HINSTANCE, _
ByVal CmdLine As WString Ptr, ByVal CmdShow As Integer) As UINT
Dim wsAppName As WString * 64
Dim WinClass As WNDCLASS
Dim WindowSize As SIZEL
Dim hWnd As HWND
Dim wMsg As MSG
wsAppName = "GetDroppedFiles" & SizeOf(UInteger) * 8
WindowSize.cx = 600
WindowSize.cy = 200
WinClass.hIcon = ExtractIcon(hInstance, "%SystemRoot%\system32\shell32.dll", 293) 'o
WinClass.style = CS_HREDRAW Or CS_VREDRAW
WinClass.lpfnWndProc = ProcPtr(WndProc)
WinClass.cbClsExtra = 0
WinClass.cbWndExtra = 0
WinClass.hInstance = hInstance
WinClass.hCursor = LoadCursor(NULL, IDC_ARROW)
WinClass.hbrBackground = Cast(HGDIOBJ, COLOR_BTNFACE + 1) 'Default color
WinClass.lpszMenuName = NULL
WinClass.lpszClassName = @wsAppName
If (RegisterClass(@WinClass)) Then
hWnd = CreateWindowEx(WS_EX_WINDOWEDGE, _
wsAppName, wsAppName, _
WS_OVERLAPPED OR WS_CLIPCHILDREN Or WS_DLGFRAME Or WS_BORDER Or WS_VISIBLE Or WS_CAPTION Or _
WS_MAXIMIZEBOX Or WS_MINIMIZEBOX Or WS_SIZEBOX Or WS_SYSMENU , _
(GetSystemMetrics(SM_CXSCREEN) - WindowSize.cx) / 2, _ 'PosX
(GetSystemMetrics(SM_CYSCREEN) - WindowSize.cy) / 2, _ 'PosY
WindowSize.cx, WindowSize.cy, _ 'SizeX, SizeY
NULL, NULL, hInstance, NULL)
ShowWindow(hWnd, SW_SHOW)
UpdateWindow(hWnd)
While GetMessage(@wMsg, ByVal NULL, 0, 0) > 0
If IsDialogMessage(hWnd, @wMsg) = 0 Then
TranslateMessage(@wMsg)
DispatchMessage(@wMsg)
End If
Wend
End If
DestroyIcon(WinClass.hIcon)
Function = wMsg.message
End Function
'_____________________________________________________________________________
End WinMain(hInstance, NULL, Command(), SW_NORMAL) 'Call main() and return the error code to the OS
'_____________________________________________________________________________
'