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

📄 myproject.cpp

📁 采用Platform Builder编写的多线程程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
					  SAFE_DeleteDC(g_hdc[6]);//释放设备环境 
					  
					  g_hdc[0]=g_hdc[4];
					  g_hdc[4]=g_hdc[8];
					  g_hdc[1]=g_hdc[5];
					  g_hdc[3]=g_hdc[7];

					  g_hdc[2]=NULL;
					  g_hdc[5]=NULL;
					  g_hdc[6]=NULL;
					  g_hdc[7]=NULL;
					  g_hdc[8]=NULL;
	}
	//(9)左下图变为目标图
	if (new_intXnumth==intXnumth-1  && new_intYnumth==intYnumth-1)
	{
			  //1.目标图变化,
		         intXnumth=new_intXnumth;
				 intYnumth=new_intYnumth;
                 pic.left = intXnumth * picWidth;
                 pic.bottom = intYnumth * picHeight;
                 pic.right = pic.left + picWidth;
                 pic.top = pic.bottom + picHeight;
			  //2.修改box的位置
			      box.top = Center.y + PicBoxHeight/2;
                  box.bottom = Center.y - PicBoxHeight/2;
                  box.left = Center.x - PicBoxWidth/2;
                  box.right = Center.x + PicBoxWidth/2;
			  //3.重新分配其相应的设备环境
					  SAFE_DeleteDC(g_hdc[0]);//释放设备环境 
					  SAFE_DeleteDC(g_hdc[5]);//释放设备环境 
					  SAFE_DeleteDC(g_hdc[1]);//释放设备环境 
					  SAFE_DeleteDC(g_hdc[2]);//释放设备环境 
					  SAFE_DeleteDC(g_hdc[8]);//释放设备环境 
					  
					  g_hdc[2]=g_hdc[4];
					  g_hdc[4]=g_hdc[6];
					  g_hdc[1]=g_hdc[3];
					  g_hdc[5]=g_hdc[7];

					  g_hdc[0]=NULL;
					  g_hdc[3]=NULL;
					  g_hdc[6]=NULL;
					  g_hdc[7]=NULL;
					  g_hdc[8]=NULL;
	}
*/
}


////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////            以下为系统初始化(开机)   专用         //////////////////////////////////////////////////

