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:rocessKeyboardClick(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;
}
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:rocessKeyboardClick(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;
}