⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demo.c

📁 赵应时遥感上机指导envi操作
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <windows.h>#include <stdio.h>#include <stdlib.h>#include <conio.h>#include <ctype.h>#include <string.h>#include "resource.h"#include "index.h"#include "stockrcv.h"#include "fstrcv.h"#include "demo.h"HINSTANCE hInst;HINSTANCE hLibrary;HWND hWnd;HWND hDlg;PAINTSTRUCT ps;RECT	FstInfoRect;RECT	SHNameRect,SZNameRect;RECT	SHListRect,SZListRect;RECT	SHDataRect,SZDataRect;RECT	TotalRect;DWORD IntCounter=0;DWORD FsthWnd=0;DWORD FstMsg=0;DWORD Retval = 0;unsigned long CardNumber=0L;int MsgCounter=0;long Total=0L, Corent=0L;int LineHeight;//---------------------------------------------------------------------------------int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,                     LPSTR lpCmdLine, int nCmdShow){    HWND hWnd;    MSG msg;    WNDCLASS WndClass;    CHAR szAppName[64];	HDC hDC;	TEXTMETRIC TextMetric;	RECT Rect;	static HFONT hfnt, hOldFont;    UNREFERENCED_PARAMETER(lpCmdLine);	UNREFERENCED_PARAMETER(nCmdShow);	WndClass.style = 0;	WndClass.lpfnWndProc = (WNDPROC)DemoWndProc;	WndClass.cbClsExtra = 0;	WndClass.cbWndExtra = 0;	WndClass.hInstance = hInstance;	WndClass.hIcon = LoadIcon(hInstance, "FSTICON");	WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);	WndClass.hbrBackground = GetStockObject(WHITE_BRUSH);	WndClass.lpszMenuName = (LPSTR) "DEMOMENU";	WndClass.lpszClassName = (LPSTR) "Demo";	RegisterClass(&WndClass);	hInst = hInstance;    LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));    hWnd = CreateWindow("Demo", szAppName, WS_OVERLAPPEDWINDOW,						CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,						CW_USEDEFAULT, NULL, NULL, hInstance, NULL);    if (!hWnd)		return (0);    ShowWindow(hWnd, SW_SHOWMAXIMIZED);	UpdateWindow(hWnd);	GetClientRect(hWnd, (LPRECT) &Rect);	hDC = GetDC(hWnd);	if(!hDC)		return FALSE;	GetTextMetrics(hDC, &TextMetric);	LineHeight = TextMetric.tmExternalLeading+TextMetric.tmHeight;    FstInfoRect.top = 0;				// 设定"PC卡信息"文字矩形域.    FstInfoRect.bottom = LineHeight;    FstInfoRect.left = Rect.left;    FstInfoRect.right = Rect.right;    SHNameRect.top = 2*LineHeight;		// 设定"上海证券"文字矩形域.    SHNameRect.bottom = 3*LineHeight;    SHNameRect.left = Rect.left;    SHNameRect.right = Rect.right;    SHListRect.top = 3*LineHeight;		// 设定"显示项目"文字矩形域.    SHListRect.bottom = 4*LineHeight;    SHListRect.left = Rect.left;    SHListRect.right = Rect.right;    SHDataRect.top = 4*LineHeight;		// 设定"数据"文字矩形域.    SHDataRect.bottom = (4+SHMAX)*LineHeight;    SHDataRect.left = Rect.left;    SHDataRect.right = Rect.right;//***********************************************************************************    SZNameRect.top = (5+SHMAX)*LineHeight;		// 设定"深圳证券"文字矩形域.    SZNameRect.bottom = (6+SHMAX)*LineHeight;    SZNameRect.left = Rect.left;    SZNameRect.right = Rect.right;    SZListRect.top = (6+SHMAX)*LineHeight;		// 设定"显示项目"文字矩形域.    SZListRect.bottom = (7+SHMAX)*LineHeight;    SZListRect.left = Rect.left;    SZListRect.right = Rect.right;    SZDataRect.top = (7+SHMAX)*LineHeight;		// 设定"数据"文字矩形域.    SZDataRect.bottom = (7+SHMAX+SZMAX)*LineHeight;    SZDataRect.left = Rect.left;    SZDataRect.right = Rect.right;    TotalRect.top = 24*LineHeight;		// 设定"总报文数"文字矩形域.    TotalRect.bottom = 25*LineHeight;    TotalRect.left = Rect.left;    TotalRect.right = Rect.right;    InvalidateRect(hWnd, &FstInfoRect, TRUE);	// 画提示信息.    InvalidateRect(hWnd, &SHNameRect, TRUE);	// 画提示信息.    InvalidateRect(hWnd, &SHListRect, TRUE);	// 画提示信息.    InvalidateRect(hWnd, &SZNameRect, TRUE);	// 画提示信息.    InvalidateRect(hWnd, &SZListRect, TRUE);	// 画提示信息.	InvalidateRect(hWnd, &TotalRect, TRUE);		// 画提示信息.    while (GetMessage(&msg, NULL, 0, 0))	{        TranslateMessage(&msg);        DispatchMessage(&msg);    }    return (msg.wParam);}//---------------------------------------------------------------------------------LRESULT CALLBACK DemoWndProc(HWND hWnd, UINT message, UINT wParam, LONG lParam){	FARPROC lpFunction;	HDC hDC;	RECT rect;	struct rSTREAMLINE rs;	int i = 1, j=0;	int Factor;	int factor[4]={ 1,10,100,1000 };	unsigned char nunit;	static HFONT hfnt,hOldFont;    switch (message)	{		case WM_CREATE:			hLibrary = LoadLibrary("FstRcv.dll");			if(hLibrary == NULL)				return(FALSE);			FsthWnd=(DWORD)hWnd;			FstMsg=WM_FSTIRQ;			lpFunction = GetProcAddress(hLibrary, "InitRcv");			CardNumber = (* lpFunction)(hWnd, FstMsg);		break;		case WM_PAINT:			hDC=BeginPaint(hWnd,&ps);			hfnt=GetStockObject(ANSI_FIXED_FONT);			SelectObject(hDC,hfnt);			SetTextColor(hDC,RGB(0,63,127));			if(IntersectRect(&rect, &FstInfoRect, &ps.rcPaint));			{				wsprintf(FstInfo,"卡号:%08ld", CardNumber);				TextOut(hDC,FstInfoRect.left,FstInfoRect.top,FstInfo,lstrlen(FstInfo));			}			// 上海证券		  	SetTextColor(hDC,RGB(64,64,128));			if (IntersectRect(&rect, &SHNameRect, &ps.rcPaint))				TextOut(hDC, 0, SHNameRect.top, SHName,lstrlen(SHName));			SetTextColor(hDC,RGB(64,128,64));			if (IntersectRect(&rect, &SHListRect, &ps.rcPaint))				TextOut(hDC, 0, SHListRect.top, SHList,lstrlen(SHList));		  	SetTextColor(hDC,RGB(128,0,128));			if (IntersectRect(&rect, &SHDataRect, &ps.rcPaint))			{				for(i=0;i<SHMAX;i++)					TextOut(hDC, 0, SHDataRect.top+i*LineHeight, SHData[i],lstrlen(SHData[i]));			}						// 深圳证券			SetTextColor(hDC,RGB(64,64,128));			if (IntersectRect(&rect, &SZNameRect, &ps.rcPaint))				TextOut(hDC, 0, SZNameRect.top, SZName,lstrlen(SZName));			SetTextColor(hDC,RGB(64,128,64));			if (IntersectRect(&rect, &SZListRect, &ps.rcPaint))				TextOut(hDC, 0, SZListRect.top, SZList,lstrlen(SZList));			SetTextColor(hDC,RGB(128,0,128));			if (IntersectRect(&rect, &SZDataRect, &ps.rcPaint))			{				for(i=0;i<SZMAX;i++)					TextOut(hDC, 0, SZDataRect.top+i*LineHeight, SZData[i],lstrlen(SZData[i]));			}			sprintf(TotalInfo, "总报文数: %ld,  正确报文数: %ld,  错误报文数: %ld",					Total, Corent, Total - Corent);			TextOut(hDC, TotalRect.left+20, TotalRect.top, TotalInfo, lstrlen(TotalInfo));			lpFunction = GetProcAddress(hLibrary, "CtrlIntr");			(* lpFunction)(1);	       	EndPaint(hWnd, &ps);			break;		case WM_FSTIRQ:			lpFunction = GetProcAddress(hLibrary, "CtrlIntr");			(* lpFunction)(0);			lpFunction = GetProcAddress(hLibrary, "TestResult");			(* lpFunction)(&Total, &Corent);			lpFunction = GetProcAddress(hLibrary, "ReceiveInfo");			MsgCounter = (* lpFunction)();			if(MsgCounter==0)			{				lpFunction = GetProcAddress(hLibrary, "CtrlIntr");				(* lpFunction)(1);				InvalidateRect(hWnd, &TotalRect, FALSE); // 画提示信息.				break;			}			for(i=0; i<MsgCounter; i++)			{				lpFunction = GetProcAddress(hLibrary, "DataAcquisition");				if((* lpFunction)(i, &rs))				{					rs.Info[rs.InfoLength] = 0;					if((rs.Address == 0x12L) && (rs.AL == 2))					{						memmove(uIndex.Str, rs.Info, rs.InfoLength);						if(uIndex.Index.DataType == 0)						{							Factor = uIndex.Index.LineNumber & 0x60;							Factor >>= 5;							uIndex.Index.LineNumber &= 0x1f;							memmove(QL_Index.IndexCode, uIndex.Index.IndexCode, 6);							QL_Index.IndexCode[6] = '\0';							ExpandData(&QL_Index.LastCloseIndex, uIndex.Index.LastCloseIndex, Factor);							ExpandData(&QL_Index.OpenIndex, uIndex.Index.OpenIndex, Factor);							ExpandData(&QL_Index.HighestIndex, uIndex.Index.HighestIndex, Factor);							ExpandData(&QL_Index.LowestIndex, uIndex.Index.LowestIndex, Factor);							ExpandData(&QL_Index.LatestIndex, uIndex.Index.LatestIndex, Factor);							ExpandData(&QL_Index.Volume, uIndex.Index.Volume, 3);							nunit=(uIndex.Index.Unit >> 4) & 0x0f;							for(j=0; j<4; j++)							{								if(nunit & 0x01)								{									QL_Index.Volume *= factor[j];									nunit>>=1;									break;								}							}														ExpandData(&QL_Index.Amount,uIndex.Index.Amount,3);							nunit=(uIndex.Index.Unit) & 0x0f;							for(j=0;j<4;j++)							{								if(nunit&0x01)								{									QL_Index.Amount *= factor[j];									break;								}								nunit>>=1;							}														SHIndex++;							if(SHIndex >= SHMAX) SHIndex=0;							sprintf(SHData[SHIndex],								"%s          %7.2f %7.2f %7.2f %7.2f %7.2f %10ld %10ld",								QL_Index.IndexCode, QL_Index.LastCloseIndex/1000.0, 								QL_Index.OpenIndex/1000.0, QL_Index.HighestIndex/1000.0,								QL_Index.LowestIndex/1000.0, QL_Index.LatestIndex/1000.0,								QL_Index.Volume, QL_Index.Amount);							SHData[SHIndex][100]='\0';						}					}					else if( (rs.Address == 0x13L) && (rs.AL == 2) )					{						memmove(uIndex.Str, rs.Info, rs.InfoLength);						if(uIndex.Index.DataType==0)						{							Factor =uIndex.Index.LineNumber&0x60;							Factor >>=5;							uIndex.Index.LineNumber&=0x1f;							memmove(QL_Index.IndexCode,uIndex.Index.IndexCode,6);							QL_Index.IndexCode[6]='\0';														ExpandData(&QL_Index.LastCloseIndex,uIndex.Index.LastCloseIndex,Factor);							ExpandData(&QL_Index.OpenIndex,uIndex.Index.OpenIndex,Factor);							ExpandData(&QL_Index.HighestIndex,uIndex.Index.HighestIndex,Factor);							ExpandData(&QL_Index.LowestIndex,uIndex.Index.LowestIndex,Factor);							ExpandData(&QL_Index.LatestIndex,uIndex.Index.LatestIndex,Factor);														ExpandData(&QL_Index.Volume,uIndex.Index.Volume,3);							nunit=(uIndex.Index.Unit>>4)&0x0f;							for(j=0;j<4;j++)							{								if(nunit&0x01)								{									QL_Index.Volume *= factor[j];									nunit>>=1;									break;								}							}														ExpandData(&QL_Index.Amount,uIndex.Index.Amount,3);							nunit=(uIndex.Index.Unit)&0x0f;							for(j=0;j<4;j++)							{								if(nunit&0x01)								{									QL_Index.Amount *= factor[j];									break;								}								nunit>>=1;							}														SZIndex++;							if(SZIndex>=SZMAX) SZIndex=0;							sprintf(SZData[SZIndex],								"%s          %7.2f %7.2f %7.2f %7.2f %7.2f %10ld %10ld",								QL_Index.IndexCode, QL_Index.LastCloseIndex/1000.0,								QL_Index.OpenIndex/1000.0, QL_Index.HighestIndex/1000.0,								QL_Index.LowestIndex/1000.0, QL_Index.LatestIndex/1000.0,								QL_Index.Volume, QL_Index.Amount);							SZData[SZIndex][100]='\0';						}					}					else if( (rs.Address == 0x2L) && (rs.AL == 1) )					{						RowNumber = rs.Info[1];						RowNumber <<=8;						RowNumber |= rs.Info[0];												if(RowNumber == 0)	// 指数						{							memmove(IndexStr.str,rs.Info,rs.InfoLength);							PackedIndex = IndexStr.Index;														Index.RowNumber=RowNumber;							Index.TotalRows=PackedIndex.TotalRows;							Index.Date=s3tol(PackedIndex.Date);							Index.Time=s3tol(PackedIndex.Time);							Index.Index=s3tol(PackedIndex.Index);							Index.AIndex=s3tol(PackedIndex.AIndex);							Index.BIndex=s3tol(PackedIndex.BIndex);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -