VC++ 開發PC版微信,CWeixin 類
阿新 • • 發佈:2019-02-15
#define WM_WX_SCANOK (WM_USER + 101) /*掃描成功*/ #define WM_WX_LOGINOK (WM_USER + 102) /*登入成功*/ #define WM_WX_HASMSG (WM_USER + 103) /*收到訊息*/ typedef struct tagWXMSG { CString strName; CString strMsg; } WXMSG; class CWeixin { public: CWeixin(); CWeixin(CWeixin& wxin); ~CWeixin(); void Attach(HWND hWnd); //設定關聯視窗 HGLOBAL GetQRCode(); //得到登入二維碼(記憶體) BOOL GetQRCode(LPCTSTR lpszPath); //得到登入二維碼(檔案) void GotoScan(); //準備掃描 BOOL QueryContacts(); //請求聯絡人列表 int GetContanctsCount(); //得到聯絡人數量 CString GetContanctAt(int nIndex); //得到指定聯絡人 BOOL SendMsg(LPCTSTR lpszContact, LPCTSTR lpszMsg); //傳送文字 BOOL SendImg(LPCTSTR lpszContact, LPCTSTR lpszFilePath); //傳送圖片 private: static UINT CheckScanProc(LPVOID pParam); //檢測二維碼被掃描 static UINT CheckOKProc(LPVOID pParam); //檢測確認登入 static UINT SyncProc(LPVOID pParam); //保持線上狀態(暫時未用到) static UINT CheckMsgProc(LPVOID pParam); //檢測是否有訊息 void UTF8ToGBK(CString& strTarget); //UTF8 轉 GBK void GBKToUTF8(CString& strTarget); //GBK 轉 UTF8 void GetSelfInfo(); //得到自己的資訊 UINT PeekMsg(WXMSG& wxMsg); //取出訊息 private: HWND m_hWnd; CInternetSession *m_pSession; CString m_strCode, m_strSid, m_strSkey; CStringArray m_saContacts; CString m_strMyUin, m_strMyUserName; CString m_strVal1, m_strVal2, m_strVal3; };
下載後文件裡有三個壓縮檔案,weixin_scr 是原始碼,weixin_app 是已經生成的exe檔案,weixin_demo 是程式示例。
相信這個demo大家都看得懂,程式碼很簡潔。