wpf - transparent MainWindow and issues with DragMove "Can only call DragMove when primary mouse button is down." - transparency

I have a wpf project which uses transparent windows and I share this transparent window styling for my dialog windows and my mainwindow.
I am getting an error on my DragMove() event of my MainWindow AFTER I close a dialog window that uses the same window style. To make this even more strange this exception only occurs when I handle a mouseleftbutton event on a label in my Status Bar on the MainWindow. IF I swap out the label for a button and replace the mouseleftbuttondown with a click event I do not get the error.
The strange thing is that the dialog window that pops up does not implement dragmove, and I'm not dragging around my mainwindow either. Somehow dragmove gets called after my code execution returns to the mainwindow after a showdialog() call.
An easy fix for me currently is to swap my label for a button and wire up the click event instead.
However, I'm more interested in hearing about what causes this issue and why a click event works but the mouse one fails miserably.
My "StatusBar" is simply a stackpanel with labels and other stackpanels (which contain more labels).
Has anyone else fought this issue before? Would I need to implement some sort of mouseclick event handler override so that I can capture and cancel this exception from happening?
Repro code can be provided if needed. I got enough hits on dragmove here so I am hoping this is an easy one for somebody out there.
Thanks in advance for any help!

my brain isn't working properly today. I forgot about routing of events in this scenario. I simply needed to set the Handled property on my routedevent that fired off when the mousebutton was down. Somehow I missed that in the debugger before posting the thread.

The 'correct' way to make a borderless window movable --> https://stackoverflow.com/a/3275712/146032
Be sure to only call DragMove when triggered by event MouseLeftButtonDown and don't forget to handle the event using e.Handled=true;

if you receive this exception when messagebox show complete. place Dragemove();
inside try and empty in catch.

Related

Is there a way with Xamarin.Forms to detect the software keyboard in my iOS app?

I have a Xamarin.Forms application with a login screen. I have added code to move the controls out of the way, when one of the Entry fields gets focus. I move the views back down in the Unfocus event handlers. In the simulator I can prevent the software keyboard from popping up. Unfortunately my event handlers still move the view up and down even without the keyboard.
Is there a way to detect the keyboard's appearance in Xamarin.Forms, while in the event handlers on the ContentPage?
I don't think there is support for this out of the box and thus I'd go with DependencyService and implement it by myself.
You could use ContentPage.LayoutChanged event.
It works because the keyboard doesn't display over the content page as one would guess, but under it, in the same layer, so it push the page up.

Ranorex v5.0 doesn’t click button sporadical

