问题描述
我有一个C ++ API项目,
在这个项目中Handel到Notepad Windows并注入Dll来处理记事本,我希望在区域中双击鼠标编辑记事本在文本上我的程序诊断双击鼠标然后获取选定的文本并在位置鼠标的工具提示中显示所选文本。
现在无法在NewWndProc中检测WM_LBUTTONDBLCLK
这是代码的一部分:
我尝试了什么:
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance ,LPSTR lpCmdLine,int nCmdShow)
{
HWND hwnd = FindWindow(notepad,NULL);
HMENU hMenu,hSubMenu;
hMenu = GetMenu(hwnd);
hSubMenu = GetSubMenu(hMenu,5);
if(hSubMenu == 0)
{
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu,MF_CHECKED | MF_UNCHECKED,ID_EXTENSION_DICTIONARY_BY_MOUSE,通过鼠标启用字典);
AppendMenu(hSubMenu,MF_CHECKED | MF_UNCHECKED,ID_EXTENSION_DICTIONARY_BY_CLIPBOARD,按剪贴板启用字典);
AppendMenu(hSubMenu,MF_CHECKED | MF_UNCHECKED,ID_EXTENSION_CLIPBOARD_SPY,启用剪贴板间谍);
AppendMenu(hMenu,MF_STRING | MF_POPUP,(UINT)hSubMenu,& Extension);
SetMenu(hwnd,hMenu);
}
PostMessage(hwnd,WM_COMMAND,GetMenuItemID(hSubMenu,1),0);
返回0;
}
LRESULT CALLBACK NewWndProc(HWND Hwnd,UINT消息,WPARAM wParam,LPARAM lParam)
{
switch(消息)
{
案例WM_MBUTTONDBLCLK:
msgbox(查找双击鼠标);
案例CS_DBLCLKS:
{
HMENU hmenu = GetMenu(Hwnd);
if(GetMenuState(hmenu,ID_EXTENSION_DICTIONARY_BY_MOUSE,MF_BYCOMMAND | MF_CHECKED))
{
HWND hwndEdit = FindWindowEx(Hwnd,NULL,EDIT ,NULL);
SendMessage(hwndEdit,0x304,0,0);
SendMessage(hwndEdit,0x304,0,0);
SendMessage(hwndEdit,WM_COPY,0,0);
SendMessage(hwndEdit,WM_PASTE,0,0);
INT nSelStart,nSelEnd;
nSelStart = 2;
nSelEnd = 1000;
SendMessage(hwndEdit,EM_GETSEL,(WPARAM) & nSelStart,(LPARAM)& nSelEnd);
int textLen =(int)SendMessage(hwndEdit,WM_GETTEXTLENGTH,0,0);
if(textLen> 0)
{
CONST WCHAR bufferSize = 1024;
WCHAR textBuffer [bufferSize];
SendMessage(hwndEdit,WM_GETTEXT,(WPARAM)bufferSize,(LPARAM)textBuffer);
CreateToolTipForRect(hwndEdit,(LPSTR)textBuffer);
}
}
}
休息;
案例WM_COMMAND:
{HMENU hmenu;
开关(LOWORD(wParam))
{
案例ID_EXTENSION_DICTIONARY_BY_MOUSE:
// if(BN_CLICKED == HIWORD(wParam)){}
{
hmenu = GetMenu(Hwnd);
CheckOrUncheckMenuItem(ID_EXTENSION_DICTIONARY_BY_MOUSE,hmenu);
休息;
}
// CheckMenuItem(hmenu,ID_EXTENSION_DICTIONARY_BY_MOUSE,MF_BYCOMMAND | MF_CHECKED);
// ModifyMenu(hmenu,IDM_REGULAR,MF_BYCOMMAND | MF_CHECKED | MF_OWNERDRAW,IDM_REGULAR,(LPTSTR)& ID_EXTENSION_DICTIONARY_BY_MOUSE);
案例ID_EXTENSION_DICTIONARY_BY_CLIPBOARD:
{
hmenu = GetMenu(Hwnd);
CheckOrUncheckMenuItem(ID_EXTENSION_DICTIONARY_BY_CLIPBOARD,hmenu);
休息;
}
case ID_EXTENSION_CLIPBOARD_SPY:
{
hmenu = GetMenu(Hwnd);
CheckOrUncheckMenuItem(ID_EXTENSION_CLIPBOARD_SPY,hmenu);
休息;
}
默认值:
返回DefWindowProc(Hwnd,Message,wParam,lParam);
}
}
break;
案例WM_MOVE:
休息;
案例WM_DESTROY:
{
LPCTSTR strMsg =此消息已发送;
SendMessage(Hwnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)strMsg);
休息;
}
案例WM_SIZE:
休息;
}
返回CallWindowProc((WNDPROC)OldWndProc,Hwnd,Message,wParam,lParam);
}
I Have one C++ API Project,
At This Project Handel to Notepad Windows And Injecting Dll To Process Notepad, I Want With Double Click Mouse in area Edit Notepad on Text My Program diagnosis Double Click Mouse Then Get Text In Selected and Show Selected Text In tool Tips at the Position Mouse.
Now Can't detection WM_LBUTTONDBLCLK In NewWndProc
This is Part Of Code:
What I have tried:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd= FindWindow("notepad", NULL );
HMENU hMenu, hSubMenu;
hMenu = GetMenu(hwnd);
hSubMenu=GetSubMenu(hMenu,5);
if (hSubMenu==0 )
{
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_CHECKED | MF_UNCHECKED , ID_EXTENSION_DICTIONARY_BY_MOUSE, "Enable Dictionary By Mouse");
AppendMenu(hSubMenu, MF_CHECKED | MF_UNCHECKED , ID_EXTENSION_DICTIONARY_BY_CLIPBOARD , "Enable Dictionary By Clipboard");
AppendMenu(hSubMenu, MF_CHECKED | MF_UNCHECKED , ID_EXTENSION_CLIPBOARD_SPY, "Enable Clipboard Spy");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Extension");
SetMenu(hwnd, hMenu);
}
PostMessage(hwnd, WM_COMMAND, GetMenuItemID(hSubMenu, 1), 0);
return 0;
}
LRESULT CALLBACK NewWndProc(HWND Hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_MBUTTONDBLCLK :
msgbox("Find Double Click Mouse ");
case CS_DBLCLKS:
{
HMENU hmenu = GetMenu(Hwnd);
if (GetMenuState(hmenu, ID_EXTENSION_DICTIONARY_BY_MOUSE, MF_BYCOMMAND | MF_CHECKED))
{
HWND hwndEdit = FindWindowEx(Hwnd, NULL, "EDIT", NULL);
SendMessage(hwndEdit, 0x304, 0, 0);
SendMessage(hwndEdit, 0x304, 0, 0);
SendMessage(hwndEdit, WM_COPY, 0, 0);
SendMessage(hwndEdit, WM_PASTE, 0, 0);
INT nSelStart, nSelEnd;
nSelStart = 2;
nSelEnd = 1000;
SendMessage(hwndEdit, EM_GETSEL, (WPARAM)&nSelStart, (LPARAM)&nSelEnd);
int textLen = (int)SendMessage(hwndEdit, WM_GETTEXTLENGTH, 0, 0);
if (textLen > 0)
{
CONST WCHAR bufferSize = 1024;
WCHAR textBuffer[bufferSize] ;
SendMessage(hwndEdit, WM_GETTEXT, (WPARAM)bufferSize, (LPARAM)textBuffer);
CreateToolTipForRect(hwndEdit,(LPSTR)textBuffer);
}
}
}
break;
case WM_COMMAND:
{ HMENU hmenu;
switch(LOWORD(wParam))
{
case ID_EXTENSION_DICTIONARY_BY_MOUSE:
//if(BN_CLICKED == HIWORD(wParam)){}
{
hmenu = GetMenu(Hwnd);
CheckOrUncheckMenuItem(ID_EXTENSION_DICTIONARY_BY_MOUSE,hmenu);
break;
}
//CheckMenuItem(hmenu, ID_EXTENSION_DICTIONARY_BY_MOUSE, MF_BYCOMMAND | MF_CHECKED);
// ModifyMenu(hmenu, IDM_REGULAR, MF_BYCOMMAND | MF_CHECKED | MF_OWNERDRAW, IDM_REGULAR, (LPTSTR) &ID_EXTENSION_DICTIONARY_BY_MOUSE);
case ID_EXTENSION_DICTIONARY_BY_CLIPBOARD:
{
hmenu = GetMenu(Hwnd);
CheckOrUncheckMenuItem(ID_EXTENSION_DICTIONARY_BY_CLIPBOARD,hmenu);
break;
}
case ID_EXTENSION_CLIPBOARD_SPY:
{
hmenu = GetMenu(Hwnd);
CheckOrUncheckMenuItem(ID_EXTENSION_CLIPBOARD_SPY,hmenu);
break;
}
default:
return DefWindowProc(Hwnd, Message , wParam, lParam);
}
}
break;
case WM_MOVE:
break;
case WM_DESTROY:
{
LPCTSTR strMsg = "This message was sent";
SendMessage(Hwnd, WM_SETTEXT, 0, (LPARAM)(LPCTSTR)strMsg);
break;
}
case WM_SIZE:
break;
}
return CallWindowProc((WNDPROC)OldWndProc, Hwnd, Message, wParam, lParam);
}
推荐答案
这篇关于编辑记事本时无法发送WM_LBUTTONDBLCLK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!