By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,479 Members | 1,749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,479 IT Pros & Developers. It's quick & easy.

Problem with rendering clipboard contents in popup menu

P: n/a
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;
}
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
twinfire wrote:
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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.