How to add the forbidden sign on the mouse cursor while drag icons in CEF (Chromium Embedded Framework)? - chromium-embedded

When I drag an item on the browser, if it is dragged to another window, I want the mouse cursor shows the forbidden sign like this:

In your implementation of IDropTarget::DragOver check if you allow your drop (according to your "another window" rule) then change the cursor with this:
HRESULT MyIDropTarget::DragOver(DWORD grfKeyState, POINTL pt, DWORD * pdwEffect)
{
if (allow_drop_in_this_window)
*pdwEffect = DropEffect(grfKeyState, pt, *pdwEffect);
else
*pdwEffect = DROPEFFECT_NONE;
return S_OK;
}

There is CefDragHandler class in cef/include. I'm not sure if you can achieve what you need (IDropTarget is the way to go on Windows, true) - the DnD support has been modified in both CEF and Chromium.
Chrome issue seems still open.

Related

Detect Win+Tab Task View

On Windows 10, you can press Win+Tab to get a "Task View" view of all your windows. I'm trying to check if this is active at any given time. I have tried using a Low Level Keyboard Hook with WH_KEYBOARD_LL but this only allows me to detect the keypress, not if the switcher is active. I've looked at the Windows DWM API and haven't found anything else either.
I have also tried using EnumWindows() and EnumChildWindows(GetDesktopWindow(), ...) and did not find any difference in the output between having the task view shown and hidden.
Is there any accurate method to detect if this is being shown?
Here's a solution that works very consistently with my version of Windows (1709 build 16299.125) and doesn't require the processor-heavy approach of a call to EnumChildWindows:
bool isTaskView() {
//Get foreground window's name
HWND fgWindow = GetForegroundWindow();
TCHAR windowName[MAX_PATH] = L"";
GetWindowText(fgWindow, windowName, MAX_PATH);
//Compare with magic string name of Task View's window
std::wstring nameStr(windowName);
return nameStr == L"Task View";
}

WPF native windows 10 toasts

Using .NET WPF and Windows 10, is there a way to push a local toast notification onto the action center using c#? I've only seen people making custom dialogs for that but there must be a way to do it through the os.
You can use a NotifyIcon from System.Windows.Forms namespace like this:
class Test
{
private readonly NotifyIcon _notifyIcon;
public Test()
{
_notifyIcon = new NotifyIcon();
// Extracts your app's icon and uses it as notify icon
_notifyIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
// Hides the icon when the notification is closed
_notifyIcon.BalloonTipClosed += (s, e) => _notifyIcon.Visible = false;
}
public void ShowNotification()
{
_notifyIcon.Visible = true;
// Shows a notification with specified message and title
_notifyIcon.ShowBalloonTip(3000, "Title", "Message", ToolTipIcon.Info);
}
}
This should work since .NET Framework 1.1. Refer to this MSDN page for parameters of ShowBalloonTip.
As I found out, the first parameter of ShowBalloonTip (in my example that would be 3000 milliseconds) is generously ignored. Comments are appreciated ;)
I know this is an old post but I thought this might help someone that stumbles on this as I did when attempting to get Toast Notifications to work on Win 10.
This seems to be good outline to follow -
Send a local toast notification from desktop C# apps
I used that link along with this great blog post- Pop a Toast Notification in WPF using Win 10 APIs
to get my WPF app working on Win10. This is a much better solution vs the "old school" notify icon because you can add buttons to complete specific actions within your toasts even after the notification has entered the action center.
Note- the first link mentions "If you are using WiX" but it's really a requirement. You must create and install your Wix setup project before you Toasts will work. As the appUserModelId for your app needs to be registered first. The second link does not mention this unless you read my comments within it.
TIP- Once your app is installed you can verify the AppUserModelId by running this command on the run line shell:appsfolder . Make sure you are in the details view, next click View , Choose Details and ensure AppUserModeId is checked. Compare your AppUserModelId against other installed apps.
Here's a snipit of code that I used. One thing two note here, I did not install the "Notifications library" mentioned in step 7 of the first link because I prefer to use the raw XML.
private const String APP_ID = "YourCompanyName.YourAppName";
public static void CreateToast()
{
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(
ToastTemplateType.ToastImageAndText02);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
stringElements[0].AppendChild(toastXml.CreateTextNode("This is my title!!!!!!!!!!"));
stringElements[1].AppendChild(toastXml.CreateTextNode("This is my message!!!!!!!!!!!!"));
// Specify the absolute path to an image
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + #"\Your Path To File\Your Image Name.png";
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
imageElements[0].Attributes.GetNamedItem("src").NodeValue = filePath;
// Change default audio if desired - ref - https://learn.microsoft.com/en-us/uwp/schemas/tiles/toastschema/element-audio
XmlElement audio = toastXml.CreateElement("audio");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Reminder");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.IM");
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Mail"); // sounds like default
//audio.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Call7");
audio.SetAttribute("src", "ms-winsoundevent:Notification.Looping.Call2");
//audio.SetAttribute("loop", "false");
// Add the audio element
toastXml.DocumentElement.AppendChild(audio);
XmlElement actions = toastXml.CreateElement("actions");
toastXml.DocumentElement.AppendChild(actions);
// Create a simple button to display on the toast
XmlElement action = toastXml.CreateElement("action");
actions.AppendChild(action);
action.SetAttribute("content", "Show details");
action.SetAttribute("arguments", "viewdetails");
// Create the toast
ToastNotification toast = new ToastNotification(toastXml);
// Show the toast. Be sure to specify the AppUserModelId
// on your application's shortcut!
ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
}
UPDATE
This seems to be working fine on windows 10
https://msdn.microsoft.com/library/windows/apps/windows.ui.notifications.toastnotificationmanager.aspx
you will need to add these nugets
Install-Package WindowsAPICodePack-Core
Install-Package WindowsAPICodePack-Shell
Add reference to:
C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd
And
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
And use the following code:
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
for (int i = 0; i < stringElements.Length; i++)
{
stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
}
// Specify the absolute path to an image
string imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png");
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier("Toast Sample").Show(toast);
The original code can be found here: https://www.michaelcrump.net/pop-toast-notification-in-wpf/
I managed to gain access to the working API for windows 8 and 10 by referencing
Windows.winmd:
C:\Program Files (x86)\Windows Kits\8.0\References\CommonConfiguration\Neutral
This exposes Windows.UI.Notifications.
You can have a look at this post for creating a COM server that is needed in order to have notifications persisted in the AC with Win32 apps https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/10/16/quickstart-handling-toast-activations-from-win32-apps-in-windows-10/.
A working sample can be found at https://github.com/WindowsNotifications/desktop-toasts

