⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modi_ocx.cpp

📁 微软的虚拟打印组件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void __fastcall TMiRect::Connect()
{
  if (!m_DefaultIntf) {
    _di_IUnknown punk = GetServer();
    m_DefaultIntf = punk;
    if (ServerData->EventIID != GUID_NULL)
      ConnectEvents(GetDunk());
  }
}

void __fastcall TMiRect::Disconnect()
{
  if (m_DefaultIntf) {
    
    if (ServerData->EventIID != GUID_NULL)
      DisconnectEvents(GetDunk());
    m_DefaultIntf.Reset();
  }
}

void __fastcall TMiRect::BeforeDestruction()
{
  Disconnect();
}

void __fastcall TMiRect::ConnectTo(IMiRectPtr intf)
{
  Disconnect();
  m_DefaultIntf = intf;
  if (ServerData->EventIID != GUID_NULL)
    ConnectEvents(GetDunk());
}

void __fastcall TMiRect::InitServerData()
{
  static Oleserver::TServerData sd;
  sd.ClassID = CLSID_MiRect;
  sd.IntfIID = __uuidof(IMiRect);
  sd.EventIID= GUID_NULL;
  ServerData = &sd;
}

IMiRectsPtr& TMiRects::GetDefaultInterface()
{
  if (!m_DefaultIntf)
    Connect();
  return m_DefaultIntf;
}

_di_IUnknown __fastcall TMiRects::GetDunk()
{
  _di_IUnknown diUnk;
  if (m_DefaultIntf) {
    IUnknownPtr punk = m_DefaultIntf;
    diUnk = LPUNKNOWN(punk);
  }
  return diUnk;
}

void __fastcall TMiRects::Connect()
{
  if (!m_DefaultIntf) {
    _di_IUnknown punk = GetServer();
    m_DefaultIntf = punk;
    if (ServerData->EventIID != GUID_NULL)
      ConnectEvents(GetDunk());
  }
}

void __fastcall TMiRects::Disconnect()
{
  if (m_DefaultIntf) {
    
    if (ServerData->EventIID != GUID_NULL)
      DisconnectEvents(GetDunk());
    m_DefaultIntf.Reset();
  }
}

void __fastcall TMiRects::BeforeDestruction()
{
  Disconnect();
}

void __fastcall TMiRects::ConnectTo(IMiRectsPtr intf)
{
  Disconnect();
  m_DefaultIntf = intf;
  if (ServerData->EventIID != GUID_NULL)
    ConnectEvents(GetDunk());
}

void __fastcall TMiRects::InitServerData()
{
  static Oleserver::TServerData sd;
  sd.ClassID = CLSID_MiRects;
  sd.IntfIID = __uuidof(IMiRects);
  sd.EventIID= GUID_NULL;
  ServerData = &sd;
}



// *********************************************************************//
// OCX PROXY CLASS IMPLEMENTATION
// (The following variables/methods implement the class TMiDocView which
// allows "" to be hosted in CBuilder IDE/apps).
// *********************************************************************//
int   TMiDocView::EventDispIDs[7] = {
    0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006,
    0x00000007};

TControlData TMiDocView::CControlData =
{
  // GUID of CoClass and Event Interface of Control
  {0xEF347A62, 0xBA21, 0x42E4,{ 0x94, 0xA0, 0x1C,0x0A, 0x6D, 0x7F,0xDF, 0xE7} }, // CoClass
  {0x9028B775, 0xEC59, 0x4118,{ 0x86, 0x2A, 0xEF,0xDE, 0xAF, 0x59,0x55, 0xA4} }, // Events

  // Count of Events and array of their DISPIDs
  7, &EventDispIDs,

  // Pointer to Runtime License string
  NULL,  // HRESULT(0x80004002)

  // Flags for OnChanged PropertyNotification
  0x00000000,
  300,// (IDE Version)

  // Count of Font Prop and array of their DISPIDs
  0, NULL,

  // Count of Pict Prop and array of their DISPIDs
  0, NULL,
  0, // Reserved
  0, // Instance count (used internally)
  0, // List of Enum descriptions (internal)
};

GUID     TMiDocView::DEF_CTL_INTF = {0xF958524A, 0x8422, 0x4B07,{ 0xB6, 0x9E, 0x19,0x9F, 0x24, 0x21,0xED, 0x89} };
TNoParam TMiDocView::OptParam;

