• Welcome to Valhalla Legends Archive.
 

[C++] TrackPopupMenu problems with my bot

Started by Smithsonian, July 24, 2005, 08:19 PM

Previous topic - Next topic

Smithsonian

Hey guys I have a rich edit control on my main dialog, and have caught the proper messages to handle the right mouse button being clicked on it. My problem is, the TrackPopupMenu function is returning error code 6 - invalid handle. I'm pretty sure I've got all my handles setup correctly, but I figured I'd post here and see if anyone can see why they're not.

Any help is appreciated. Thanks.


ERROR_INVALID_HANDLE (6) - The handle is invalid.

case WM_CONTEXTMENU:
{
HMENU menu = CreatePopupMenu();
MENUITEMINFO menuinfo;
int x = LOWORD(lParam);
int y = HIWORD(lParam);

menuinfo.cbSize = sizeof(menuinfo);
menuinfo.fMask = MIIM_TYPE;
menuinfo.fType = MFT_STRING;
menuinfo.fState = MFS_ENABLED;

char MenuText[24];
strcpy(MenuText, "Copy");
menuinfo.dwTypeData = MenuText;
menuinfo.cch = strlen(MenuText);



if(!InsertMenuItem(menu, 0, true, &menuinfo))
AppendText(hBNChat, RED, "Failed to create copy tab menu\n");

menuinfo.cbSize = sizeof(menuinfo);
menuinfo.fMask = MIIM_TYPE;
menuinfo.fType = MFT_STRING;
menuinfo.fState = MFS_ENABLED;

strcpy(MenuText, "Clear");
menuinfo.dwTypeData = MenuText;
menuinfo.cch = strlen(MenuText);



if(!InsertMenuItem(menu, 0, true, &menuinfo))
AppendText(hBNChat, RED, "Failed to create clear tab menu\n");

int result = TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD,
x, y, 0, GetDlgItem(hMainDlg, IDC_BNCHAT), NULL);

switch(result) {
case 0:
DestroyMenu(menu);
break;
case 1:
SendDlgItemMessage(hMainDlg, IDC_BNCHAT, WM_COPY, 0, 0);
break;
case 2:
SendDlgItemMessage(hMainDlg, IDC_BNCHAT, WM_SETTEXT, 0, (LPARAM)"");
break;
default:
AppendText(hBNChat, RED, "Result: %i\n", result);
break;
}

DestroyMenu(menu);
break;
}

warz

Is the popup menu being displayed? If so then I'm guessing it's talking about the handle to the hWnd to send the messages to?

Smithsonian

#2
The popup appears, so it's the result of TrackPopupMenu. Anyways, I change the TrackPopupMenu line to look like this...


int result = TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD,
x, y, 0, hDlgMain, NULL);


Changed that handle to the handle of my main dialog window

and now I sometimes get error code 5 - access is denied, and sometimes code 6 - invalid handle. Whats going on ???

Smithsonian

Hey, I've posted on another forum about this problem and they didn't seem to know anything. I was wondering if anyone else on here that's programmed C++ bots has messed with popup menus. Zakath maybe? Just trying to get these things workin! Thanks.