我有下面的代码,我试图从事件窗口获取选定的文本并将其打印到控制台上。
DWORD new12=0;
KEYBDINPUT* input = new KEYBDINPUT[key_count];
if( GetGUIThreadInfo( new12, lpgui ) )
{
target_window = lpgui->hwndFocus;
}
else
{
// You can get more information on why the function failed by calling
// the win32 function, GetLastError().
std::cout<<"error1";
}
// We're sending two keys CONTROL and 'V'. Since keydown and keyup are two
// seperate messages, we multiply that number by two.
for( int i = 0; i < key_count; i++ )
{
input[i].dwFlags = 0;
//input[i].type = INPUT_KEYBOARD;
}
input[0].wVk = VK_CONTROL;
input[0].wScan = MapVirtualKey( VK_CONTROL, MAPVK_VK_TO_VSC );
input[1].wVk = 0x56; // Virtual key code for 'v'
input[1].wScan = MapVirtualKey( 0x56, MAPVK_VK_TO_VSC );
我有上面的 C++ 代码,但它似乎在 input[0].wScan = 行中给出了一个错误,指出“
我想知道这里有什么问题。我认为这个错误不会因为任何声明问题而出现。你能帮我一下吗?谢谢。错误:MAPVK_VK_TO_VSC' 未在此范围内声明
” MapVirtualKey( VK_CONTROL, MAPVK_VK_TO_VSC );
最佳答案
MAPVK_VK_TO_VSC 是一个简单的#define MAPVK_VK_TO_VSC (0)
,甚至不是一个常量,因此应该在预处理阶段解析。
要么您错过了在此代码之前包含“winuser.h”(在这种情况下,MapVirtualKey 和 VK_ 常量也将未声明),要么您在某处未定义 WIN_VER(或将其定义为小于 0x400)。有时很容易忘记 WIN_VER 必须以十六进制定义,并且使用 #define WINVER 500 之类的内容,您的版本低于 2.0
关于c++ - 使用c++从事件窗口获取选定的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16503586/