How do I check if a button exists on a window with AutoHotkey? - screen-scraping

In my case, there are times that a certain button will exist and not exist.
Is there a way to check whether a certain button exists on a window using AutoHotkey?

If you use ControlGet with a command and the control does not exist then ErrorLevel will be set to 1.
You could use ControlGet to get the window handle (HWND) of a control. If the control exists the window handle will be put in your output var and ErrorLevel will be set to 0, otherwise the output var will be blank and ErrorLevel will be 1.
In the example below the first two lines get the window handle for the 'Ok' button on Notepad's About screen (the about screen must of course be shown for it to work) and show the results in a MsgBox. The ClassNN of the Ok button is Button1.
The second two lines to the same but for a control with a ClassNN of Button2 that doesn't exist.
ControlGet, Handle, Hwnd,, Button1, About Notepad ahk_class #32770
MsgBox Handle: %Handle%`n`nError: %ErrorLevel%
ControlGet, Handle, Hwnd,, Button2, About Notepad ahk_class #32770
MsgBox Handle: %Handle%`n`nError: %ErrorLevel%

Here is the code example from notepadplusplus_toogle_find_window.ahk using ControlGet:
; Button1 is the class name for the title bar and close button of the results pane when docked
ControlGet, OutputVar, Visible,, Button1, Notepad++
if ErrorLevel = 0
{
If OutputVar > 0
{
; Found it docked
Open := 1
; Get the size and coordinates of the title bar and button
ControlGetPos, X, Y, Width, Height, Button1
; Set the coordinates of the close button
X := Width - 9
Y := 5
; Send a click
ControlClick, Button1,,,,, NA x%X% y%Y%
}
}

Related

X Motif client not applying scrollbars to a RowCol widget as expected

I have a C client for X Motif that is not showing the scrollbars for a Row Col widget as expected. The main window (toplevel) has a form added to it. In the form I add a label gadget as a top attachment to the left side. Then, I add a Quit button as a top attachment to the right side.
Then I add a ScrolledWindow widget and attach it to the form as a bottom attachment to the left side. I specify the height, width and scrollbar policy value as:
sw = XtVaCreateManagedWidget("scrolled_w", xmScrolledWidgetWidgetClass, form,
XmNwidth, 575,
XmNheight, 120,
XmNscrollingPolicy, XmAUTOMATIC,
XmNscrollBarDisplayPolicy, XmAS_NEEDED, NULL);
Inside the sw widget I create a row col widget and add a bunch of buttons
to it. They are displaying fine and going in using the orientation desired.
rowcol = XmCreateRowColumn(sw, "rowcolumn", NULL, 0);
XtVaGetValues(rowcol, XmNforeground, &fg, XmNbackground, &bg,
XmNborderColor, &bord, NULL);
XtVaSetValues(rowcol, XmNpacking, XmPACK_COLUMN,
XmNnumColumns, COLS,
XmNorientation, XmHORIZONTAL,
NULL);
The issue is when I resize the main X window, I "expect" that scrollbars
should be applied to the row col window when the size of the main window is
not letting the entire scrolled window display. But it doesn't. The only
way I can get the scroll bars to show is if I rejig the XmNwidth and XmNheight
values for the creation of the window.
Any idea why this is happening?
thx.
W.

WinForms DockStyle with GroupBox and Button

I have a splitter with a group box in it:
top panel
----splitter------------------------
group box------
xxxxxxxxx
xxxxxxxxx
xxxxxxxxx
[button]
The group box is set to DockStyle.Fill. If the Button is set to DockStyle.Bottom, the button clings to the bottom of the panel, as I'd like it to do, but the bottom of the group box is obscured behind the button, as if the group box did not know that the button was occupying the space. The group box thinks all of its contents are visible and the scrollbar disappears.
How do I get the group box to use all space that is available but to extend no lower than the top edge of the button?
You have to make sure that the group box is set to the top: right now it thinks it's "lower" than the button, so it tries to fill the whole panel. If you set the button to be docked first, call GroupBox.BringToFront() second, and then set the GroupBox.DockStyle.Fill, it should work with the available space.

How to create and show a infotip when clickng a label?

