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.