#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;
};
demo 下载:http://download.csdn.net/detail/joneeky/5107849
下载后文件里有三个压缩文件,weixin_scr 是源码,weixin_app 是已经生成的exe文件,weixin_demo 是程序示例。
相信这个demo大家都看得懂,代码很简洁。