从零构建自己的远控•客户端设计面向对象(13)
#include <stdio.h> #include <windows.h> class CManager; class CClientSocket { public: void setManagerCallBack(CManager* pManager); CManager* m_pManager; bool Connect();//每一个模块单独创建连接 }; void CClientSocket::setManagerCallBack(CManager* pManager) { m_pManager = pManager; } class CManager { public: CManager(CClientSocket* pClient); CClientSocket* m_pClient; virtual void OnReceive();//不同dlg 进行虚写 }; CManager::CManager(CClientSocket* pClient) { m_pClient = pClient; m_pClient->setManagerCallBack(this); } class CFileManager :public CManager//文件操作模块 { public: CFileManager(CClientSocket* pClient); void OnReceive();//文件操作所有指令 }; CFileManager::CFileManager(CClientSocket* pClient):CManager(pClient) { } void CFileManager::OnReceive() { printf("更具服务器返回指令执行操作"); } void CManager::OnReceive() { } bool CClientSocket::Connect() { m_pManager->OnReceive(); return 0; } int main() {//例子 CClientSocket socketClient; CFileManager manager(&socketClient); socketClient.Connect(); return 0; }
从此山高路远,纵马扬鞭。愿往后旅途,三冬暖,春不寒,天黑有灯,下雨有伞。此生尽兴,不负勇往。