我試圖打開不同的網址,當點擊圖像(每個圖像將打開不同的網址)不幸的是,它不斷打開第一個網址。圖像的方向和調用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