Invisible Dialog/Button or retrieving mouseclick

Started by ml1969, July 18, 2009, 10:10:52 AM

Previous topic - Next topic

ml1969

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

Stefan Pendl

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.
---
Stefan

Proud member of the UltraDefrag Development Team

ml1969

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

JohnF

Pick up the mouse clicks, maybe use WM_LBUTTONDOWN then write the code to decide if the click was in the top left.

John



ml1969

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



JohnF


ml1969

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

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

Stefan Pendl

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.
---
Stefan

Proud member of the UltraDefrag Development Team

ml1969

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

Seltsamuel

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

JohnF

#11

#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

ml1969

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

Stefan Pendl

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.
---
Stefan

Proud member of the UltraDefrag Development Team

JohnF

#14
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);
   }
}