I have a ranorex project, which automated an use case with clicking 5 buttons in an application.
To set up this project I used the record function. I defined some sleep times between the clicks.
The run with the clicks is in a loop, where the loop count is dynamically defined. One button of the five and always the same button, Ranorex "ignores" sometimes. According to the log file, the button is visible and enabled and ranorex also runs the code with the Click(), but the application doesn’t receive the click. Before in code the click is called, I check with an “If” whether the button is visible and enabled - and if the click() is called (or doesn't), I log it to ranorexlog. Sometimes the application is running through and all the clicks work and sometimes this button click is missing one or more times. It doesn’t depend on the sleep time between the clicks, because I tried long and small pause times. It doesn’t depend on the focus of the application, too, because I switched the focus several times.
Does anybody know this problem, workarounds or what I’m doing wrong?
the obvious workaround is to use Mouse.Click("{Button}") with a 0 duration rather than invoking the click event, or if you are invoking the mouse click invoke the buttons click action. (sorry since they are both named Click() i don't know which one you are using).
As to what is happening, from your description it sounds like your script is finding more than one element with the same xpath. This would cause issues with the click event because it may try to click on the element, but it's the first xpath that matches not the second. Are there any optional elements in this sequence of button clicks that appear? for instance a busy spinner with inner text of "OK" that is hidden from view when you are clicking a button on a form with inner text of "OK" would cause two elements to be found if the xpath was looking for an inner text of ok. This element that is causing may not have been caught in the recorder because it might not have been present at the time.
Another possibility if you are using Mouse.Click() (particularly if this is a website)is that it is possible your button is not actually on the screen, I know that should be taken care of by the visible check but it is visible on the dom even though it is not visible on the screen that causes issues.
I highly recommend do not use the recorder to create test suites that need to be re-runnable. It would actually be better to use the spy tool to create a repository or several repositories for the product you are testing, this way you can be sure the xpaths are all unique, which using the recorder there is no gaurantee. You can actually record with the created repository, and ranorex will attempt to find item in the repository before creating a new item, so the recorder will use this repository when creating recordings.

How to get the handle of a Vista style Open/SaveDialog?

I'd like to get the window handle of a new vista-style Open/SaveDialog opened by my Delphi application.
It was possible with the old style dialog by parsing OnShow, but with the new style dialog there is no such event.
Is there a possibility maybe to iterate through all window handles in Windows and get it that way?
Thanks!
Edit: I know that OpenDialog.Handle will return the handle, but only when the dialog is visible (otherwise it's 0). I'd need an event to catch the Handle straight after showing the dialog (without any user action, ie.: select an item in the dialog, changing the file type, etc.).
I'd like to get the window handle of a new vista-style Open/SaveDialog opened by my Delphi application.
This is available through the dialog's Handle property.
Probably the easiest way to catch the event of the dialog showing is to use a CBT hook that you set immediately before showing the dialog, and remove as soon as it closes.
TOpenDialog has an OnShow event which fires just after dialog is shown so you can use to get the OpenDialog.Handle since the handle is already set at that time.
EDIT: After some pepole pointed out that using of OnShow event changes the dialogs apperance I tested this out and can confirm that using of OnShow event realy does change the dialogs aperance.

How to capture mouse clicks outside of form (like with Code Insight in Delphi)

I like the idea of the Delphi Code Insight window (custom listbox on form without borders basically) where you can click outside of the form and it will close it automatically.
My first thought was to call SetCapture/ReleaseCapture in the FormCreate and FormDestroy respectively. I set the form's caption to X/Y on the FormMouseMove, but it doesn't update the coordinates outside of the form.
If I call SetCapture/ReleaseCapture from within MouseDown and MouseUp, it does update the coordinates as expected, so that proves the concept does work.
I tried other things as well, e.g. post a WM_USER in the OnShow event, and call SetCapture from there, but it still doesn't update the coordinates. I then tried the TApplicationEvents component (OnMessage), but that doesn't work either.
I've read several articles already, but wasn't able to find what I was looking for. Some articles called SetCapture from within the MouseMove, but that doesn't work when the mouse cursor starts outside of the form. Hrm...
The next step would be to use a WindowsHook, but that's where I stopped. I know how to implement one, but it just seems like I'm missing something really obvious here. There must be a simpler way to do this.
Any ideas? :)
Cheers,
Jarno
What you want can be done easier by adding TApplicationEvents to your form and use the event OnDeactivate. That one gets triggered whenever the application loses focus.
Maybe WM_NCHITTEST can help you somehow. As they say, if the mouse is captured, this message is sent to the window that has captured the mouse. So I would capture the mouse for the form and then wait until result of this message is HTNOWHERE, which should mean "out of the window".
But as far as I can remember, this never worked for me fine, so I finally used (as you mentioned) mouse hook.But in my case I've had a lot of components on that popup form and you need to consider messaging for them too.
The implementation I've used (with a little changes) and which works is here.
I had a similar problem (I needed to implement a scrolling windows if the mouse pointer hovered over a special area and I was not able to use SetCapture)
and circumvented it using a timer + GetCursorPos method.
Just do then a ScreenToClient and check if the mouse is within the window.

Delphi "Tray" icon (NotifyIcon) context-menu does not disappear when clicking outside it

I'm trying to show a popup menu when right clicking my Notification Icon, which works fine; But I want the menu to disappear when the user clicks outside of that menu.
It's supposedly by design as per KB135788 - PRB: Menus for Notification Icons Do Not Work Correctly (archive).
But no decent app I know of behaves like this. I've tried calling SetForegroundWindow using the popup menu's handle to no avail. I'm sure it's possible to work around this, as I've done it years ago but don't remember how.
Anyone know how to achieve the expected behaviour?
I've found a solution!
I was calling
SetForegroundWindow(PopupMenu1.Handle);
Which doesn't work, but changing this in the OnPopup event handler to
procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
// Hack to fix the "by design" behaviour of popups from notification area icons.
// See: http://support.microsoft.com/kb/135788
BringToFront();
end;
Works!
Obviously, if the form is visible when this is called, your app will jump foremost, but if it's hidden (as mine is), then it'll work.
I'd be interested to know if there's a way to make the menu work right without the window jumping foremost, though.

Resources