NO

Author Topic: Pocket pc CONTEXTMENU  (Read 4534 times)

grom-it

  • Guest
Pocket pc CONTEXTMENU
« on: April 10, 2008, 10:03:12 PM »
Hi all...
I have hunted high and low and cant seem to find info on how to implement a pocket pc context menu.

Is this facility alrfeady in Pelles c IDE and i have missed it?


Currently on my own pocket pc i get a little circle of dots appear as i hold the stylus onto the screen just before the context menu pops up.

No such action in my own app .
Whilst the blue dots are not absoultley neccasary it would be nice to do it the right way.

Any Info greatly appreciated.
Gromit.


Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Pocket pc CONTEXTMENU
« Reply #1 on: April 15, 2008, 06:33:25 PM »
I don't think I have ever used context menus on Pocket PC, but there appears to be a WM_CONTEXTMENU message and TrackPopupMenu() API function - just like on desktop Windows.

Maybe trapping the WM_CONTEXTMENU message and using code like this will work on Pocket PC too...?!

Code: [Select]
    /* ... snip ... */
    hMenu = LoadMenu(g_hmod, MAKEINTRESOURCE(menu-identifier));
    if (hMenu != NULL)
    {
        switch (TrackPopupMenu(GetSubMenu(hMenu, 0)  /* use first popup as context menu */,
            TPM_RETURNCMD|TPM_<flag>..., x, y, ...
       {
           case menu-id-1:  /* do something */
           case menu-id-2:  /* do something */
       }
       /* ... snip ... */
    }
/Pelle

grom-it

  • Guest
Re: Pocket pc CONTEXTMENU
« Reply #2 on: June 27, 2008, 11:50:12 PM »
 :)
I have Managed to implement a context menu using win32 API so if this is any use to anyone.
Here it is and i only hope i have done it right .
If not Why not please tell.


static LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{




 switch (msg)
    {
 
 HANDLE_MSG(hwnd, WM_CREATE, Main_OnCreate);
        HANDLE_MSG(hwnd, WM_ACTIVATE, Main_OnActivate);
        HANDLE_MSG(hwnd, WM_SETTINGCHANGE, Main_OnSettingChange);
        HANDLE_MSG(hwnd, WM_PAINT, Main_OnPaint);
        HANDLE_MSG(hwnd, WM_COMMAND, Main_OnCommand);
        HANDLE_MSG(hwnd, WM_DESTROY, Main_OnDestroy);
        /* TODO: enter more messages here */
 
I have implemented a windows timer on a pendown event and if the pen stays down for half a second my MyContextMenu is called

 
case WM_LBUTTONDOWN :
   {
   SetTimer(g_hwnd,1,500,NULL); // think this is .5 second
         g_xPos = LOWORD(lParam);
         g_yPos = HIWORD(lParam); // just positional globals
      }
 break;
case WM_LBUTTONUP:
      
 KillTimer(g_hwnd,1); // make sure timer is killed on button up
         break;

case WM_TIMER:
     KillTimer(g_hwnd,1); // kill my timer
DO I NEED TO kill an expired timer or is it already dead
   
// call my menu
MyContextMenu(g_xPos,g_yPos);

         break;
   
 default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
}



 static void MyContextMenu(int x,int y)
{
TrackPopupMenuEx(g_hpopup,TPM_VERTICAL,x,y,g_hwnd,NULL);
}



My CONTEXTMENU is  created in WM_Create as

g_hpopup=CreatePopupMenu(); 

            AppendMenu(g_hpopup, MF_STRING, IDMPOP1_SAMPLE, L"Sample1");
            AppendMenu(g_hpopup, MF_STRING, IDMPOP2_SAMPLE,L"Sample2");

}

The only real problem i can see myself is the fact that, on pen up following context menu call, or pen not down long enough so no call, i am implementing a KillTimer call on a timer that may not now exist but this does not show any errors on the PDA and compiles ok ???
i had thought of using a Boolean to test it before killing but it does seem to work ok without.
Any feedback Would be Appreciated.
 :)