iT邦幫忙

0

C++程式 Form event之 MouseWheelDown及MouseWheelUp問題請教

  • 分享至 

  • xImage

我在Form之event FormMouseWheelDown及FormMouseWheelUp 設計兩段程式碼如下,目地為使操作滑鼠中鍵滾動時可變換ListBox項目。結果做出來了如影片所示。
然而有一瑕疵,即滑鼠中鍵滾動時游標移動兩個項目,我希望能一一移動,請問高手大大可有解方? 謝謝

//------------------------------------------------------------------------
void __fastcall TForm1::FormMouseWheelDown(TObject *Sender, TShiftState Shift, TPoint &MousePos,
          bool &Handled)
{
  ListBox1->SetFocus();

  if(ListBox1->ItemIndex < ListBox1->Items->Count){
    ++ListBox1->ItemIndex;  //往下切換項目
    //----- 顯示項目名稱 ---
    String itm = ListBox1->Items->Strings[ListBox1->ItemIndex];
    Edit3->Text = get_window_tlt(itm);
    //----- 顯示項目位置 ---
    Label20->Caption=(String)ListBox1->ItemIndex + " / " + (String)ListBox1->Items->Count; 
    //----------------------
  }
}
//------------------------------------------------------------------------

void __fastcall TForm1::FormMouseWheelUp(TObject *Sender, TShiftState Shift, TPoint &MousePos,
 bool &Handled)
{
  ListBox1->SetFocus();
 
  if(ListBox1->ItemIndex>0){
    --ListBox1->ItemIndex;  //往上切換項目
    //----- 顯示項目名稱 ---
    String itm = ListBox1->Items->Strings[ListBox1->ItemIndex];
    Edit3->Text = get_window_tlt(itm);
    //----- 顯示項目位置 ---
    Label20->Caption=(String)ListBox1->ItemIndex + " / " + (String)ListBox1->Items->Count; 
    //----------------------
  }
}
//------------------------------------------------------------------------

https://youtube.com/shorts/f_cENmRz5Vw?feature=share

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
frogsoul
iT邦研究生 5 級 ‧ 2024-01-01 19:51:33

Handled設True

看更多先前的回應...收起先前的回應...
cpc0935 iT邦研究生 5 級 ‧ 2024-01-01 20:52:26 檢舉

那裡的Handled?

frogsoul iT邦研究生 5 級 ‧ 2024-01-02 08:43:19 檢舉

你的函式
search一下你自己的程式碼應該很明顯

cpc0935 iT邦研究生 5 級 ‧ 2024-01-02 11:12:33 檢舉
void __fastcall TForm1::FormMouseWheelDown(TObject *Sender, TShiftState Shift, TPoint &MousePos,
          bool &Handled)
{
  Handled = true;
  ...
}

/images/emoticon/emoticon01.gif哇! 真的解決了耶!!
https://youtu.be/CKHVVV6nK74
非常感謝,你太強了
可否解釋一下為何好嗎?

frogsoul iT邦研究生 5 級 ‧ 2024-01-03 08:34:34 檢舉

Windows message相關的API,
通常都會利用Handled來讓呼叫你的人知道,
這個message是否有被確實的處理。

這種情況,如果你放任Handled維持false,
上層就會認為你沒有做事,或是事情沒做完,
然後接著做他認為該彌補的動作。

這個所謂該彌補的動作,通常是呼叫下一個候補UI元件來處理,
例如被蓋在下面的另一個UI元件。

至於為什麼在這邊會是同一個元件被重複呼叫,
我就不清楚了。

cpc0935 iT邦研究生 5 級 ‧ 2024-01-08 21:33:04 檢舉

了解,感謝!

我要發表回答

立即登入回答