Problem with rendering clipboard contents in popup menu

T

twinfire

I have an mfc dialog application that sets a dll as a global keyboard
hook. The dll looks for the correct key press, grabs the mouse coords
and then sends a message back to the dialog app. I am trying to get
the dialog app to set focus on the windows under the cursor, issue a
control-c keyboard event to copy the underlying text and then read
from the clipboard and display in a popup menu. I have not been able
to get this to work. The text under the cursor is copied the first
time and display in the popup, but subsequent keyboard presses over
different text results in the initial text to be display in the menu.
I am attaching the method in the dialog app that handles the message
coming from the dll hook. Thanks for any help you can offer.

LRESULT CInSideDlg::processKeyboardClick(WPARAM wParam, LPARAM lParam)
{

POINT pt;
pt.x = wParam;
pt.y = lParam;

HWND hwnd = ::WindowFromPoint(pt);

::ShowWindow(hwnd, SW_SHOW);
::SetForegroundWindow(hwnd);
::SetFocus(hwnd);

keybd_event(VK_CONTROL,0x45,KEYEVENTF_EXTENDEDKEY | 0, 0);
keybd_event(0x43,0x45,KEYEVENTF_EXTENDEDKEY | 0,0);
keybd_event(0x43,0x45,KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0);

CMenu mainMenu;
VERIFY(mainMenu.LoadMenu(IDR_MENU2));

CMenu* popupMenu = mainMenu.GetSubMenu(0);

int iCount = popupMenu->GetMenuItemCount();

while (iCount > 0) {
popupMenu->DeleteMenu(0, MF_BYPOSITION);
iCount = popupMenu->GetMenuItemCount();
}

if (OpenClipboard()) {
HANDLE hClipboardData = GetClipboardData(CF_TEXT);
char *pchData = (char*)GlobalLock(hClipboardData);

CString strFromClipboard = pchData;
popupMenu->InsertMenu(0, MF_BYPOSITION | MF_POPUP,
ID_INSIDE_DUMMYITEM, strFromClipboard);
popupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, wParam,
lParam, AfxGetMainWnd());

GlobalUnlock(hClipboardData);
CloseClipboard();
}

return 0L;
}
 
A

Aggro

twinfire said:
I have an mfc dialog application

This group is for standard C++ language only, not for MFC or dialogs,
try this group instead:

microsoft.public.vc.mfc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top