我试图打开不同的网址,当点击一张图片(每个图片将打开不同的网址)不幸的是,它一直只打开第一个网址。图像的方向和调用url的代码放在mouseclick的callbackfuction下,如下所示。
| | |
| Image 1|Image 2 |
|________|________|
void CallBackFunc(int event, int x, int y, int flags, void * userdata)
{
if(event == EVENT_LBUTTONDOWN && image1.data)
{
//cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
const char * urlA = "http://www.google.com";
wchar_t urlW[MAX_PATH];
std::copy(urlA, urlA + lstrlenA(urlA) + 1, urlW);
if((int)ShellExecuteW(NULL, L"open", urlW, NULL, NULL, SW_SHOW) < 32)
;
}
else if(event == EVENT_LBUTTONDOWN && image2.data)
{
cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")"
<< endl;
const char * urlA = "http://www.yahoo.com";
wchar_t urlW[MAX_PATH];
std::copy(urlA, urlA + lstrlenA(urlA) + 1, urlW);
if((int)ShellExecuteW(NULL, L"open", urlW, NULL, NULL, SW_SHOW) < 32)
;
}
else if(event == EVENT_RBUTTONDOWN)
{
cout << "Right button of the mouse is clicked - position (" << x << ", " << y << ")"
<< endl;
}
else if(event == EVENT_MBUTTONDOWN)
{
cout << "Middle button of the mouse is clicked - position (" << x << ", " << y
<< ")" << endl;
}
else if(event == EVENT_MOUSEMOVE)
{
cout << "Mouse move over the window - position (" << x << ", " << y << ")" << endl;
}
}
我真的不知道我哪里错了,因为我试图声明第二个url为urlB,但它仍然不起作用。我希望有人能帮助我。谢谢!
PS (我正在使用opencv 3.0在C++上运行程序)
发布于 2016-03-01 13:40:02
从图片的方向判断,可以通过点击事件的x
坐标来选择网址。例如,如果你的图像在宽度上是相等的,你可以只使用x < window_width/2
条件。
示例:
if(event == EVENT_LBUTTONDOWN && x < window_width / 2)
要获得窗口宽度,您可以获取cvGetWindowHandle
窗口本机句柄,然后在其上使用特定于平台的函数,或者仅根据图像的大小计算宽度。
https://stackoverflow.com/questions/35715317
复制相似问题