So, let me first explain what am I dealing with. I have a usb card reader and c++ application, which intercepts the scan of a card and opens the WPF application.
Maybe it will sound stupid, but belive me I have tested 100 times. When I debug my c++ application in visual studio, when on scan read, it starts my wpf application, and waits 2 seconds, meanwhile when I start without debugging WPF application in function OnLoad calls
1 2 3 4
|
this.Activate();
this.Topmost=ture;
TextBox1.Focus();
Keyboard.Focus(Textbox1);
|
and the window is open, it is in the front, it's active, and then when 2 seconds passes the scanned string is in my TextBox. It works when my WPF application is openned, closed, it intercepts even if I have a cursor in address bar of a browser.
But, I don't know where is the point, when I manually open my interceptor c++ exe application, it starts my wpf application, but the window stays in background, so nothing gets in my TextBox field.(YES I HAVE CHECKED IF I AM CALLING THE RIGHT EXE FILE)
Bellow is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
while (interception_receive(context, device = interception_wait(context), &stroke, 1) > 0)
{
if (interception_is_keyboard(device))
{
InterceptionKeyStroke &keystroke = *(InterceptionKeyStroke *)&stroke;
if (device == usbNum)
{
HWND chromeWindow = FindWindow(NULL, nameOfTheWindow);
if (NULL == FindWindow(NULL, nameOfTheWindow) ) {
ShellExecuteA(NULL, "open", path, NULL, NULL, SW_SHOW);
wcout << "if " << i << endl;
wcout << "Card has been noticed, opening WPF" << endl;
Sleep(sleepTime);
}
else {
HWND chromeWindow = FindWindow(NULL, nameOfTheWindow);
if (GetForegroundWindow() != chromeWindow) {
wcout << "else if " << i << endl;
SetForegroundWindow(chromeWindow);
SetActiveWindow(chromeWindow);
SetFocus(chromeWindow);
ShowWindow(chromeWindow, SW_RESTORE);
SetWindowPos(chromeWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
SetActiveWindow(chromeWindow);
wcout << "WPF is openned, activating" << endl;
}
else {
wcout << "else else " << i << endl;
//ShowWindow(chromeWindow, SW_RESTORE);
SetWindowPos(chromeWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
wcout << "Window is opened making it active" << endl;
}
}
i++;
if (i > sleepTime) {
i = 1;
}
}
}
|
Is it possible that Visaual studio ha more rights? I don't know what can be causing this...
I also recorder my screen so that you can truelly understand my problem. On 20 sec I am manually starting my c++ program, and you will se, it stays hidden.
https://www.youtube.com/watch?v=weM4a8H6h6w&feature=youtu.be
When will this work, I am going to write an article of the whole procedure, how to intercept string from a usb reader. Beacuse I belive I am not the only one with this kind of a problem to intercept data from usb reader.
PLease can somebody suggest what to do?
Regards!