static inline void ValidCtrCheck(TMiDocView *)
{
   delete new TMiDocView((TComponent*)(0));
};

void __fastcall TMiDocView::InitControlData()
{
  ControlData = &CControlData;
};

void __fastcall TMiDocView::CreateControl()
{
  if (!m_OCXIntf)
  {
    _ASSERTE(DefaultDispatch);
    DefaultDispatch->QueryInterface(DEF_CTL_INTF, (LPVOID*)&m_OCXIntf);
  }
};

TCOMIMiDocView __fastcall TMiDocView::GetDefaultInterface()
{
  CreateControl();
  return m_OCXIntf;
};

void __fastcall TMiDocView::ClientToDocument(long* plX/*[in,out]*/, long* plY/*[in,out]*/)
{
  GetDefaultInterface()->ClientToDocument(plX/*[in,out]*/, plY/*[in,out]*/);
}

void __fastcall TMiDocView::DocumentToClient(long* plX/*[in,out]*/, long* plY/*[in,out]*/)
{
  GetDefaultInterface()->DocumentToClient(plX/*[in,out]*/, plY/*[in,out]*/);
}

void __fastcall TMiDocView::ClientToImage(long lSX/*[in]*/, long lSY/*[in]*/, long* pnPage/*[out]*/,
                                          long* plX/*[out]*/, long* plY/*[out]*/)
{
  GetDefaultInterface()->ClientToImage(lSX/*[in]*/, lSY/*[in]*/, pnPage/*[out]*/, plX/*[out]*/,
                                       plY/*[out]*/);
}

void __fastcall TMiDocView::ImageToClient(long nPage/*[in]*/, long lX/*[in]*/, long lY/*[in]*/,
                                          long* plSX/*[out]*/, long* plSY/*[out]*/)
{
  GetDefaultInterface()->ImageToClient(nPage/*[in]*/, lX/*[in]*/, lY/*[in]*/, plSX/*[out]*/,
                                       plSY/*[out]*/);
}

void __fastcall TMiDocView::GetVisibleRect(long* Left/*[out]*/, long* Top/*[out]*/,
                                           long* Right/*[out]*/, long* Bottom/*[out]*/)
{
  GetDefaultInterface()->GetVisibleRect(Left/*[out]*/, Top/*[out]*/, Right/*[out]*/, Bottom/*[out]*/);
}

void __fastcall TMiDocView::MoveRectIntoView(long Left/*[in]*/, long Top/*[in]*/, long Right/*[in]*/,
                                             long Bottom/*[in]*/)
{
  GetDefaultInterface()->MoveRectIntoView(Left/*[in]*/, Top/*[in]*/, Right/*[in]*/, Bottom/*[in]*/);
}

void __fastcall TMiDocView::GetScale(double* pdScaleX, double* pdScaleY)
{
  GetDefaultInterface()->GetScale(pdScaleX, pdScaleY);
}

void __fastcall TMiDocView::SetScale(double dScaleX, double dScaleY)
{
  GetDefaultInterface()->SetScale(dScaleX, dScaleY);
}

void __fastcall TMiDocView::SelectAll(long nPage/*[in]*/)
{
  GetDefaultInterface()->SelectAll(nPage/*[in]*/);
}

void __fastcall TMiDocView::MoveSelectionToView(LPDISPATCH pdispSelection)
{
  GetDefaultInterface()->MoveSelectionToView(pdispSelection);
}

LPUNKNOWN __fastcall TMiDocView::get_Document(void)
{
  return GetDefaultInterface()->get_Document();
}

void __fastcall TMiDocView::set_Document(LPUNKNOWN pVal/*[in]*/)
{
  GetDefaultInterface()->set_Document(pVal/*[in]*/);
}

Modi_tlb::IMiSelectableItemPtr __fastcall TMiDocView::get_TextSelection(void)
{
  return GetDefaultInterface()->get_TextSelection();
}

void __fastcall TMiDocView::set_TextSelection(Modi_tlb::IMiSelectableItem* pVal/*[in]*/)
{
  GetDefaultInterface()->set_TextSelection(pVal/*[in]*/);
}

Modi_tlb::IMiSelectableImagePtr __fastcall TMiDocView::get_ImageSelection(void)
{
  return GetDefaultInterface()->get_ImageSelection();
}

void __fastcall TMiDocView::set_ImageSelection(Modi_tlb::IMiSelectableImage* pVal/*[in]*/)
{
  GetDefaultInterface()->set_ImageSelection(pVal/*[in]*/);
}

