virtual keyboard ctrl button - keyboard

I want to ask why stack my CTRL button in the virtual keyboard. I am using C# code:
keybd_event(ctrl, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(A, 0, KEYEVENTF_EXTENDEDKEY, 0);
Task.Delay(TimeSpan.FromMilliseconds(100)).Wait();
keybd_event(ctrl, 0, KEYEVENTF_KEYUP, 0);
keybd_event(A, 0, KEYEVENTF_KEYUP, 0);
variables
public const int KEYEVENTF_EXTENDEDKEY = 0x0001; //Key down flag
public const int KEYEVENTF_KEYUP = 0x0002; //Key up flag
public const int A = 0x41; //A key code
public const int ctrl = 0xA2; //ctrl key code
When I execute code all time Ctrl button was press. I press right ctrl button in my keyboard and problem disappearing.
maybe somebody know how solve problem. When execute code CTRL button will not press.

try using 0x0003 as keyup flag for ctrl/shift/alt

Related

Unable to change the tab bitmaps in a CMFCPropertySheet with OutLook_Bar style

I have an application with property sheet in outlook_bar style which I am using as a main dialog. I have created the property sheet with 3 pages on it. I have created 6 bitmaps each dimension(82,82) for displaying on the tabs.At a time 3 of the bitmaps will be used by the property sheet.
Whenever a user navigates to a new tab I would like to change the bitmap displayed on the selected tab. I have written a function ChangeImgList(int selno) below to do this.
The function is called from the OnSetActive function of the respective property pages.When I run the code I get an "Encountered an improper argument error" at the line SetIconsList(m_shtSelImages.m_hImageList).
I get this error when the second time this function is called.
The function is as below:
void AppPropSheet::ChangeImgList(int sel)
{
//m_shtSelImages is of type CImageList and m_bmpimgs[3] is an array of CBitmap
//both are members of AppPropSheet class
static bool firsttime = true;
int retval;
if(!firsttime)
for(int i=0;i<3;i++)
m_bmpimgs[i].~CBitmap();
if (sel == 0)
m_bmpimgs[0].LoadBitmapA(IDB_BITMAP86);
else
m_bmpimgs[0].LoadBitmapA(IDB_BITMAP77);
if (sel == 1)
m_bmpimgs[1].LoadBitmapA(IDB_BITMAP87);
else
m_bmpimgs[1].LoadBitmapA(IDB_BITMAP81);
if (sel == 2)
m_bmpimgs[2].LoadBitmapA(IDB_BITMAP88);
else
m_bmpimgs[2].LoadBitmapA(IDB_BITMAP79);
if (!firsttime)
m_shtSelImages.DeleteImageList();
retval = m_shtSelImages.Create(81, 81, ILC_COLOR24|ILC_MASK , 1, 1);
retval = m_shtSelImages.Add(&m_bmpimgs[0], RGB(128, 128, 128));
retval = m_shtSelImages.Add(&m_bmpimgs[1], RGB(128, 128, 128));
retval = m_shtSelImages.Add(&m_bmpimgs[2], RGB(128, 128, 128));
//SetIconsList(m_shtSelImages.m_hImageList);
firsttime = false;
}
//end of function
In the debugger I found the following :
It asserts in the SetIconsList function at line ENSURE(m_Icons.GetSafeHandle()==NULL) in afxpropertysheet.cpp
Apparently the way I am trying to change the bitmap is not provided by the framework.Looking forward to your suggestions.
The following code in class derived from CMFCPropertySheet class works
If there is any other way that works please let me know.
m_wndPane1.RemoveAllButtons();
retval=m_wndPane1.AddButton(m_bmpimgs[0], "Button one text", 10050, 0);
retval=m_wndPane1.AddButton(m_bmpimgs[1], "Button two text", 10051, 1);
retval=m_wndPane1.AddButton(m_bmpimgs[2], "Button three text", 10052, 2);
m_wndPane1.InvalidateButton(0);
m_wndPane1.InvalidateButton(1);
m_wndPane1.InvalidateButton(2);

SetLimitText not working for multiline in MFC application

I have an edit text control which is represented as following in .rc:
EDITTEXT IDC_EDIT1, 26, 23, 60, 14, ES_RIGHT | ES_MULTILINE | ES_AUTOHSCROLL
I tried un-restrict the limit lext using: m_editCtrl.SetLimitText(0);
but it is not working. If I remove 'ES_RIGHT' from the rc file, it worked well.
Is there any way to to un-restrict the text limit for ES_RIGHT?
Thanks in advance.
if(m_pEdit != NULL)
{
CString strVal;
//Get text value from the dit control
m_pEdit->GetWindowText(strVal);
//Get parent control
CWnd* pParentHwnd = m_pEdit->GetParent();
CRect ctrlRect;
m_pEdit->GetWindowRect(&ctrlRect);
pParentHwnd->ScreenToClient(&ctrlRect);
DWORD dwStyle = m_pEdit->GetStyle();
DWORD dwExstyle = m_pEdit->GetExStyle();
CFont* pFont = m_pEdit->GetFont();
int nCtrlID = m_pEdit->GetDlgCtrlID();
DWORD dwSelection = m_pEdit->GetSel();
CWnd* pWndPreviousCtrl = m_pEdit->GetNextWindow(GW_HWNDPREV);
m_pEdit->DestroyWindow();
if (dwStyle & ES_MULTILINE)
{
dwStyle &= ~ES_MULTILINE;
}
//Create edit control
BOOL bIsCreated = m_pEdit->CreateEx(dwExstyle, _T("EDIT"), strVal, dwStyle, ctrlRect, pParentHwnd, nCtrlID);
if (bIsCreated)
{
//Set window position to maintain z-order for tab navigation
m_pEdit->SetWindowPos(pWndPreviousCtrl, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
//Restore font
m_pEdit->SetFont(pFont);
//Restore last selection
m_pEdit->SetSel(dwSelection);
if (bHasFocus)
{
m_pEdit->SetFocus();
}
}
}
It appears that ES_RIGHT style doesn't play nice with ES_AUTOHSCROLL.
Looks like you can make it work if you create your edit control without ES_RIGHT style and later modify it like that:
GetDlgItem(IDC_EDIT1)->ModifyStyle(0, ES_RIGHT);
The issue is reproducible for ES_MULTILINE. Remove multiline from rc, it will solve the problem.

Mouse moves to original location after crossing montiors

I can't test different Windows versions, but I suspect it's a Windows 8 issue (due to the corner and side hotspots).
I'm trying to move the cursor to specified coordinates using SendInput, SetCursorPos, mouse_event and MoveMouse from Autohotkey and AutoIt. It works when moving the cursor on the same monitor, but not when crossing monitors.
When crossing monitors, if my mouse cursor is at (100, 100) on secondary monitor (to the right), moving to (0, 0) (primary monitor) will move and stay there. GetCursorPos will tell me it's at (0, 0). But soon as I move, the cursor starts from (0, 0) on secondary monitor.
How do I move my cursor across my monitor without having it jump to the original monitor again?
SendInput example C++:
int MouseMove(int x, int y) {
int screenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
int screenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
INPUT input;
input.type = INPUT_MOUSE;
input.mi.dx = round((x * 65535) / (screenWidth - 1));
input.mi.dy = round((x * 65535) / (screenHeight - 1));
input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_VIRTUALDESK | MOUSEEVENTF_MOVE;
input.mi.mouseData = 0;
input.mi.time = 0;
input.mi.dwExtraInfo = 0;
return SendInput(1, &input, sizeof(INPUT));
}
AutoHotkey example:
CoordMode, Mouse, Screen
MouseMove, 0, 0, 0
AutoIt example:
MouseMove(0, 0, 0)
I have no way of testing your issue but maybe I can point you in the right direction.
The only thing I can think of is using MouseGetPos to store your current mouse position,SysGet to grab the 2nd Monitor, and use MouseMove to return you to original position after your SendInput.
Hope this helps.
This may be a bug in Autoit or Windows.
Try doing MouseMove in a different way and play with $Window.
Local $WM_MOUSEMOVE = 0x0200
DllCall("user32.dll", "int", "SendMessage", _
"hwnd", WinGetHandle( $Window ), _
"int", $WM_MOUSEMOVE, _
"int", 0, _
"long", _MakeLong($X, $Y))
Are your monitors set to Extend mode?

Suppose if I want to press Delete button 9 times in my CODED UI code, is there any shortcut or do I need to give keyboard control 9 times in code?

Suppose if I want to press Delete button 9 times in my CODEDUI code, is there any shortcut or I need to give keyboard control 9 times in code?
You can use a for loop to loop through clicking the control 9 times:
for(var i = 0;i < 9;i++)
{
Mouse.Click(UiControl.DeleteButton);
}
You can place this in a method in your .UiMap file, or in your testmethod.
Some unasked advice: If you want to click delete 9 times because you have 9 items you want to delete 9 items from a table or another element you could try to get the count of the children:
var deleteNum = UiControl.Table.GetChildren().Count;
for(var i = 0; i < deleteNum; i++ )
{
Mouse.Click(UiControl.DeleteButton);
}
This will help as you won't use the control more than it should, and will make sure your testmethods are more robust against changes in the application.
Here's a click example using WinAPI - since it's faster than control identification.
public static class AppManager
{
private const int MOUSEEVENTF_LEFTDOWN = 0x02;
private const int MOUSEEVENTF_LEFTUP = 0x04;
[DllImport("user32.dll",
CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
private static extern void mouse_event(long dwFlags,
long dx,
long dy,
long cButtons,
long dwExtraInfo);
public static void RapidClick(Point pt)
{
Cursor.Position = pt;
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, pt.X, pt.Y, 0, 0);
}
}
Then to use RapidClick, I do this:
var point = new Point(control.Left+1, control.Top + 1);
for (int pos = 0; pos < totalClicks; pos++)
{
AppManager.RapidClick(point);
}
The benefits of this is that the performance is mindblowingly fast. This is because you do a lookup to the control once to get the initial co-ordinates, after that you can rapid click it reliably.
This has worked for me locally, and also no issues with RDC or in labs environment too.

How to specify negative range for slider control?

I am developing a MFC based SDI VC++ application. In my application I need to specify negative range value for my Slider Control. The minimum range for the Slider is -40 and maximum range is 255. I tried it using SetRange function. But it is not working. How can I set this range in the slider?Please Help..
My code for the Slider is as follows:
Slider is declared as
CSliderCtrl m_ctrlECTSlider;
OnInitialUpdate function contains
m_ctrlECTSlider.SetRangeMin(-40);
int iValMin = m_ctrlECTSlider.GetRangeMin();
m_ctrlECTSlider.SetRangeMax(255);
int iValMax = m_ctrlECTSlider.GetRangeMax();
m_ctrlECTSlider.SetPos(0);
SetDlgItemInt( IDC_ECT_VALUE, m_ctrlECTSlider.GetPos(), FALSE);
SetDlgItemInt( IDC_MIN_ECT, iValMin, FALSE);
SetDlgItemInt( IDC_MAX_ECT, iValMax, FALSE);
OnBnClickedSet function contains
int nMin = GetDlgItemInt(IDC_MIN_ECT, 0, FALSE);
int nMax = GetDlgItemInt(IDC_MAX_ECT, 0, FALSE);
m_ctrlECTSlider.SetRange(nMin, nMax);
m_ctrlECTSlider.SetPos(nMin);
int pos = m_ctrlECTSlider.GetPos();
SetDlgItemInt(IDC_ECT_VALUE, m_ctrlECTSlider.GetPos(), FALSE);
m_ctrlECTSlider.RedrawWindow();
Here the problem is the value returned during debugg is all correct. But when it comes to UI on running the min value is 429496 and not -40 in the edit box..Why is it so..I am developing SDI application using CFormView class..
Thanks in advance.
Your minimum value is '-40'which is signed integer and You are treating as unsigned integer as last parameter of 'SetDlgItemInt' and 'GetDlgItemInt' method is 'FALSE'.
That's why you are getting wrong value in place of '-40'.
Use following code for correct behavior.
//For setting value
SetDlgItemInt( IDC_ECT_VALUE, m_ctrlECTSlider.GetPos(), TRUE);
SetDlgItemInt( IDC_MIN_ECT, iValMin, TRUE);
SetDlgItemInt( IDC_MAX_ECT, iValMax, TRUE);
// For getting value use as follows
int nMin = GetDlgItemInt(IDC_MIN_ECT, 0, TRUE);
int nMax = GetDlgItemInt(IDC_MAX_ECT, 0, TRUE);
You can use this link http://msdn.microsoft.com/en-us/library/c7t43w0s%28v=vs.90%29.aspx
for more details.
Call void SetRangeMin(int nMin, BOOL bRedraw = FALSE); as :
m_Slider.SetRangeMin(0);
And call void SetRangeMax(int nMax, BOOL bRedraw = FALSE); as :
m_Slider.SetRangeMax(50);
Also before calling GetPos() verify that the slider is in the range by calling the VerifyPos()
This is good tutorial on MFC Sliders - Windows Controls: Sliders (Track Bars).

Resources