?? listeningthread.cpp
字號:
// ListeningThread.cpp : implementation file
//
#include "stdafx.h"
#include "MIcqWin32x.h"
#include "ListeningThread.h"
#include "MICQComponents.h"
#include "micq.h"
//#include <winsock2.h>
#include <io.h>
#include <conio.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CListeningThread
IMPLEMENT_DYNCREATE(CListeningThread, CWinThread)
CListeningThread::CListeningThread()
{
}
CListeningThread::~CListeningThread()
{
}
BOOL CListeningThread::InitInstance()
{
// TODO: perform and per-thread initialization here
int time_delay = 120;
struct timeval tv;
fd_set readfds;
// memset( serv_mess, FALSE, 1024 );
int next;
int nextaff;
int pos,apos;
FILE *socksave;
socksave=fopen(".\\socket","w");
fprintf(socksave,"%d",sok);
fclose(socksave);
Login( sok, UIN, passwd, our_ip, our_port, set_status );
next = time( NULL );
nextaff = time(NULL);
nextaff+=40;
next += 60;
LV_COLUMN* col1;
col1= (LV_COLUMN*)malloc(sizeof(LV_COLUMN));
col1->mask=(LVCF_SUBITEM|LVCF_FMT|LVCF_WIDTH|LVCF_TEXT);
col1->fmt=LVCFMT_LEFT;
col1->cx=60;
col1->iSubItem=0;
col1->pszText="Nick";
col1->cchTextMax=4;
statusTab->InsertColumn(0,col1);
LV_COLUMN* col2;
col2= (LV_COLUMN*)malloc(sizeof(LV_COLUMN));
col2->mask=(LVCF_SUBITEM|LVCF_WIDTH|LVCF_TEXT|LVCF_FMT);
col2->fmt=LVCFMT_LEFT;
col2->cx=42;
col2->iSubItem=1;
col2->pszText="Status";
col2->cchTextMax=6;
statusTab->InsertColumn(1,col2);
statusTab->SetTextBkColor(CLR_NONE);
apos=-1;
CList->numContacts=Num_Contacts;
for (int nbc=0; nbc<Num_Contacts; nbc++) {
CList->Nicks[nbc]=Contacts[nbc].nick;
CList->Status[nbc]=Contacts[nbc].status;
CList->UINs[nbc]=Contacts[nbc].uin;
pos=statusTab->InsertItem(apos+1,CList->Nicks[nbc]);
statusTab->SetItemData(pos,CList->UINs[nbc]);
apos=pos;
}
for ( ; !Quit; )
{
tv.tv_sec = 0;
tv.tv_usec = 100000;
FD_ZERO(&readfds);
FD_SET(sok, &readfds);
/* don't care about writefds and exceptfds: */
select (sok+1, &readfds, NULL, NULL, &tv);
if (FD_ISSET(sok, &readfds))
if (!Handle_Server_Response( sok )) {
Quit_ICQ( sok );
Login( sok, UIN, passwd, our_ip, our_port, set_status );
}
/* else if (_kbhit()) /* sorry, this is a bit ugly... [UH]*/
/*
{
Get_Input( sok );
}
/* M_print("Timed out.\n");*/
if ( time( NULL ) > next )
{
next = time( NULL ) + time_delay;
Keep_Alive( sok );
}
if( time (NULL) > nextaff) {
nextaff = time(NULL)+60;
statusTab->DeleteAllItems();
CList->numContacts=Num_Contacts;
// apos=statusTab->InsertItem(0,"--Online--");
apos=-1;
for (int nbc=0; nbc<CList->numContacts; nbc++){
CList->Nicks[nbc]=Contacts[nbc].nick;
CList->Status[nbc]=Contacts[nbc].status;
CList->UINs[nbc]=Contacts[nbc].uin;
if ( CList->Status[nbc] != STATUS_OFFLINE ) {
pos=statusTab->InsertItem(apos+1,CList->Nicks[nbc]);
if ( (CList->Status[nbc] & 0xffff) == STATUS_AWAY ) statusTab->SetItemText(pos,1,"Away");
if ( (CList->Status[nbc] & 0xffff) == STATUS_NA ) statusTab->SetItemText(pos,1,"N/A");
if ( (CList->Status[nbc] & 0xffff) == STATUS_DND ) statusTab->SetItemText(pos,1,"DND");
if ( (CList->Status[nbc] & 0xffff) == STATUS_OCCUPIED ) statusTab->SetItemText(pos,1,"Occ.");
if ( (CList->Status[nbc] & 0xffff) == STATUS_INVISIBLE ) statusTab->SetItemText(pos,1,"Inv.");
statusTab->SetItemData(pos,CList->UINs[nbc]);
apos=pos;
}
}
/* pos=statusTab->InsertItem(apos+1,"");
apos=statusTab->InsertItem(pos+1,"--Offline--");
*/
if (CList->DisplayOffline) {
for (nbc=0; nbc<CList->numContacts; nbc++){
if (CList->Status[nbc]==STATUS_OFFLINE) {
pos=statusTab->InsertItem(apos+1,CList->Nicks[nbc]);
statusTab->SetItemText(pos,1,"Offline");
statusTab->SetItemData(pos,CList->UINs[nbc]);
apos=pos;
}
}
}
}
}
return TRUE;
}
int CListeningThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
Quit_ICQ( sok );
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(CListeningThread, CWinThread)
//{{AFX_MSG_MAP(CListeningThread)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListeningThread message handlers
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -