Hello,
I hope you may help me, and I hope my question is in the right forum.
I have a PNA with WinCe, there is one apllication running ind "fullscreen" mode.
What I planed to do is:
When there is a "mouseclick" in the topleft-corner (50*50 pixel wide) the app should perform a createprozess an end.
All other click should pass through to the main-app.
like an invisible Button on the forground of the desktop.
Is this possible?
I tried things like setcapture or SetWindowsHookEx but I m not the prof and I didnot find any examples für Wince...
Perhaps you may help me.
Michael
You are trying to create a hot-spot.
You would need to add a check in the window procedure for mouse clicks and check the pointer position, I think.
Just a thought, never had done that.
Hello Stefan,
yes something like that, but I have no idea where to start :-[ :'(
All I found at google or MSDN does not fit that what I try to do.
Michael
Pick up the mouse clicks, maybe use WM_LBUTTONDOWN then write the code to decide if the click was in the top left.
John
Hello,
it is not nessesarily to have a window to pick up mousevents?
I can do that but only i have a "window" in the top left corner.....
I do that with a loop and peekmessage, it works but only with a smal window.
And if its possible to do that without a window, that will be the best ...
Michael
maybe : http://msdn.microsoft.com/en-us/library/ms632599%28VS.85%29.aspx#message_only (http://msdn.microsoft.com/en-us/library/ms632599%28VS.85%29.aspx#message_only)
Take a look at GetCursorPos() API.
John
Quote from: nicolas.sitbon on July 19, 2009, 08:36:42 AM
maybe : http://msdn.microsoft.com/en-us/library/ms632599%28VS.85%29.aspx#message_only (http://msdn.microsoft.com/en-us/library/ms632599%28VS.85%29.aspx#message_only)
Thanks for that, looks very interessting but on an WinCe-Device the HWND_MESSAGE does not exists :-(, so I looked for an found this
#define HWND_MESSAGE ((HWND)(-3))
but also no success :'(
The GetCursorPos() work fine, if i have also an existing window, perhaps I do some misstakes ;D but I triy to learn with that.
The only Thing i would do is:
is there a click -> WM_LBUTTONDOWN
if 0 < p.x < 50 && 0 < p.y < 50 then do anything
looks very simple, but I also should click the other runnung app outside the coordinates p.x p.y
Michael
You do not have a window, so you need to use the handle of the desktop, which should be zero for Windows.
If you use a mouse message hook, you should be able to get that information, be sure to call NextHook, if you processed the message, so the window it was intended for gets it.
Hello Stefan,
perhaps, can you give me an entry point, where should I start?
I tried alot... googled and read but nowhere I can find a short example or code-snipplet who shows me the way.
Its easier to say I want to create a nonvisible button on topmost of the desktop / windows.
Michael
Hi,
as JohnF suggested GetCursorPos() is your way to go:
http://msdn.microsoft.com/en-us/library/ms648390(VS.85).aspx
in combination with OpenInputDesktop()
Greetings
Seltsamuel
#include <windows.h>
#include <stdio.h>
int main(void)
{
POINT p;
while(1){
Sleep(200);
GetCursorPos(&p);
printf("%d %d\n", p.x, p.y);
if(p.x > 0 && p.x <50 && p.y > 0 && p.y < 50){
GetAsyncKeyState(VK_LBUTTON);// for first time, clear buffer
if(GetAsyncKeyState(VK_LBUTTON) & 0x8000){
break;
}
}
}
return (0);
}
EDIT:
GetAsyncKeyState(VK_LBUTTON) && 0x8000
should be
GetAsyncKeyState(VK_LBUTTON) & 0x8000
Someone let me know that it was wrong.
John
Hello Stefan,
thank you very much.
I did not thought, that it could be "easy" like this, but I have one problem.
I think the getcursopos- api do not really work correctly.... mhhh
The first time I changed something, cause I need for WinCe unicode.....
Then I remarked the I got no action...
So I changed the code in this
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpszCmdLine, int nCmdShow)
{
POINT p;
wchar_t hStr1[100];
wchar_t hStr2[100];
int x;
int y;
while(1){
Sleep(200);
GetCursorPos(&p);
x = p.x;
y = p.y;
swprintf(hStr1, L"%d", x );
swprintf(hStr2, L"%d", y);
// if(p.x > 0 && p.x <480 && p.y > 0 && p.y < 272){
GetAsyncKeyState(VK_LBUTTON);// for first time, clear buffer
if(GetAsyncKeyState(VK_LBUTTON && 0x8000)){
MessageBox(NULL, hStr1, hStr2, MB_TOPMOST| MB_YESNO);
}
//}
}
return (0);
}
Now for testing I get for y -> 9 an for x -> -2145173072 evrytime, everywhere I click on the Display :'(
Michael
Quote from: ml1969 on July 21, 2009, 05:41:51 AM
Hello Stefan,
thank you very much.
I did not thought, that it could be "easy" like this, but I have one problem.
Sorry, but the example was posted by John, so there is nothing to thank me.
I am not the guy, who is stealing the glory of others.
To your problem, notice John has corrected his code, which might solve your problem too.
Try this. It uses GetMessagePos() instead of GetCursorPos() and also an invisible window. When there is a left button click in the top 50 pixels you should hear a Beep as the app exits.
EDIT: Added DestroyWindow(hwnd);
John
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>
#include <tchar.h>
static LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
static HANDLE ghInstance;
void GetCursorPosWinCE(POINT *pt)
{
DWORD pos = GetMessagePos();
pt->x = LOWORD(pos);
pt->y = HIWORD(pos);
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
ghInstance = hInstance;
/* Register the main window class */
wc.lpszClassName = _T("testerClass");
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = ghInstance;
wc.hIcon = LoadIcon(ghInstance, NULL);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if (!RegisterClass(&wc))
return 1;
/* Create the main window but don't show it */
hwnd = CreateWindow(_T("testerClass"), _T("tester Program"), WS_OVERLAPPEDWINDOW, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, ghInstance, NULL);
if (!hwnd)
return 1;
// DON'T SHOW THE WINDOW
// ShowWindow(hwnd, nCmdShow);
// UpdateWindow(hwnd);
POINT p;
SetTimer(hwnd, 1, 100, NULL);
while (GetMessage(&msg, NULL, 0, 0))
{
// GetCursorPos(&p);
GetCursorPosWinCE(&p);
if (p.x > 0 && p.x < 50 && p.y > 0 && p.y < 50)
{
GetAsyncKeyState(VK_LBUTTON); // for first time, clear buffer
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000)
{
break;
}
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
MessageBeep(16);
KillTimer(hwnd, 1);
DestroyWindow(hwnd);
return msg.wParam;
}
static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
Oh sorry John ::),
but I want to say thanks all of you, who helps me here....
Ok,
I tried this code, but the same as the getcursorpos....... then I have changed a litte bit, to see what happens:
while (GetMessage(&msg, NULL, 0, 0))
{
// GetCursorPos(&p);
GetCursorPosWinCE(&p);
GetAsyncKeyState(VK_LBUTTON); // for first time, clear buffer
if (GetAsyncKeyState(VK_LBUTTON) & 0x8000)
{
if (p.x > -1 && p.x < 480 && p.y > -1 && p.y < 272)
{
break;
}
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//MessageBeep(16);
swprintf(hStr1, L"%d %d", p.x , p.y );
MessageBox(NULL, hStr1, L"B2", MB_TOPMOST|MB_YESNO);
KillTimer(hwnd, 1);
DestroyWindow(hwnd);
return msg.wParam;
}
Now I see the MessageBox and it shows me for p.x = 0 und p.y = 0 (that´s wy I changed the if statement from 0 to -1)
Ok , now I took the break statement out, to get an endless loop,
the first time the messagebox comes up it shows me 0/0 for x and y, ....
I clicked OK and the next time it shows me the coordinates where i clicked the button NOT where I clicked on the screen.
I can reproduce it... it only shows me the point from the messagebox where I cleick YES or NO.
I hoped I would see the coordinates from that point I cleicked the screen....
Perhaps the code only works when a real notification was send???
Ok now I have a big unvisible button ;D,
Why will the GetCursorPos and GetCursorPosCe will not worl like you think? ???
Michael
The idea behind the code is that a Timer message comes every 0.1 of a second so when a message (Timer) is received the click will give you the position.
I have no idea why those two API's appear not to be working and I can't test it on your platform.
John
mhhh perhaps cause there no visible cursor? ???
in an other try, I used the WM_LBUTTONDOWN with a peekmessage loop,
I could get the coordinates with the
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
But only I created a "visible" window.....
Michael
Hello,
an other thought...
Could this work.... no real code
I register a hotkey using.... RegisterHotKey(hwnd, (UINT) 0x0001, 0, (UINT) VK_LBUTTON)
now I enter a message loop while (GetMessage(&msg, NULL, 0, 0) != 0)
switch (msg.wParam)
{
case 0x0001:
xPos = GET_X_LPARAM(msg.lParam);
yPos = GET_Y_LPARAM(msg.lParam);
if (xPos > 0 && xPos < 50 && yPos > 0 && yPos < 50) {
do what I want;
}
else {
generate org. click with mouse_event
I thought on that, cause I wrote a litte " hotkey" program to use the 4 hardware-buttons (VK_F6 ..VK_F9 of the PNA) with my own user- code
Can I use VK_LBUTTON as a "Hotkey" ?
Michael
Hi,,
also do not work :-(
is there no other possibility?
Michael
Ok
I think the manufactor has disabled this function like it is discribe on the msdn website :-(,
cause the code above works on an other pna from an othe manufactor..
Thanks alot, an is there an other way to retrive the mouse position I will be glad....
Michael
This is my last suggestion - make a transparent window always on top at the top left of the screen and pick up WM_LBUTTONDOWN.
John
Hello Johm
this was my thought at first, but I can create a window that receives the WM_LBUTTONDOWN, then the window ist visible or if I create a non-visible window I did not receive the command :-(
Ok I think I do a mistake here, but I`m a beginner and try alot :-)
WS_EX_TRANSPARENT is an undeclared identifier :-( on a wince system
for me it would be OK if the titlebar is visible (I set the position of the window outside the desktop)
and if the white region of the window could be transparent......
I used at least SetWindowPos(hwnd, HWND_TOPMOST, -25, -25, 65,65,SWP_NOOWNERZORDER| SWP_SHOWWINDOW);
so the window is almost on top, bu the white region is visible..... :-(
I saw something about SetWindowRgn .... but I dont understand the right way to use it :-(
Michael
// WS_EX_TRANSPARENT is an undeclared identifier :-( on a wince system
Sorry I can't help.
Search the web and see if anyone else has done this.
John
Hi JOHN
so I tried your code with the GetCursorPosCe() AND made the window visible.
Even when the window is visible, I mean it is OnTop your Code works fine and I got the correct coordinates of the cursor, ok it is interessting but helps me not really....
One thought....
I wait for the VK_LBUTTON with the with the AsyncKeyState.
Show for a real short time the window, get the cursorposition an hide the window....
I hope this will not take to much process-power.....
Michael
//I hope this will not take to much process-power.....
Use Sleep(20) in the loop.
John