PUBLIC.CPP
资源名称:SNMP范例源代码.zip [点击查看]
上传用户:shgx688
上传日期:2009-12-27
资源大小:855k
文件大小:8k
源码类别:
SNMP编程
开发平台:
MultiPlatform
- //#include "hwt.rh"
- #include "stdafx.h"
- #if !defined(PUBLIC_H)
- #include "public.h"
- #endif
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- Animated::Animated( int numB, char far* name, int delayTics, int endTics ,BOOL isCallIn)
- : WaitingTic(0)
- {
- NumBmps = numB;
- CurBmp = 0;
- Bmps = new (CBitmap(*[NumBmps])); // create array of numB CBitmap*'s
- Stoping = 1;
- DelayTics = delayTics;
- EndTics = endTics;
- IsCallIn = isCallIn;
- // Load in bitmap resources
- //
- for (int j = 0; j < NumBmps; j++) {
- char resName[40];
- sprintf(resName, "%s%d", name ,j+1 );
- Bmps[j] = new CBitmap();
- Bmps[j]->LoadBitmap(resName);
- }
- }
- //
- //
- //
- Animated::~Animated()
- {
- for (int j = 0; j < NumBmps; j++)
- {
- Bmps[j]->DeleteObject();
- delete Bmps[j];
- }
- delete Bmps;
- }
- //
- // Begin to draw the series of bitmaps timed to the timer.
- //
- void
- Animated::DisplayBegin(CDC& dc, int x, int y)
- {
- CurBmp = 0;
- X = x;
- Y = y;
- WaitingTic = 1; // prime the time clock
- Stoping = 0;
- SoundCnt = 0;
- DisplayNext(dc);
- }
- #define SoundDelay 9
- //
- // Draw each of the bitmaps timed to the timer.
- //
- void Animated::DisplayNext(CDC& dc)
- {
- WaitingTic--;
- if (WaitingTic || CurBmp == NumBmps)
- return;
- if(IsCallIn&&
- !(SoundCnt%SoundDelay
- // &&(SoundCnt-1)%(SoundDelay)
- // &&(SoundCnt-2)%(SoundDelay)
- // &&(SoundCnt-3)%(SoundDelay)
- )
- ) {
- // sndPlaySound(0,0);
- // sndPlaySound("home.wav", SND_ASYNC);
- // MessageBeep(0);
- }
- if(IsCallIn)
- SoundCnt = (SoundCnt+1)%SoundDelay;
- CDC dcImage;
- if (!dcImage.CreateCompatibleDC(&dc))
- return;
- BITMAP bm;
- Bmps[CurBmp]->GetBitmap(&bm);
- // Paint the image.
- CBitmap* pOldBitmap = dcImage.SelectObject(Bmps[CurBmp]);
- dc.BitBlt(X, Y, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
- dcImage.SelectObject(pOldBitmap);
- dcImage.DeleteDC();
- if(!EndTics)
- CurBmp = (CurBmp+1)%NumBmps;
- else
- CurBmp = (CurBmp+1);
- WaitingTic = (CurBmp == NumBmps) ? EndTics : DelayTics;
- }
- void
- Animated::Stop(CDC& dc){
- // if(!Stoping)
- {
- CDC dcImage;
- if (!dcImage.CreateCompatibleDC(&dc))
- return;
- BITMAP bm;
- Bmps[NumBmps-1]->GetBitmap(&bm);
- // Paint the image.
- CBitmap* pOldBitmap = dcImage.SelectObject(Bmps[NumBmps-1]);
- dc.BitBlt(X, Y, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
- dcImage.SelectObject(pOldBitmap);
- dcImage.DeleteDC();
- }
- Stoping = 1;
- }
- static CPen BlackPen(PS_SOLID, 1, RGB(0,0,0));
- static CPen DkGrayPen(PS_SOLID, 1, RGB(128,128,128));
- static CPen GrayPen(PS_SOLID, 1, RGB(192,192,192));
- static CPen WhitePen(PS_SOLID, 1, RGB(255,255,255));
- void myrect(CDC& dc,int x1,int y1,int x2,int y2,int type,COLORREF color){
- //return;
- CPen newPen;
- CPen *oldPen;
- switch(type){
- case ColorRect:
- oldPen = dc.SelectObject(&BlackPen);
- // newPen.CreatePen( PS_SOLID, 1,RGB(0,0,0));
- break;
- case DownRect:
- oldPen = dc.SelectObject(&DkGrayPen);
- // newPen.CreatePen( PS_SOLID, 1,RGB(128,128,128));
- break;
- case UpRect:
- oldPen = dc.SelectObject(&WhitePen);
- // newPen.CreatePen( PS_SOLID, 1, RGB(255,255,255));
- break;
- case WhiteRect:
- oldPen = dc.SelectObject(&WhitePen);
- // newPen.CreatePen( PS_SOLID, 1,RGB(255,255,255));
- break;
- case BlackRect:
- oldPen = dc.SelectObject(&BlackPen);
- // newPen.CreatePen( PS_SOLID, 1,RGB(0,0,0));
- break;
- }
- // oldPen = dc.SelectObject(&newPen);
- dc.MoveTo(x2, y1);
- dc.LineTo(x1, y1);
- dc.LineTo(x1, y2+1);
- // newPen.DeleteObject();
- switch(type){
- case ColorRect:
- dc.SelectObject(&WhitePen);
- // newPen.CreatePen( PS_SOLID, 1, RGB(255,255,255));
- break;
- case DownRect:
- dc.SelectObject(&WhitePen);
- // newPen.CreatePen( PS_SOLID, 1, RGB(255,255,255));
- break;
- case UpRect:
- dc.SelectObject(&DkGrayPen);
- // newPen.CreatePen( PS_SOLID, 1, RGB(128,128,128));
- break;
- case WhiteRect:
- dc.SelectObject(&WhitePen);
- // newPen.CreatePen( PS_SOLID, 1,RGB(255,255,255));
- break;
- case BlackRect:
- dc.SelectObject(&BlackPen);
- // newPen.CreatePen( PS_SOLID, 1,RGB(0,0,0));
- break;
- }
- // dc.SelectObject(&newPen);
- dc.MoveTo(x1+1, y2);
- dc.LineTo(x2, y2);
- dc.LineTo(x2, y1);
- // newPen.DeleteObject();
- if(type==ColorRect){
- dc.SelectObject(&WhitePen);
- //// newPen.CreatePen( PS_SOLID, 1,RGB(255,255,255));
- // dc.SelectObject(&newPen);
- dc.MoveTo(x2, y1+1);
- dc.LineTo(x1+1, y1+1);
- dc.LineTo(x1+1, y2);
- // newPen.DeleteObject();
- dc.FillRect(CRect(x1+2,y1+2,x2-1,y2-1),&CBrush(color));//RGB(0,100,100));
- dc.SelectObject(&BlackPen);
- // newPen.CreatePen( PS_SOLID, 1,RGB(0,0,0));
- // dc.SelectObject(&newPen);
- dc.MoveTo(x2-1, y1+1);
- dc.LineTo(x1+1, y1+1);
- dc.LineTo(x1+1, y2-1);
- // newPen.DeleteObject();
- dc.SelectObject(&WhitePen);
- // newPen.CreatePen( PS_SOLID, 1,RGB(255,255,255));
- // dc.SelectObject(&newPen);
- dc.LineTo(x2-1, y2-1);
- dc.LineTo(x2-1, y1+1);
- // newPen.DeleteObject();
- }
- dc.SelectObject(oldPen);
- }
- ////////////////////////////////////////////
- void DrawBMP(CDC& dc, int x, int y, CBitmap& bitmap) //画位图
- {
- CDC dcImage;
- if (!dcImage.CreateCompatibleDC(&dc))
- return;
- BITMAP bm;
- bitmap.GetBitmap(&bm);
- // Paint the image.
- CBitmap* pOldBitmap = dcImage.SelectObject(&bitmap);
- dc.BitBlt(x, y, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
- dcImage.SelectObject(pOldBitmap);
- dcImage.DeleteDC();
- }
- void DrawNum(CDC& dc,char * Num, int x, int y,int len )
- {
- }
- int copyfile(char *sourcefile,char *objectfile)
- {
- return 1;
- }
- void strtodata(int bytelength,CString sourcestr,BYTE * resultbyte)
- {
- // ASSERT(bytelength%2==0);
- int templength=sourcestr.GetLength();
- char* tempstr=sourcestr.GetBuffer(templength);
- char lowbyte[9];
- char highbyte[9];
- char realbyte[18];
- if(templength==0)
- {for(int j=0;j<9;j++)
- resultbyte[j]=0xff;
- }
- else
- {for(int i=0;i<templength;i++)
- realbyte[i]=*(tempstr+i);
- for( i=0;i<bytelength-templength;i++)
- realbyte[templength+i]=0x3f;
- for( i=0;i<bytelength;i+=2)
- lowbyte[i/2]=realbyte[i]-0x30;
- for( i=1;i<bytelength;i+=2)
- highbyte[(i-1)/2]=(realbyte[i]-0x30)<<4;
- for( i=0;i<bytelength/2;i++)
- resultbyte[i]=lowbyte[i]+highbyte[i];
- }
- }
- int asc_BCD(char * sasc ,char * DBCD,int type)
- {
- int i=0;
- char ch,ch1;
- if((type==0xc)||(type==0xd))
- {
- char t_sasc[8];
- int len;
- if(type==0xc)
- {
- len=strlen(sasc);
- t_sasc[0]=0;
- if(len<4)
- {
- for(i=0;i<(4-len);i++) t_sasc[i]='0';
- t_sasc[i]=0;
- }
- strcat(t_sasc,sasc);
- }
- if(type==0xd)
- {
- len=strlen(sasc);
- t_sasc[0]=0;
- if(len<2)
- {
- for(i=0;i<(2-len);i++) t_sasc[i]='0';
- t_sasc[i]=0;
- }
- strcat(t_sasc,sasc);
- }
- for(i=0;(t_sasc[i]!=' ');i++)
- {
- ch=t_sasc[i]-0x30;
- ch1=ch<<4;
- DBCD[i/2]=ch1;
- i++;
- ch1=t_sasc[i];
- if(ch1)
- {
- ch=ch1-0x30;
- DBCD[i/2]|=ch;
- }
- else
- {
- i++;
- break;
- }
- }
- return (i/2);//此处有疑问!!!
- }
- for(i=0;(sasc[i]!=' ');i++)
- {
- ch=sasc[i]-0x30;
- if(!ch) ch=10;
- ch1=ch<<4;
- DBCD[i/2]=ch1;
- i++;
- ch1=sasc[i];
- if(ch1)
- {
- ch=ch1-0x30;
- if(!ch) ch=10;
- DBCD[i/2]|=ch;
- }
- else
- {
- i++;
- break;
- }
- }
- return (i/2);//此处有疑问!!!
- }
- int asc_bin(char * sasc, char * DBCD)
- {
- int i;
- char ch,ch1;
- for(i=0;sasc[i]!=' ';i++)
- {
- ch=sasc[i];
- if((ch>='0')&&(ch<='9')) ch1=ch-'0';
- if((ch>='a')&&(ch<='z')) ch1=ch-'a'+0xa;
- if((ch>='A')&&(ch<='Z')) ch1=ch-'A'+0xa;
- ch1=ch1<<4;
- DBCD[i/2]=ch1;
- i++;
- ch=sasc[i];
- if(ch)
- {
- if((ch>='0')&&(ch<='9')) ch1=ch-'0';
- if((ch>='a')&&(ch<='z')) ch1=ch-'a'+0xa;
- if((ch>='A')&&(ch<='Z')) ch1=ch-'A'+0xa;
- DBCD[i/2]|=ch1;
- }
- }
- i=strlen(sasc);
- if(i%2) return(i/2+1);
- else return (i/2);
- }