//1.调用初始化函数  foninitial
void  OnInitial(void)
{
    /////////////////////////////////////////////////////////  

        //1.读取默认海图的  缺省参数
        CIni Ini(haituINI,LPhaituINI);
        	
		char* MapName_char; 
        MapName_char=new char[10];
		  //初始化变量, data和name
        Ini.ReadData("默认海图","海图");
        MapName_char=Ini.data;

	    //单幅图像的经纬度间隔
        double x=Ini.ReadData(MapName_char,"屏幕经度"); 
	   if(x>=100)
	   {
          int y=(int)(x/100);
	          x=y*60+x-y*100;
	   }
       PicJingDuGap=x;//(单位:分)单幅图像的经度宽度
       
	   x=Ini.ReadData(MapName_char,"屏幕纬度"); 
	   if(x>=100)
	   {
          int y=(int)(x/100);
	          x=y*60+x-y*100;
	   }
       PicWeiDuGap=x;//(单位:分)单幅图像的纬度宽度

		

       //图像左下角的经纬度
       x=Ini.ReadData(MapName_char,"左经度"); 
	   if(x>=100)
	   {
          int y=(int)(x/100);
	          x=y*60+x-y*100;
	   }
       LeftJingDu=x;//(单位:分)

	   x=Ini.ReadData(MapName_char,"下纬度");
	   if(x>=100)
	   {
          int y=(int)(x/100);
	          x=y*60+x-y*100;
	   }
       BottomWeiDu=x;//(单位:分)

 	   //检测正确  
	   //printf("LeftJingDu=%f   ,BottomWeiDu=%f  ,PicJingDuGap=%f  ,PicWeiDuGap=%f",
	   //	   LeftJingDu,BottomWeiDu,PicJingDuGap, PicWeiDuGap);





    StrPicName0=new TCHAR[40];//分配内存
//Center.x,Center.y在GPS线程内采集
/////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////	
///////////////////////////////////////////////////////////////////////////////////
	while(Center.x==0 && Center.y==0) {Sleep(25);}//如果GPS没有采集到信号则等待片刻 25 毫秒    

	
//	RePicAndBoxPosition(Center);//确定PIC和Box的位置
//	ReNotLoadBoxPosition(Center,pic);//根据目标点在Pic的位置(左上、右上、右下、左下)  确定NotLoadBox的位置

//	intXnumth = Center.x/picWidth;//取整
//    intYnumth = Center.y/picHeight;
//	intXnumth++;intYnumth++;//左下角的文件名是01001

	SAFE_ReleaseDC(hwndMain,hdc);
	hdc = ::GetDC(hwndMain);//目标设备环境的句柄
 
	InitLoadPic(Center);//根据Center.x,Center.y确定调入的4幅图 	
	g_hdc6=g_hdc[6]; g_hdc7=g_hdc[7]; g_hdc11=g_hdc[11]; g_hdc10=g_hdc[10];
    
	   // Adjust the size of the client rect to take into account
       // the command bar height.
	   GetClientRect(hwndMain,&rect);
       rect.top+=CommandBar_Height(GetDlgItem(hwndMain,IDC_CMDBAR));
	   rect.right=rect.left+PicBoxWidth;// picbox宽
	   rect.bottom=rect.top+PicBoxHeight;//picbox高

	InvalidateRect(hwndMain,&rect,true);//重画屏幕
 
 
   /*
        Ini.ReadData(MapName_char,"缺省经度"); 
	    int a=(int)(atoi(Ini.data)/100);
        double b=(atof(Ini.data)/100-a)/0.6;
        Center.x=a+b;//此时Center.x单位为:度 例如 缺省经度=12830,则为128.5度
		Center.x= (Center.x-LeftJingDu)*picWidth/PicJingDuGap;//单位:象素点  转换为象素点位置

       Ini.ReadData(MapName_char,"缺省纬度");
       a=(int)(atoi(Ini.data)/100);
       b=(atof(Ini.data)/100-a)/0.6;
       Center.y=a+b;
	   Center.y=(TopWeiDu-Center.y)*picHeight/PicWeiDuGap;//单位:象素点   转换为象素点位置

       */




   
    /*

  
   Ini.ReadData(MapName_char,"目录");
   str=Ini.data;
   Ini.ReadData(MapName_char,"文件名前缀");
   str=strcat(str,Ini.data);

    TCHAR*  MapPath0;  
    //返回实际需要的MapName_TCHAR缓冲区的大小
   int k=MultiByteToWideChar(CP_ACP,0,str,-1,MapPath0,0);;
   MultiByteToWideChar(CP_ACP,0,str,-1,MapPath0,k);
   MapPath=lpstrcat(MapPath,MapPath0));//     到此的路径为\\My Documents\\HT100Y\\100xNameyName


  
  
    */
    //注:用完后的指针变量要free()释放掉。
//    SAFE_FREE(MapName_char);


}



//////////fReadGPSSerialThread  以下为系统开机时读取GPS串口数据的线程
DWORD WINAPI  ReadGPSSerialThread(PVOID pArg) 
{
	//now
	//ReadCom1;
     Center.x=1390;
	 Center.y=710;
     while(1)
	 {
		 //Center.x=900;
	     //Center.y=680;
		 Sleep(2000);//read serial every two minutes;
		 //sleep

		 	InvalidateRect(hwndMain,&rect,true);//重画屏幕
	 }

	   // ExitThread(0x15);return 0x15;
}


