BCB-Memo貼上之後自動換行-WM_PASTE 


有時候你可能會需要讓使用者在 Memo 貼上文字之後自動換行。要達到這樣的效果有幾種方法辦得到。第一種是在OnMouseUp event 裡頭偵測使用者是否按下了 Ctrl+V。

不過這方法並不是很好,所以在這裡我要介紹第二種方法。第二種方法是直接偵測送到 Memo 的 WM_PASTE 訊息。



//Unit1.h

private: // User declarations

//新增定義

TWndMethod OldMemoProc;

void __fastcall NewMemoProc(TMessage &Message);





//Unit1.cpp
void __fastcall TForm1::NewMemoProc(TMessage &Message)
{
   OldMemoProc(Message);
   if (Message.Msg == WM_PASTE)    //若是貼上
       Memo1->Lines->Add("");      //就自動換行
   }

}


//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  OldMemoProc = Memo1->WindowProc;
  Memo1->WindowProc = NewMemoProc;
}


arrow
arrow

    yao67 發表在 痞客邦 留言(0) 人氣()