www.pudn.com > ShowRadarData.rar > ShowRadarData.cpp


//***************************************************************************************************** 
 
 
#include                         //定义头文件 
#include 
#include 
#include 
#include 
#include 
 
 
//***************************************************************************************************** 
 
long WINAPI WndProc(HWND nWnd,UINT iMessage,UINT wParam,LONG lParam); 
BOOL InitWindowsClass(HINSTANCE hInstance);             //为新建一个绘图窗口,定义了一些函数原型  
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow); 
HWND hWndMain; 
 
 
//***************************************************************************************************** 
 
 
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) 
{ 
  MSG Message; 
 
  if(!InitWindowsClass(hInstance)) return FALSE; 
  if(!InitWindows(hInstance,nCmdShow)) return FALSE; 
  while(GetMessage(&Message,0,0,0)) 
  { 
    TranslateMessage(&Message); 
    DispatchMessage(&Message); 
 
  } 
    return Message.wParam; 
} 
 
 
//***************************************************************************************************** 
 
 
long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam) 
{ 
  HDC hDC; 
  HBRUSH hBrush; 
  HPEN hPen;                            //一些句柄和变成的定义我们将在后面的程序里具体作介绍 
  PAINTSTRUCT PtStr; 
                                                  
 
  int x=540,y=185,i,j; 
  SIZE size; 
 
  HFONT holdFont,hnewFont; 
  TEXTMETRIC tm; 
 
  char lp[]="5  dBZ",lp1[]="10",lp2[]="15",lp3[]="20",lp4[]="25",lp5[]="30",lp6[]="35",lp7[]="40",lp8[]="45",lp9[]="50",lp10[]="55",lp11[]="60",lp12[]="65",lp13[]="70",lp14[]="75",p7[]="Date:",p8[]="Time:"; 
  char p1[]="Base Reflectivity",p2[]="Range:",p3[]="Resolution:",p4[]="VCP:",p5[]="Elev: 1.5deg",p6[]="Max:"; 
 
 
//***************************************************************************************************** 
 
 
  switch(iMessage) 
  { 
	case WM_CREATE: 
 
 
	break; 
    case  WM_PAINT: 
 
 
 
    hDC=BeginPaint(hWnd,&PtStr); 
    hPen=CreatePen(PS_DOT,1,RGB(0,0,0)); 
    SelectObject(hDC,hPen); 
    hBrush=(HBRUSH)GetStockObject(BLACK_BRUSH); 
    SelectObject(hDC,hBrush); 
 
 
 
 
 
 
 
 
    unsigned char k,arr[454][454]; 
    long unsigned int d; 
 
//***************************************************************************************************** 
 
 
    FILE *fp;                                     //以只读的方式打开一个文件名为"radardata.dat"的二进制文件,这  
    if((fp=fopen("radardata.dat","rb+"))==NULL)           //个文件就是前面基数据读取程序生成的文件。 
	{ 
      cout<<"读取文件出错!"<=0&&arr[i][j]<76)           //回波强度值小于5dbz的,我们将其衰减为0,用黑色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(0,0,0)); 
	  } 
      if(arr[i][j]>76&&arr[i][j]<=86)         //回波强度值大于5,小于10dbz的,用浅蓝色表示。          
	  { 
		 
      SetPixel(hDC,i,j,RGB(0,230,255)); 
	  } 
 
      if(arr[i][j]>86&&arr[i][j]<=96)         //回波强度值大于10,小于15dbz的,用蓝色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(0,150,255)); 
	  } 
      if(arr[i][j]>96&&arr[i][j]<=106)        //回波强度值大于15,小于20dbz的,用深蓝色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(0,0,255)); 
	  } 
      if(arr[i][j]>106&&arr[i][j]<=116)       //回波强度值大于20,小于25dbz的,用浅绿色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(0,255,0)); 
	  } 
      if(arr[i][j]>116&&arr[i][j]<=126)       //回波强度值大于25,小于30dbz的,用绿色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(0,200,0)); 
	  } 
      if(arr[i][j]>126&&arr[i][j]<=136)       //回波强度值大于30,小于35dbz的,用深绿色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(0,128,0)); 
	  } 
      if(arr[i][j]>136&&arr[i][j]<=146)       //回波强度值大于35,小于40dbz的,用浅黄色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(255,255,0)); 
	  } 
      if(arr[i][j]>146&&arr[i][j]<=156)       //回波强度值大于40,小于45dbz的,用黄色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(220,180,0)); 
	  } 
 
      if(arr[i][j]>156&&arr[i][j]<=166)       //回波强度值大于45,小于50dbz的,用深黄色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(255,180,0)); 
	  } 
      if(arr[i][j]>166&&arr[i][j]<=176)       //回波强度值大于50,小于55dbz的,用红色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(255,0,0)); 
	  } 
      if(arr[i][j]>176&&arr[i][j]<=186)       //回波强度值大于55,小于60dbz的,用棕色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(170,0,0)); 
	  } 
      if(arr[i][j]>186&&arr[i][j]<=196)       //回波强度值大于60,小于65dbz的,用深棕色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(100,0,0)); 
	  } 
      if(arr[i][j]>196&&arr[i][j]<=206)       //回波强度值大于65,小于70dbz的,用紫色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(255,0,255)); 
	  } 
      if(arr[i][j]>206&&arr[i][j]<=216)       //回波强度值大于70,小于75dbz的,用浅紫色表示。 
	  { 
		 
      SetPixel(hDC,i,j,RGB(255,180,255)); 
	  } 
      if(arr[i][j]>216&&arr[i][j]<=255)       //回波强度值大于75dbz的,用白色表示。           
	  { 
		 
      SetPixel(hDC,i,j,RGB(255,255,255)); 
	  } 
 
	} 
 
 
 