I'm using VSTUDIO2012, my problem seems simple but it's too hard for me,
EDIT: It's a "windows forms application"
I have a label and when i click at the label i want to show a little info in a "infotip" or "tooltip" or "ballontip", i want to show a message like for 5-10 seconds...
Someone can guide me about how to make this? or references on the web please?
EDIT2: I've tried this:
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
'MessageBox.Show("Use the 'Ctrl+C' hotkey to copy the" & vbNewLine & "mouse coordinates into the clipboard.", "Mouse XY by Elektro H#cker")
End Sub
Private Sub ToolTip1_Popup(sender As Object, e As PopupEventArgs) Handles ToolTip1.Popup
ToolTip1.Show("Tooltip text goes here", Label1)
End Sub
When you start your application, you should your form you're working on in the center of the screen.
On the left side of the screen you should see a panel labeled 'Toolbox' (it may be on different sides of the screen depending on how you arrange your panels. I think default is left though. If you don't see it you can show it by selecting 'Toolbox' from the view menu or by pressing "Ctrl + Alt + X".).
With the 'Toolbox' panel open, you should see several collapsible panels. Open either 'All Windows Forms' or 'Common Controls'. Near the bottom of each collapsible area is an element you can add labeled 'ToolTip'. Once its been added successfully, a light gray control panel appears with your new ToolTip control labeled 'ToolTip1'.
Once the control is added you simply right click on an element that you want to add a tooltip to such as a label. When the popup context menu appears choose 'Properties' (the very last option). This opens the Properties Panel.
When the Properties Panel opens, scroll to the bottom of the list. Right below the TextAlign Property should be a property called ToolTip on ToolTip1. Enter your tooltip text here. Now when a user hovers over your label, the text entered will appear in a standard yellowish popup tooltip.

Appear & Disappear Images using TimerControl , C#.net

I have 3 Images (Image1, Image2, Image3),
Using a timer control with interval value of 5000, i.e 5second, I
want to accomplish the following:
Initially, only Image1 is visible to the user middle of the form, i.e the 2 images
are set to be invisible.
When load the form appear and image1
appears exact middle of the form
After 5 seconds, the image1 disappear and image 2 appears right side.
After 5 seconds, the image2 disappear and image3 appears left side
After 5 seconds, the image3 disappear and the image1 appear
I am setting timer control's Enable property to "True" in Design
time.
I am setting timer control's Interval property value to 5000 in
Design Time.
I assume that I do all the coding but not working only displaying two images
Can anyone help me code what I want to accomplish?
Very "dirty" solution: keep a status variable from 0 to 2 (included) and increment for each tick then show/hide each image with that.
On the timer tick event handler:
if (++_status > 2)
_status = 0;
pctImage1.Visible = _status == 0;
pctImage2.Visible = _status == 1;
pctImage3.Visible = _stauts == 2;

Using the TaskBarItemInfo in WPF for the progress bar in Win 7 taskbar

Does anybody have a WPF example of updating the ProgressState through the available enum states when progressing through ProgressValue?
I have the following code which binds my progress value to run from 0 to 1:
<Window.TaskbarItemInfo>
<TaskbarItemInfo Description="An app with a taskbar info description"
ProgressValue="{Binding Count}" ProgressState="Normal"/>
</Window.TaskbarItemInfo>
But, what is a good way to go from None to Normal to None or other flows: None-Normal-Paused-Normal-None.
The code above shows the progress bar on the left at 0% and then finishes at 100% (1).
I imagine I could bind this with a converter to another property hanging of my ViewModel, but wanted to see if anyone had any slicker solutions.
Thanks!
In the same way that you are binding the ProgressValue, you can also bind the ProgressState. The type of the ProgressState is an enum called TaskbarItemProgressState, which includes the states you already mentioned.
public enum TaskbarItemProgressState
{
// Summary:
// No progress indicator is displayed in the taskbar button.
None = 0,
//
// Summary:
// A pulsing green indicator is displayed in the taskbar button.
Indeterminate = 1,
//
// Summary:
// A green progress indicator is displayed in the taskbar button.
Normal = 2,
//
// Summary:
// A red progress indicator is displayed in the taskbar button.
Error = 3,
//
// Summary:
// A yellow progress indicator is displayed in the taskbar button.
Paused = 4,
}
I think the 'slickest' ways to do this are the ways you already mentioned, either with a converter or manually
ProgressValue is double
use value from 0 to 1

Resources