///fInitLoadPic  
void InitLoadPic(POINT Center)
{ 

	//
	 
	RePicAndBoxPosition(Center);//确定PIC和Box的位置
	ReNotLoadBoxPosition(Center,pic);//根据目标点在Pic的位置(左上、右上、右下、左下)  确定NotLoadBox的位置

	int intXnumth = Center.x/picWidth;//取整
    int intYnumth = Center.y/picHeight;
	intXnumth++;intYnumth++;//左下角的文件名是01001

	//注:按左上、右上、右下、左下的顺序,先占到的边先取等号 (>= <=)
	switch(WhereIsCenterAtPic(Center,pic)) 
	{
	   case 1:   //第一种情况   目标在目标图的左上部分
	       //目标图
		   MakePicName(intXnumth,intYnumth,0,0); LoadPicToHdc_i(hdc, StrPicName0,11);
		   
		   //邻接图 (顺时针)
		   MakePicName(intXnumth,intYnumth,-1,0); LoadPicToHdc_i(hdc, StrPicName0,10);
		   MakePicName(intXnumth,intYnumth,-1,1); LoadPicToHdc_i(hdc, StrPicName0,6);
		   MakePicName(intXnumth,intYnumth,0,1); LoadPicToHdc_i(hdc, StrPicName0,7);   
	       break;
	   case 2:   //第二种情况   目标在目标图的右上部分
           //目标图
		   MakePicName(intXnumth,intYnumth,0,0);  LoadPicToHdc_i(hdc, StrPicName0,10);
		   
		   //邻接图 (顺时针)
		   MakePicName(intXnumth,intYnumth,0,1);  LoadPicToHdc_i(hdc, StrPicName0,6);
		   MakePicName(intXnumth,intYnumth,1,1);  LoadPicToHdc_i(hdc, StrPicName0,7);
		   MakePicName(intXnumth,intYnumth,1,0);  LoadPicToHdc_i(hdc, StrPicName0,11);     	
           break;
	   case 3:   //第三种情况   目标在目标图的右下部
           //目标图
		   MakePicName(intXnumth,intYnumth,0,0);  LoadPicToHdc_i(hdc, StrPicName0,6);
		   
		   //邻接图 (顺时针)
		   MakePicName(intXnumth,intYnumth,1,0);  LoadPicToHdc_i(hdc, StrPicName0,7);
		   MakePicName(intXnumth,intYnumth,1,-1);  LoadPicToHdc_i(hdc, StrPicName0,11);
		   MakePicName(intXnumth,intYnumth,0,-1);  LoadPicToHdc_i(hdc, StrPicName0,10);      	
           break;
	   case 4:     //第四种情况   目标在目标图的左下部
          //目标图
		   MakePicName(intXnumth,intYnumth,0,0);  LoadPicToHdc_i(hdc, StrPicName0,7);
		   
		   //邻接图 (顺时针)
		   MakePicName(intXnumth,intYnumth,0,-1);  LoadPicToHdc_i(hdc, StrPicName0,11);
		   MakePicName(intXnumth,intYnumth,-1,-1);  LoadPicToHdc_i(hdc, StrPicName0,10);
		   MakePicName(intXnumth,intYnumth,-1,0);  LoadPicToHdc_i(hdc, StrPicName0,6);     	
           break;
	}
}
///////    以上为开机初始化时调入图像的函数 和线程   ///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

