[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
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

  1. include <vcl.h>
  2. pragma hdrstop
  1. include "Unit1.h"
//---------------------------------------------------------------------------
  1. pragma package(smart_init)
  2. pragma resource "*.dfm"
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; } //---------------------------------------------------------------------------


Unit1.h

//---------------------------------------------------------------------------
  1. ifndef Unit1H
  2. define Unit1H
//---------------------------------------------------------------------------
  1. include <Classes.hpp>
  2. include <Controls.hpp>
  3. include <StdCtrls.hpp>
  4. include <Forms.hpp>
  5. include <AppEvnts.hpp>
  6. include <ComCtrls.hpp>
  7. include <ExtCtrls.hpp>
//--------------------------------------------------------------------------- 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; //---------------------------------------------------------------------------
  1. endif


Code links

Links



last edited (November 18, 2006) by bilderbikkel, Number of views: 2681, Current Rev: 2 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Site Management by Lars Hagelin at Kontantkort.se.