void __fastcall TMiDocView::set_LayerVisible(Modi_tlb::MiVIEWLAYER Index/*[in]*/,
                                             VARIANT_BOOL pfVisible/*[in]*/)
{
  GetDefaultInterface()->set_LayerVisible(Index/*[in]*/, pfVisible/*[in]*/);
}

TOLEBOOL __fastcall TMiDocView::get_LayerVisible(Modi_tlb::MiVIEWLAYER Index/*[in]*/)
{
  return GetDefaultInterface()->get_LayerVisible(Index/*[in]*/);
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

int __fastcall TMiDocView::First(void)                      //翻到文档第一页
{
  return FFirst(true);
}
int __fastcall TMiDocView::Previous(void)                   //翻到文档上一页
{
  return FPrevious(true);
}
int __fastcall TMiDocView::Next(void)                       //翻到文档下一页
{
  return FNext(true);
}
int __fastcall TMiDocView::Last(void)                       //翻到文档最后一页
{
  return FLast(true);
}
int __fastcall TMiDocView::SlideIndex(int Index)            //翻到文档指定 Index 页   1..N  从 1 开始
{
   return FSlideIndex(Index ,true);
}

int __fastcall TMiDocView::ProcData( TMemoryStream *AData ) //处理 网络 数据
{
  if ((AnsiString)FileName == "") return 0;

  if (AData->Size != sizeof (PrintCntlData)) return 0;
  AData->Position = 0;
  PrintCntlData Data;
  AData->Read( & Data , AData->Size);
  if (Data.CheckKey() == false) return 0;
  if ( Data.CNTR == MSG_INDEX ) {
      if ( Data.BACK <1 ) return 0;
      if ( Data.BACK >NumPages ) return 0;
      if ( Data.BACK != PageNum+1) FSlideIndex(Data.BACK);
      return 1;
  }
  if (Data.CNTR == MSG_SCALE)
  {
    Scale(Data.BACK);
    return 1;
  }
  return 0;

}
int __fastcall TMiDocView::GetNowIndex(void)                //得到当前的 文档页码
{
  //this->SetScale()
  return PageNum+1;
}
void __fastcall TMiDocView::Scale(int Value) //放大缩小  百分数
{
  if ((AnsiString)FileName == ""){
    return;
  }
  FScaleValue = Value;
  SetScale(Value/100.0,Value/100.0);
  DoData(MSG_SCALE ,"Scale",FScaleValue);
}
int __fastcall TMiDocView::GetScale() //放大缩小  百分数
{
  return FScaleValue;
}

void __fastcall TMiDocView::ResetSlideNow(void)
{
  if ((AnsiString)FileName == ""){
    return;
  }
  ProcSendNowSideIndex(NULL);
}
void __fastcall TMiDocView::SetAutoResetSlideTime(DWORD Value)
{
  FAutoResetSlideTime = Value;
  bool B = Timer->Enabled ;
  Timer->Enabled =false;
  Timer->Interval =FAutoResetSlideTime;
  Timer->Enabled = B;
}
void __fastcall TMiDocView::SetAutoResetSlide(bool Value)
{
  FAutoResetSlide = Value;
  Timer->Enabled =Value;
}
bool __fastcall TMiDocView::GetAutoResetSlide()
{
  return Timer->Enabled;
}


void __fastcall TMiDocView::DoData(WORD MSG,AnsiString Result, DWORD BACK)
{
  if (FNeedOnData == false) return;
  PrintCntlData Data;
  Data.SetKey();
  Data.CNTR = MSG;
  Data.BACK = BACK;
  TMemoryStream *Stream = new  TMemoryStream;
  Stream->Write(&Data, sizeof(PrintCntlData));
  Stream->Position = 0;
  try
  {
    if (FOnData)FOnData(this,Stream, Result);
  }catch(...)
  {
  }
  delete  Stream;
}
void __fastcall TMiDocView::ProcSendNowSideIndex(System::TObject* Sender )
{
  if ((AnsiString)FileName == ""){
    return;
  }
  try{
    DoData(MSG_INDEX ,"Timer",PageNum +1);
    DoData(MSG_SCALE ,"Timer",FScaleValue);
  }catch(...)
  {
  }
}

int __fastcall TMiDocView::FFirst(bool NeedOnData)
{
  if ((AnsiString)FileName == "") return 0;
  PageNum = 0;
  if ( NeedOnData )DoData(MSG_INDEX ,"First",PageNum +1);
  return 1;
}
int __fastcall TMiDocView::FPrevious(bool NeedOnData)
{
  if ((AnsiString)FileName == "") return 0;
  if (PageNum ==0) PageNum = NumPages -1;
  else PageNum --;
  if ( NeedOnData )DoData(MSG_INDEX ,"Previous",PageNum +1);
  return 1;
}
int __fastcall TMiDocView::FNext(bool NeedOnData)
{
  if ((AnsiString)FileName == "") return 0;
  if (PageNum == NumPages -1) PageNum = 0;
  else PageNum ++;
  if ( NeedOnData )DoData(MSG_INDEX ,"Next",PageNum +1);
  return 1;
}
int __fastcall TMiDocView::FLast(bool NeedOnData)
{
  if ((AnsiString)FileName == "") return 0;
  PageNum = NumPages -1;
  if ( NeedOnData )DoData(MSG_INDEX ,"Last",PageNum +1);
  return 1;
}
int __fastcall TMiDocView::FSlideIndex(int Index,bool NeedOnData)
{
  if ((AnsiString)FileName == "") return 0;
  PageNum = Index -1;
  if ( NeedOnData )DoData(MSG_INDEX ,"SlideIndex",PageNum +1);
  return 1;
}
//--------------------------------
IMiDocSearchPtr& TMiDocSearch::GetDefaultInterface()
{
  if (!m_DefaultIntf)
    Connect();
  return m_DefaultIntf;
}

_di_IUnknown __fastcall TMiDocSearch::GetDunk()
{
  _di_IUnknown diUnk;
  if (m_DefaultIntf) {
    IUnknownPtr punk = m_DefaultIntf;
    diUnk = LPUNKNOWN(punk);
  }
  return diUnk;
}

void __fastcall TMiDocSearch::Connect()
{
  if (!m_DefaultIntf) {
    _di_IUnknown punk = GetServer();
    m_DefaultIntf = punk;
    if (ServerData->EventIID != GUID_NULL)
      ConnectEvents(GetDunk());
  }
}

void __fastcall TMiDocSearch::Disconnect()
{
  if (m_DefaultIntf) {
    
    if (ServerData->EventIID != GUID_NULL)
      DisconnectEvents(GetDunk());
    m_DefaultIntf.Reset();
  }
}

void __fastcall TMiDocSearch::BeforeDestruction()
{
  Disconnect();
}

void __fastcall TMiDocSearch::ConnectTo(IMiDocSearchPtr intf)
{
  Disconnect();
  m_DefaultIntf = intf;
  if (ServerData->EventIID != GUID_NULL)
    ConnectEvents(GetDunk());
}

void __fastcall TMiDocSearch::InitServerData()
{
  static Oleserver::TServerData sd;
  sd.ClassID = CLSID_MiDocSearch;
  sd.IntfIID = __uuidof(IMiDocSearch);
  sd.EventIID= GUID_NULL;
  ServerData = &sd;
}


};     // namespace Modi_tlb


