It's kind of weird issue, let me try to explain. I wrote a (dialog based) app in c++/MFC that supports drag-n-dropping.
I do the following test on Windows 7 with default themes. My app is running on the screen. It is not a top window (in its z-order) or in other words it's obscured by other windows on top of it.
If I begin dragging a link or just a text selection from the Chrome or Firefox web browser, first into my app's icon on the taskbar, the icon flashes and my app pops up on the screen (by receiving the top z-order) so I can then drag-and-drop into my app. Everything works fine.
If I do the same from IE 9 (version 9.0.8112, update versions 9.0.12) when I drag selected text or a link first to the taskbar icon of my app to make my app become top window (in z-order), the app icon continues flashing but it never gets shown on the screen like it happens with Chrome or FF, so as a result I have to abandon my drag-and-drop.
Any idea why is it happening like that with IE and if there's a way to fix it?
EDIT: Here's the code sample in regards to my comments below:
HRESULT __stdcall DragEnter(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
{
//IDropTarget::DragEnter
m_fAllowDrop = QueryDataObject(pDataObject);
if(m_fAllowDrop)
{
//SUCCESS
// get the dropeffect based on keyboard state
}
else
{
//FAILURE
*pdwEffect = DROPEFFECT_NONE;
}
return S_OK;
}
BOOL QueryDataObject(IDataObject* pDataObject, int* pnOutDataType)
{
static FORMATETC fmtetc_file = {CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
static FORMATETC fmtetc_txt = {CF_UNICODETEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
BOOL bRes = FALSE;
HRESULT hr;
//See if our data type
hr = pDataObject->QueryGetData(&fmtetc_file);
if(hr == S_OK)
{
bRes = TRUE;
}
//In my case hr is E_FAIL or 0x80004005
hr = pDataObject->QueryGetData(&fmtetc_txt);
if(hr == S_OK)
{
bRes = TRUE;
}
//In my case hr is E_FAIL or 0x80004005
return bRes;
}
As part of its sandboxing to prevent unauthorized changes to the machine, Internet Explorer runs in a lower UIPI (User Interface Privilege Isolation) integrity level than other apps do. As such, it does not have permission to access your app by default, which is more likely to be running in a medium or high UIPI integrity level (depending on whether it is UAC elevated or not). The flashing taskbar button means that something is trying to bring your app to the foreground but does not have permission to do so (see the documentation of SetForegroundWindow() for more details). UIPI does not allow a lower-integrity process to send window messages to a higher-integrity process unless the receiving process explicitally tells UIPI to allow it. Chrome and FireFox are likely running in the same integrity level as your app. In order to support drag-and-drop from Internet Explorer, call ChangeWindowMessageFilter() or ChangeWindowMessageFilterEx() to let your app receive WM_DROPFILES, WM_COPYDATA, and WM_COPYGLOBALDATA (0x0049) messages from lower-integrity processes.
Update: It looks like Internet Explorer in particular imposes additional restrictions on drag&drop operations when it is running in Protected Mode:
How to handle drag & drop from low integrity Internet Explorer
Understanding and Working in Protected Mode Internet Explorer - Allowing Drag and Drop Operations in your Application
Related
I need to disable notifications at my app when there is another app fullscreen like powerpoint or VLC to do not bother a user.
For now, I get to this code, but it always returns true. Whether there is some app fullscreen or not. I am not sure whether this should work only for app bars or also taskbar.
HWND hWnd;
hWnd = FindWindow(L"Shell_TrayWnd", nullptr);
if( hWnd )
{
APPBARDATA apd;
apd.cbSize = sizeof(APPBARDATA);
apd.hWnd = hWnd;
bool uState = bool(SHAppBarMessage(ABN_FULLSCREENAPP , &apd));
if(uState)
qDebug()<<"fullscreen";
else
qDebug()<<"not fullscreen";
}
ABN_FULLSCREENAPP is not a message you send to the shell, it's a message the shell sends to you when an application enters or leaves full screen mode. The message is sent to the owner of an app bar created with ABM_NEW.
Documentation is here.
My reading of the documentation is that you have to create an app bar to receive this message but you may be able to set it to zero height or width with ABM_SETPOS if you want to hide it.
I'm trying to access text of Google Chrome's webpage to read it and offer some actions (for example, remind). Everything works good, but I need to enable accessibility inspection programmatically. I use this code:
wchar_t className[100];
GetClassName(hwnd, className, 100) == 0 || wcscmp(className, L"Chrome_WidgetWin_1");
CComPtr<IAccessible> pAccMain;
HRESULT hr = ::AccessibleObjectFromWindow(hWndChrome, 1, IID_IAccessible, (void**)(&pAccMain));
CComPtr<IAccessible> pAccMain2;
::AccessibleObjectFromWindow(hWndChrome, OBJID_CLIENT, IID_IAccessible, (void**)(&pAccMain2));
And nothing happens until I run browser with --force-renderer-accessibility parameter or manually change accessibility settings located in chrome://accessibility.
What am i doing wrong?
Found this info: "Chrome calls NotifyWinEvent with EVENT_SYSTEM_ALERT and the custom object id of 1. If it subsequently receives a WM_GETOBJECT call for that custom object id, it assumes that assistive technology is running". Does anybody know how to implement this?
Use SetWinEventHook, e.g.
HWINEVENTHOOK hook = SetWinEventHook(EVENT_SYSTEM_ALERT, EVENT_SYSTEM_ALERT,NULL, WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT)
Then in your WinEventProc, you'll be given a hWnd, idObject, and idChild when Chrome sends the EVENT_SYSTEM_ALERT.
If idObject == 1 then call AccessibleObjectFromEvent(), passing it those hWnd, idObject, and idChild arguments.
AccessibleObjectFromEvent will then send the WM_GETOBJECT. From the docs::
Applications never send this message directly. Microsoft Active Accessibility sends this message in response to calls to AccessibleObjectFromPoint, AccessibleObjectFromEvent, or AccessibleObjectFromWindow.
By using AccEvent I can see that Google Chrome only appears to send the EVENT_SYSTEM_ALERT when it starts, e.g. opening a new tab doesn't trigger it, so you'd need to have done the SetWinEventHook() before Chrome is launched.
I have an installation dialog (made with nsis) that has two buttons (install and cancel). I'm trying to write automated tests for the install process using low level win32 api. To click on the button(s) I use the following code:
char windowName[] = "Desktop Application Setup";
char cancelButtonText[] = "Cancel";
HWND hWndMainWindow = NULL;
HWND hButton = NULL;
hWndMainWindow = FindWindow(NULL, windowName);
if (hWndMainWindow)
{
hButton = FindWindowEx(hWndMainWindow, NULL, NULL, cancelButtonText);
if (hButton)
{
SendMessage(hButton, BM_CLICK, 0, 0);
}
}
On Windows 7, this works perfectly. On Windows 10, it simply does nothing. It finds the button, it sends the message, but the click just doesn't happen.
Is this some security thing introduced in Windows 10? Is it a known issue?
it is better to send WM_COMMAND with the ID of the button, but the way you are doing works also if Lang is always in English. but the problem with your case is that buttons on dialog usually have an "&" to indicate the keyboard short cut, and usually hidden by system unless you press alt key. (like menus).
so: text of the button is most likely to be "&cancel"
I am using GetForegroundWindow() from a service as i want to monitor the window that is in focus but the function is returning null on windows 7 due to interactive user problem. Is there any way by which i can get the focused window in my service?
HWINSTA hWinStaUser = OpenWindowStation(_T("WinSta0"), FALSE, MAXIMUM_ALLOWED);
if (SetProcessWindowStation(hWinStaUser))
{
/* -- Open user's desktop "Default". -- */
HDESK hDeskUser = OpenInputDesktop(0,FALSE,MAXIMUM_ALLOWED);
//HDESK hDeskUser = OpenDesktop(_T("Default"), 0, FALSE, MAXIMUM_ALLOWED);
/* -- Set thread desktop to "Default". -- */
if (SetThreadDesktop(hDeskUser))
{
HWND hwndActiveWin = GetForegroundWindow();
int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL);
if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) )
{
HWND hwndFocused = GetFocus (); // focused control within the active window, i.e. focus throughout the screen
if(hwndFocused != NULL)
{
DWORD dwProcessID = 0;
GetWindowThreadProcessId(hwndFocused, &dwProcessID);
processPid = dwProcessID;
}
AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
}
}
you need to understand the problem itself. services cannot interact with desktop because of security risk and because there can be many desktops (many logged in users). GetForegroundWindow() is an interaction with desktop. There's no simple workaround. Complicated one involves separate process running as windows application (not a service) and communicating with your service.
Please help me understand what I’m doing wrong!
I have a problem when I programmatically activate my IE toolbar from other program.
Making it following the instruction given at Microsoft support site (http://support.microsoft.com/kb/q255920/):
SHDocVw::IWebBrowser2Ptr pIE;
HRESULT hr = ::CoCreateInstance(CLSID_InternetExplorer, NULL,
CLSCTX_LOCAL_SERVER, IID_IWebBrowser2, (LPVOID*)&pIE);
if(FAILED(hr)) return;
try {
_variant_t vClsID;
_variant_t vVis;
_variant_t vNotUsed;
vClsID.vt = VT_BSTR;
vClsID.bstrVal = SysAllocString(OLESTR("{MY_TOOLBAR_GUID}"));
vVis.vt = VT_BOOL;
vVis.boolVal = VARIANT_TRUE;
vNotUsed.vt = VT_INT;
vNotUsed.intVal = 1;
hr = pIE->ShowBrowserBar()(&vClsID, &vVis, &vNotUsed);
SysFreeString(vClsID.bstrVal);
if(FAILED(hr)) return;
}catch(...) {return;}
pIE->Navigate2(&Url);
pIE->Visible = TRUE;
This code works correctly in IE7, but doesn't work in IE8. In both cases ShowBrowserBar() returns S_OK, but in IE8 toolbar.dll is not loaded into the browser, i.e. the toolbar is not activated and therefore not displayed.
I also tried to launch IE8 with three tabs and check if ShowBrowserBar() attempts to open the toolbar in the tabs, not the manager process.
It is log file:
Handle url 'outlook:'
ShowBrowserBar() FAILED!
Handle url 'http://www.handypassword.com'
ShowBrowserBar() SUCCESSED!
Handle url 'http://www.google.ru/'
ShowBrowserBar() SUCCESSED!
Handle url 'http://vkontakte.ru/'
ShowBrowserBar() SUCCESSED!
Everything works as expected in IE7, but not in IE8, and I can't understand why the ShowBrowserBar() method returns S_OK in both of them.
Has anybody got any clues?
Warm regards,
Anna.
I find an answer of this problem!
By default, any add-on or toolbar you install in Internet Explorer will be enabled; but it can later on become disabled (you can no longer use it), either because you or another Windows user has manually disabled it, or because a third-party installer in conflict automatically disabled it. If user disable toolbar manually you can't show it automatically! You need to re-enable the add-on, in Tools, Manage Add-Ons.