home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / borland / cb / setup / cbuilder / data.z / DEMOLBL.CPP < prev    next >
C/C++ Source or Header  |  1997-02-28  |  2KB  |  78 lines

  1. //---------------------------------------------------------------------------
  2. // Borland C++Builder
  3. // Copyright (c) 1987, 1997 Borland International Inc.  All Rights Reserved.
  4. //---------------------------------------------------------------------------
  5. // Demonstrates FreeNotication to safely link to controls in other forms
  6. //  through form linking and demonstrates preventing a component from being used
  7. //  in form inheritence
  8.  
  9. #if !defined (REGISTER_ALL_CONTROLS)
  10.   #include  "demolbl.h"
  11. #else
  12.   #include "source\demolbl.h"
  13. #endif
  14.  
  15. //#pragma resource "*.res"   //IDE links .res automatically for components
  16.  
  17. namespace Demolbl{
  18. void __fastcall Register()
  19. {
  20.   TComponentClass classes[1] = {__classid(TDemoLabel)};
  21.   RegisterComponents("Samples", classes, 0);
  22. }
  23. } //end namespace
  24.  
  25. __fastcall TDemoLabel::TDemoLabel(TComponent *AOwner):
  26.     TGraphicControl(AOwner)
  27. {
  28.   FComponentStyle >> csInheritable;
  29.   Width=64;
  30.   Height=13;
  31. }
  32.  
  33. void __fastcall    TDemoLabel::Notification(TComponent *AComponent, TOperation Operation)
  34. {
  35.   TGraphicControl::Notification(AComponent, Operation);
  36.   if ((Operation == opRemove)  && (AComponent == FFocusControl))
  37.     FFocusControl = 0;
  38. }
  39.  
  40. void __fastcall    TDemoLabel::SetFocusControl(TWinControl *Value)
  41. {
  42.   FFocusControl = Value;
  43.  
  44.   // Calling FreeNotification ensures that this component will receive an
  45.   // opRemove when Value is either removed from its owner or when it is
  46.   // destroyed.
  47.  
  48.   Value->FreeNotification(Value);
  49. }
  50.  
  51. void __fastcall    TDemoLabel::Paint()
  52. {
  53.   TRect    Rect = ClientRect;
  54.   Canvas->Font = Font;
  55.   Canvas->Brush->Color = Color;
  56.   Canvas->FillRect(Rect);
  57.   DrawText(Canvas->Handle, Caption.c_str(), Caption.Length(), &RECT(Rect),
  58.     DT_EXPANDTABS | DT_WORDBREAK | DT_LEFT);
  59. }
  60.  
  61. void __fastcall    TDemoLabel::CMDialogChar(TCMDialogKey &Message)
  62. {
  63.   if (FFocusControl != NULL &&
  64.       Enabled == true &&
  65.       IsAccel(Message.CharCode, Caption))
  66.       if (FFocusControl->CanFocus()){
  67.         FFocusControl->SetFocus();
  68.         Message.Result = 1;
  69.       }
  70. }
  71.  
  72. void __fastcall    TDemoLabel::CMTextChanged(TMessage &Message)
  73. {
  74.   Invalidate();
  75. }
  76.  
  77.  
  78.