问题描述
截至目前,我已成功获得x和y坐标。
在面板代码中。
POINT cursorPos;
GetCursorPos(& cursorPos);
int x;
int y;
x = cursorPos.x;
y = cursorPos.y;
cout<< x<< endl;
cout<< y<< endl;
然而,我得到的x和y坐标是全局的,也就是说,不在我希望得到坐标的面板内。
我明白需要ClientToScreen将x和y坐标更改为相对位置,但我如何在C ++ / CLR中这样做?
因为ClientToScreen需要一个句柄,这在C ++ / CLR中没有引入(请原谅我,如果这个点我错了)。谢谢:)
更新:我尝试将我的面板投射到hwnd中,但仍然无法正常工作。
HWND hwnd = static_cast< hwnd>(this-> panel1-> Handle.ToPointer());
So as of now, I've managed to successfully get the x and y coordinates.
Inside the panel code.
POINT cursorPos;
GetCursorPos(&cursorPos);
int x;
int y;
x = cursorPos.x;
y = cursorPos.y;
cout << x << endl;
cout << y << endl;
However, the x and y coordinate that I got is global, aka, not within a panel that I want to get my coordinates from.
I do understand that ClientToScreen is required to change the x and y coordinate to its relative placing, but how do i do that in C++/CLR?
Because ClientToScreen requires a handle, which is not introduced in C++/CLR (Pardon me if im wrong about this point). Thanks :)
Update: I tried casting my panel into a hwnd, but still its not working.
HWND hwnd = static_cast<hwnd>(this->panel1->Handle.ToPointer());
推荐答案
这篇关于在C ++ / CLI中获取GetCursorPos之后的相对位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!