//***************************************************************************************************** 
 
                                                //为配合用户观查图像,在回波强度图上给出了一些径向线, 
    for(i=0;i<5;i++)                            //以及一系列以观测站为中心的同心圆,是用点画虚线表示的。 
	{ 
	 
      Arc(hDC,0+i*45,0+i*45,453-i*45,453-i*45,226,226-i*45,226,226-i*45); 
 
	} 
 
      MoveToEx(hDC,0,226,NULL); 
      LineTo(hDC,453,226); 
      MoveToEx(hDC,226,0,NULL); 
      LineTo(hDC,226,453); 
      MoveToEx(hDC,113,34,NULL); 
      LineTo(hDC,339,419); 
      MoveToEx(hDC,34,113,NULL); 
      LineTo(hDC,419,339); 
      MoveToEx(hDC,34,339,NULL); 
      LineTo(hDC,419,113); 
      MoveToEx(hDC,113,419,NULL); 
      LineTo(hDC,339,34); 
      MoveToEx(hDC,454,454,NULL); 
      LineTo(hDC,474,454); 
 
//***************************************************************************************************** 
 
	                                              //为配合用户观查图像,在回波强度图的右边给出了回波强 
DeleteObject(hPen);                               //度彩色条。 
hPen=(HPEN)GetStockObject(BLACK_PEN); 
SelectObject(hDC,hPen); 
Rectangle(hDC,454,0,700,454); 
DeleteObject(hPen); 
 
hBrush=CreateSolidBrush(RGB(0,230,255)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,185,530,200); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(0,150,255)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,200,530,215); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(0,0,255)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,215,530,230); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(0,255,0)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,230,530,245); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(0,200,0)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,245,530,260); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(0,128,0)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,260,530,275); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(255,255,0)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,275,530,290); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(220,180,0)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,290,530,305); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(255,180,0)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,305,530,320); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(255,0,0)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,320,530,335); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(170,0,0)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,335,530,350); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(100,0,0)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,350,530,365); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(255,0,255)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,365,530,380); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(255,180,255)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,380,530,395); 
DeleteObject(hBrush); 
 
hBrush=CreateSolidBrush(RGB(255,255,255)); 
SelectObject(hDC,hBrush); 
Rectangle(hDC,500,395,530,410); 
DeleteObject(hBrush); 
DeleteObject(hBrush); 
 
 
//***************************************************************************************************** 
 
hnewFont=CreateFont(15,0,0,0,200,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH&FF_DONTCARE,"黑体"); 
GetTextMetrics(hDC,&tm); 
SelectObject(hDC,hnewFont); 
 
SetTextColor(hDC,RGB(255,255,255)); 
SetBkColor(hDC,RGB(0,0,0)); 
 
 
TextOut(hDC,x,y,lp,6); 
                                             //在图的右这给出了一些重要的文本信息。 
TextOut(hDC,x,y+15,lp1,2); 
 
TextOut(hDC,x,y+30,lp2,2); 
 
TextOut(hDC,x,y+45,lp3,2); 
 
TextOut(hDC,x,y+60,lp4,2); 
 
TextOut(hDC,x,y+75,lp5,2); 
 
TextOut(hDC,x,y+90,lp6,2); 
 
TextOut(hDC,x,y+105,lp7,2); 
 
TextOut(hDC,x,y+120,lp8,2); 
 
TextOut(hDC,x,y+135,lp9,2); 
 
TextOut(hDC,x,y+150,lp10,2); 
 
TextOut(hDC,x,y+165,lp11,2); 
 
TextOut(hDC,x,y+180,lp12,2); 
 
TextOut(hDC,x,y+195,lp13,2); 
 
TextOut(hDC,x,y+210,lp14,2); 
 
 
TextOut(hDC,500,5,p1,17); 
 
TextOut(hDC,500,20,p2,6); 
 
TextOut(hDC,500,35,p3,11); 
 
TextOut(hDC,500,50,p7,5); 
 
TextOut(hDC,500,65,p8,5); 
 
TextOut(hDC,500,100,p4,4); 
 
TextOut(hDC,500,125,p5,12); 
 
TextOut(hDC,500,150,p6,4); 
 
DeleteObject(hnewFont); 
 
EndPaint(hWnd,&PtStr); 
 
 
 
 
//***************************************************************************************************** 
 
 
 
 
return 0;                               
case  WM_DESTROY: 
	PostQuitMessage(0);                                      //退出窗口。 
	return 0; 
default : 
	return(DefWindowProc(hWnd,iMessage,wParam,lParam)); 
} 
} 
 
 
 
//***************************************************************************************************** 
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow) 
{ 
HWND hWnd; 
hWnd=CreateWindow("WinFill","新一代天气雷达反射率强度显示",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL); 
if(!hWnd)  
return FALSE; 
hWndMain=hWnd; 
 
ShowWindow(hWnd,nCmdShow); 
UpdateWindow(hWnd); 
return TRUE; 
 
} 
 
 
//***************************************************************************************************** 
 
 
BOOL InitWindowsClass(HINSTANCE hInstance)               //窗口类的初始化。 
{ 
WNDCLASS WndClass; 
WndClass.cbClsExtra=0; 
WndClass.cbWndExtra=0; 
WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH)); 
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW); 
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION); 
WndClass.hInstance=hInstance; 
WndClass.lpfnWndProc=WndProc; 
WndClass.lpszClassName="WinFill"; 
WndClass.lpszMenuName=NULL; 
WndClass.style=CS_HREDRAW|CS_VREDRAW; 
return RegisterClass(&WndClass); 
 
} 
 
//*****************************************************************************************************