How to Test Print-preview of Chrome browser using Chrome webdriver?

I have tried using switching between windows using
String winHandleBefore = driver.getWindowHandle();
<code to print>
for (String winHandle : driver.getWindowHandles())
driver.switchTo().window(winHandle);
driver.findElement(By.className("cancel")).click();
driver.switchTo().window(winHandleBefore);
This hangs my test case execution after it opens the print preview page.
Also tried with javascript executor method, but no use.
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("window.close()", "");
Please suggest if it's possible to do so.
I have found the answer to my question. I used below code snippet.
//Create a Region for Desktop Screen
ScreenRegion s = new DesktopScreenRegion();
//Find target with below Image in Desktop Screen
Target target = new ImageTarget(new File("Image.png"));
ScreenRegion r = s.find(target);
// Create a mouse object
Mouse mouse = new DesktopMouse();
// Use the mouse object to click on the center of the target region
mouse.click(r.getCenter());
With the help of this snippet you would able to find the print or cancel and do the mouse click event and proceed with selenium tests. This was possible using sikuli API

When iOS simulator starts, is it possible to automatically load the Web Inspector?

I'm using iOS 6 simulator with the shiny new Web Inspector in Safari.
Question: Is it possible to automatically load the Web Inspector when the iOS 6 web application loads?
I'm using PhoneGap/Cordova and have a lot of javascript loading on startup. I use console.log() extensively for debugging and would like it to load Web Inspector once the application starts.
Currently when I hit Run on Xcode, the app loads and I setTimeout on my first function so I can rush over to Safari and attach the Web Inspector on that page.
I'd much prefer to remove this step and add an automated step that would load the Web Inspector directly.
Any other solutions?
This is a partial solution. This opens the debug window of Safari with one click which is a lot better but not automatic.
Open Script Editor on your mac (Command + Space Bar and type in Script Editor)
Paste in this code:
-- `menu_click`, by Jacob Rus, September 2006
--
-- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}`
-- Execute the specified menu item. In this case, assuming the Finder
-- is the active application, arranging the frontmost folder by date.
on menu_click(mList)
local appName, topMenu, r
-- Validate our input
if mList's length < 3 then error "Menu list is not long enough"
-- Set these variables for clarity and brevity later on
set {appName, topMenu} to (items 1 through 2 of mList)
set r to (items 3 through (mList's length) of mList)
-- This overly-long line calls the menu_recurse function with
-- two arguments: r, and a reference to the top-level menu
tell application "System Events" to my menu_click_recurse(r, ((process appName)'s ¬
(menu bar 1)'s (menu bar item topMenu)'s (menu topMenu)))
end menu_click
on menu_click_recurse(mList, parentObject)
local f, r
-- `f` = first item, `r` = rest of items
set f to item 1 of mList
if mList's length > 1 then set r to (items 2 through (mList's length) of mList)
-- either actually click the menu item, or recurse again
tell application "System Events"
if mList's length is 1 then
click parentObject's menu item f
else
my menu_click_recurse(r, (parentObject's (menu item f)'s (menu f)))
end if
end tell
end menu_click_recurse
menu_click({"Safari", "Develop", "IOS Simulator", "index.html"})
Once the simulator has opened, click run on your script (you might need to allow the script editor in the settings the first time).
(Optional) You can save your the scripts as an app so that you don't have to have the script editor open.
(this answer is a more detailed version of Galatin's previous answer)
It's mid-2014 and there's still no elegant solution to this that I know of, but I like the idea of adding a short pause with setTimeout to your app's init code. If adding a setTimeout call isn't possible, you can also issue window.location.reload() from the Safari console to restart your application with the benefit of full debugging.
1) Inside your OnDeviceReady handler add debugger;
onDeviceReady: function() {
debugger;
// the rest of your device ready code
}
2) Run the application via xcode or cmdline.
3) Attach the debugger via Safari->Develop->Simulator->Appname -> index file
4) Open the console view of safari and enter:
Window.location = "";
5) The app will reload and the debugger will attach on the first line of onDeviceReady().
6) Debug as normal.

Mono winforms app fullscreen in Ubuntu?

Just wondering if there's a known way of getting a Mono System.Windows.Forms application to go fullscreen on Ubuntu/Gnome.
Mono is 2.4.2.3
Ubuntu is 9.10
Doing it on Windows requires a pinvoke, clearly not going to work here.
This is what I get setting window border to none, window position to centre, and state to maximised:
alt text http://dl.dropbox.com/u/116092/misc/permalink/joggler/screenshot01.png
Update.
Have also tried:
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
CTRL-F11
Text = string.Empty; // No caption
MaximizeBox = false;
MinimizeBox = false;
ControlBox = false;
FormBorderStyle = None;
WindowState = Maximized;
FormBorderStyle = FormBorderStyle.None;
Location = new Point(0, 0);
Size = Screen.PrimaryScreen.Bounds.Size;
All of which I end up with the same result.
I have come across a lead which involves a pinvoke involving _NET_WM_STATE_FULLSCREEN but that's as far as I've got with it. Any pointers on that would be appreciated.
_NET_WM_STATE_FULLSCREEN will just get rid of the borders. The GNOME panel will still appear.
According to the following post, the secret is to get rid of the minimum/maximum sizes so that the window manager does the resizing itself:
http://linux.derkeiler.com/Mailing-Lists/GNOME/2010-01/msg00035.html
Here is some documentation on the native spec:
http://standards.freedesktop.org/wm-spec/wm-spec-latest.html
http://www.x.org/docs/ICCCM/icccm.pdf
To talk directly to the X Window System you have to pinvoke into XLib. In order to send something like _NET_WM_STATE_FULLSCREEN you have to have a pointer to the window and also to the display.
I am not sure how to find the display but I can help with a pointer to the window. When running on X, the property Form.Handle should be a pointer to the X window.
Not sure what you mean by "Full Screen" - but I've written several Windows.Forms applications that take over the screen, and without a single PInvoke.
Here's how I configure my main form ...
Text = string.Empty; // No caption
MaximizeBox = false;
MinimizeBox = false;
ControlBox = false;
FormBorderStyle = None;
WindowState = Maximized;
Optionally,
TopMost = true;
Hope this helps.
You need to disable visual effects in ubuntu.
edit:
And make sure your form size is at least screen resolution without borders. If borders are on design time and you are removing them in code you will need something like 1030x796 for a 1024x768 display.
I have been suffered by this problem 2 days and finally i got the solution:
click the 1st icon on left tool bar and search compizconfig program. Go to preference-> unity and you will see there is a tick for unity plugin on the left side. Remove that tick and you will see the top menu bar disappeared.
Though this thread is very old but I still hope I can help anyone who gets this problem and seek for help.
Have you tried this?
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
Unfortunately I have no Ubuntu available right now, but I can see old patches for this in old mono versions...
It should be possible to display every app running inside gnome in fullscreen mode with the "CTRL+F11" hotkey.
Maybe you could try
System.Windows.Forms.SendKeys.Send();
but that is just a guess, I haven't got a Linux running atm to try this. But maybe this helps.
I can't test it at the moment, but have you tried a simple resize?
form.FormBorderStyle = FormBorderStyle.None
form.Location = Point(0, 0)
form.Size = Screen.PrimaryScreen.Bounds.Size
I have worked around this for now by setting the autohide property of the panel.
Not ideal because it depends on the user changing their environment to use my application, but better than nothing.
YMMV. http://fixunix.com/xwindows/91585-how-make-xlib-based-window-full-screen.html
The following worked:
(Inspiration was taken from here: https://bugzilla.xamarin.com/show_bug.cgi?id=40997)
1) sudo apt-get install wmctrl
2) In your code:
Form form = new MainWindow();
form.FormBorderStyle = FormBorderStyle.None;
form.WindowState = FormWindowState.Maximized;
form.Load += (s, e) => {
Process process = new Process {
StartInfo = new ProcessStartInfo {
FileName = "wmctrl",
Arguments = $"-r :ACTIVE: -b add,fullscreen",
CreateNoWindow = true
}
};
process.Start();
process.WaitForExit();
};
Application.Run(form);

Resources