// *********************************************************************//
// The Register function is invoked by the IDE when this module is 
// installed in a Package. It provides the list of Components (including
// OCXes) implemented by this module. The following implementation
// informs the IDE of the OCX proxy classes implemented here.
// *********************************************************************//
namespace Modi_ocx
{

void __fastcall PACKAGE Register()
{
  // [1]
  TComponentClass cls_ocx[] = {
                              __classid(Modi_tlb::TMiDocView)
                           };
  RegisterComponents("CHL", cls_ocx,
                     sizeof(cls_ocx)/sizeof(cls_ocx[0])-1);
  // [10]
  TComponentClass cls_svr[] = {
                              __classid(Modi_tlb::TDocument), 
                              __classid(Modi_tlb::TLayout), 
                              __classid(Modi_tlb::TMODI_Image), 
                              __classid(Modi_tlb::TWord), 
                              __classid(Modi_tlb::TMiFont), 
                              __classid(Modi_tlb::TWords), 
                              __classid(Modi_tlb::TImages), 
                              __classid(Modi_tlb::TMiRect), 
                              __classid(Modi_tlb::TMiRects), 
                              __classid(Modi_tlb::TMiDocSearch)
                           };
  RegisterComponents("CHL", cls_svr,
                     sizeof(cls_svr)/sizeof(cls_svr[0])-1);
}

};     // namespace Modi_ocx

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -