我试图打开不同的网址,当点击图像(每个图像将打开不同的网址)不幸的是,它不断打开第一个网址。图像的方向和调用url的代码放在鼠标点击的回调函数下,如下所示。用鼠标点击两个不同的图像打开不同的网址C++
| | |
| 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(我运行该程序的C++与OpenCV的3.0)
你为什么调度image.data?如果方向一致,可能只是检查'x
yuyoyuppe