我在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; 
    //----------------------
  }
}
//------------------------------------------------------------------------
Handled設True
void __fastcall TForm1::FormMouseWheelDown(TObject *Sender, TShiftState Shift, TPoint &MousePos,
          bool &Handled)
{
  Handled = true;
  ...
}
 哇!  真的解決了耶!!
哇!  真的解決了耶!!
https://youtu.be/CKHVVV6nK74
非常感謝,你太強了
可否解釋一下為何好嗎?
Windows message相關的API,
通常都會利用Handled來讓呼叫你的人知道,
這個message是否有被確實的處理。
這種情況,如果你放任Handled維持false,
上層就會認為你沒有做事,或是事情沒做完,
然後接著做他認為該彌補的動作。
這個所謂該彌補的動作,通常是呼叫下一個候補UI元件來處理,
例如被蓋在下面的另一個UI元件。
至於為什麼在這邊會是同一個元件被重複呼叫,
我就不清楚了。
了解,感謝!