//------------fOnDraw()绘图函数---------------------
void OnDraw(HDC hdc)
{
	/*
	int width,height;
	//按hdc6 7 11 10顺序
    if(Cross.x>box.right){ width=PicBoxWidth;}else{width=Cross.x-box.left;}
	//if(box.top>Cross.y){ height=PicBoxHeight;}else{height=box.top-Cross.y;}
	if(box.bottom>Cross.y){ height=PicBoxHeight;}else{height=box.top-Cross.y;}
	BitBlt(hdc, 0, rect.top,  width , height ,   g_hdc6, picWidth-(Cross.x-box.left) ,  picHeight-(box.top-Cross.y) ,SRCCOPY );					
		

	if(box.left>Cross.x) {width=PicBoxWidth;}else{width=box.right-Cross.x;}
	if(box.bottom>Cross.y) {height=PicBoxHeight;}else{height=box.top-Cross.y; }
	BitBlt(hdc, Cross.x-box.left, rect.top,  width,  height , g_hdc7, 0 , picHeight-(box.top-Cross.y) ,SRCCOPY );			
	


	if(box.left>Cross.x){width=PicBoxWidth;}else{width=box.right-Cross.x; }
	if(box.top<Cross.y){height=PicBoxHeight;}else{height=Cross.y-box.bottom; }
	BitBlt(hdc, Cross.x-box.left, rect.top+box.top-Cross.y, width ,  height ,  g_hdc11, 0 , 0 ,SRCCOPY ); 			
	

/////
    if(box.right<Cross.x){width=PicBoxWidth;}else{width=Cross.x-box.left; }
	if(box.top<Cross.y){height=PicBoxHeight;}else{height=Cross.y-box.bottom;}
	BitBlt(hdc,  0 , rect.top+box.top-Cross.y , width, height , g_hdc10, picWidth-(Cross.x-box.left) , 0 ,SRCCOPY );    
*/

	//   6 7 11 10顺序
	if(Cross.x<box.left)   //左部
	{
		if(Cross.y<box.bottom )//上
		{
			BitBlt(hdc,  0 , rect.top, PicBoxWidth, PicBoxHeight , g_hdc7, box.left-Cross.x , Cross.y+picHeight-box.top ,SRCCOPY );    
		}
		else if(Cross.y>=box.bottom && Cross.y<=box.top)//中
		{ 
			BitBlt(hdc,  0 , rect.top , PicBoxWidth , box.top-Cross.y , g_hdc7, box.left-Cross.x , Cross.y+picHeight-box.top,SRCCOPY );    	
			BitBlt(hdc,  0 , rect.top+box.top-Cross.y , PicBoxWidth, Cross.y-box.bottom , g_hdc11, box.left-Cross.x , 0 ,SRCCOPY );    
		}
		else //下
		{
			BitBlt(hdc,  0 , rect.top , PicBoxWidth, PicBoxHeight , g_hdc11, box.left-Cross.x , Cross.y-box.top ,SRCCOPY );    
		}
	}//if(Cross.x<box.left)   //左结束

	else if(Cross.x>=box.left && Cross.x<=box.right)//中部
	{
		if(Cross.y<box.bottom )//上
		{
			BitBlt(hdc,  0 , rect.top, Cross.x-box.left , PicBoxHeight , g_hdc6, box.left-(Cross.x-picWidth) , Cross.y+picHeight-box.top ,SRCCOPY );    
			BitBlt(hdc,  Cross.x-box.left , rect.top, box.right-Cross.x , PicBoxHeight , g_hdc7, 0 , Cross.y+picHeight-box.top ,SRCCOPY );    
	
		}
		else if(Cross.y>=box.bottom && Cross.y<=box.top)//中
		{ 
			BitBlt(hdc,  0 , rect.top , Cross.x-box.left , box.top-Cross.y , g_hdc6, box.left-(Cross.x-picWidth) , Cross.y+picHeight-box.top,SRCCOPY );    				
			BitBlt(hdc,  Cross.x-box.left , rect.top , box.right-Cross.x, box.top-Cross.y , g_hdc7, 0 , Cross.y+picHeight-box.top ,SRCCOPY );    
 
			BitBlt(hdc,  Cross.x-box.left , rect.top+box.top-Cross.y , box.right-Cross.x , Cross.y-box.bottom , g_hdc11, 0 , 0 ,SRCCOPY );    	

			BitBlt(hdc,  0 , rect.top+box.top-Cross.y , Cross.x-box.left , Cross.y-box.bottom , g_hdc10, box.left-(Cross.x-picWidth) , 0 ,SRCCOPY );    
		    
		}
		else //下
		{
			BitBlt(hdc,  0 , rect.top , Cross.x-box.left , PicBoxHeight , g_hdc10, box.left-(Cross.x-picWidth) , Cross.y-box.top ,SRCCOPY );    
		    BitBlt(hdc,  Cross.x-box.left , rect.top , box.right-Cross.x , PicBoxHeight , g_hdc11, 0 , Cross.y-box.top ,SRCCOPY );    		    
		}
	}
	else //右部
	{
		if(Cross.y<box.bottom )//上
		{
			BitBlt(hdc,  0 , rect.top, PicBoxWidth, PicBoxHeight , g_hdc6, box.left-(Cross.x-picWidth) , Cross.y+picHeight-box.top ,SRCCOPY );    
		}
		else if(Cross.y>=box.bottom && Cross.y<=box.top)//中
		{ 
			BitBlt(hdc,  0 , rect.top , PicBoxWidth , box.top-Cross.y , g_hdc6, box.left-(Cross.x-picWidth) , Cross.y+picHeight-box.top,SRCCOPY );    	
			BitBlt(hdc,  0 , rect.top+box.top-Cross.y , PicBoxWidth, Cross.y-box.bottom , g_hdc10, box.left-(Cross.x-picWidth) , 0 ,SRCCOPY );    
		}
		else //下
		{
			BitBlt(hdc,  0 , rect.top , PicBoxWidth, PicBoxHeight , g_hdc10, box.left-(Cross.x-picWidth) , Cross.y-box.top ,SRCCOPY );    
		}

	}
	


  }

⌨️ 快捷键说明

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