[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppVclUserMessage
Below is an example to trap all windows messages and to generate and send your own user message.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppVclUserMessage
(C++ VCL) Make your own user messages
To generate a unique messsage number use the function RegisterWindowMessage.Below is an example to trap all windows messages and to generate and send your own user message.
Unit1.cpp
- include <vcl.h>
- pragma hdrstop
//---------------------------------------------------------------------------
- include "Unit1.h"
TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner), WM_DO_STUFF(RegisterWindowMessage("BILDERBIKKEL_DO_STUFF")) { doHandle = true; Application->OnMessage = ApplicationEvents1->OnMessage; } //--------------------------------------------------------------------------- void __fastcall TForm1::ApplicationEvents1Message(tagMSG &Msg, bool &Handled) { if (Msg.message==0 || doHandle==false) return; String output = IntToStr(Msg.message) + '\t' + IntToStr(Msg.lParam) + '\t' + IntToStr(Msg.wParam); if (Msg.message==this->WM_DO_STUFF) { Handled = true; output = "*****\t" + output; } RichEdit1->Lines->Add(output); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *) { PostMessage(0,this->WM_DO_STUFF,69,69); } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *) { doHandle = !doHandle; } //---------------------------------------------------------------------------
- pragma package(smart_init)
- pragma resource "*.dfm"
Unit1.h
//---------------------------------------------------------------------------//---------------------------------------------------------------------------
- ifndef Unit1H
- define Unit1H
//--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TApplicationEvents *ApplicationEvents1; TRichEdit *RichEdit1; TPanel *Panel1; TButton *Button1; TButton *Button2; void __fastcall ApplicationEvents1Message(tagMSG &Msg, bool &Handled); void __fastcall Button1Click(TObject *Sender); void __fastcall Button2Click(TObject *Sender); private: // User declarations bool doHandle; public: // User declarations const UINT WM_DO_STUFF; __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //---------------------------------------------------------------------------
- include <Classes.hpp>
- include <Controls.hpp>
- include <StdCtrls.hpp>
- include <Forms.hpp>
- include <AppEvnts.hpp>
- include <ComCtrls.hpp>
- include <ExtCtrls.hpp>
- endif
Code links
- #include
- class
- const
- extern
- if
- #include
- int
- PostMessage
- private
- public
- ?RegisterMessage
- return
- TApplicationEvents
- TForm
- TForm1
- TRichEdit
- unsigned
- void
Links
- http://www.codeproject.com/dialog/messagehandling3.asp: The page this info is inspired by
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
