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

📄 myproject.cpp

📁 采用Platform Builder编写的多线程程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
      DialogProc_DefLocSet);   // Pointer to the dialog box procedure.


   //以下三句将从对话框送回的 TCHAR数据转换为 char 类型
  //k=WideCharToMultiByte(CP_ACP,0,MapName_TCHAR,-1,MapName_char,0,NULL,NULL);
  WideCharToMultiByte(CP_ACP,0,MapName_TCHAR,-1,MapName_char,128,NULL,NULL);


 // k=WideCharToMultiByte(CP_ACP,0,JingDu_TCHAR,-1,JingDu_char,0,NULL,NULL);
  WideCharToMultiByte(CP_ACP,0,JingDu_TCHAR,-1,JingDu_char,128,NULL,NULL);

  // k=WideCharToMultiByte(CP_ACP,0,JingDu_TCHAR,-1,WeiDu_char,0,NULL,NULL);
  WideCharToMultiByte(CP_ACP,0,WeiDu_TCHAR,-1,WeiDu_char,128,NULL,NULL);

 
  //以下保存数据到INI文件
  Ini.Write(MapName_char,"缺省经度",JingDu_char);
  Ini.Write(MapName_char,"缺省纬度",WeiDu_char);
  Ini.Save();
  Ini.~CIni();
 

  //以下用于检验
  //double jingdu=Ini.ReadData(MapName_char,"缺省经度");
  //double weidu=Ini.ReadData(MapName_char,"缺省纬度");
  //printf("缺省地图=%s\n",MapName_char);
  //printf("缺省纬度=%f\n",weidu);
  //printf("缺省经度=%f\n",jingdu);


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

   SAFE_FREE(MapName_TCHAR);
   SAFE_FREE(JingDu_TCHAR);
   SAFE_FREE(WeiDu_TCHAR);

   
    return 0;
}

//      以上自定义菜单响应函数,用于响应自己工程的菜单。//
//      自定义菜单响应函数结束+++++//
//------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------
//           以下是  对话框过程函数
//

//No1.  初始位置设置
BOOL CALLBACK DialogProc_DefLocSet (
                    HWND hwndDlg,   // Handle to the dialog box.
                    UINT uMsg,      // Message.
                    WPARAM wParam,  // First message parameter.
                    LPARAM lParam)  // Second message parameter.
{
  switch(uMsg)
  {
    case WM_INITDIALOG:
      // Insert code here to put the string (to find and replace with)
      // into the edit controls.
      // ...
	  //SetDlgItemText(hwndDlg,IDC_MapName,a_tchar);
	//	MAKEINTRESOURCE(i)
       SetDlgItemText(hwndDlg,IDC_MapName,MapName_TCHAR);
        
	   SetDlgItemText(hwndDlg,IDC_EditDefJingDu,JingDu_TCHAR);

       SetDlgItemText(hwndDlg,IDC_EditDefWeiDu,WeiDu_TCHAR);

       SetDlgItemText(hwndDlg,IDC_EditTest,a_tchar);




      return TRUE;  

    case WM_COMMAND:
      switch (LOWORD(wParam))
      {
        //case IDC_BTNFINDNEXT:
          // Insert code here to handle the case of pushing the
          // "Find Next" button.
          // ...
          //break;

        //case IDC_BTNREPLACE:
          // Insert code here to handle the case of pushing the
          // "Replace" button.
          // ...
          //break;

        //case IDC_BTNREPLACEALL:
          // Insert code here to handle the case of pushing the
          // "Replace All" button.
          // ...
         // break;
	    case  IDOK:

			//注:100为返回的数据字节,不能太小,若太小,则出现没有全部返回的现象。
            //不能用sizeof(MapName_TCHAR),因为sizeof(MapName_TCHAR)=4
			GetDlgItemText(hwndDlg,IDC_MapName,MapName_TCHAR,100);

			GetDlgItemText(hwndDlg,IDC_EditDefJingDu,JingDu_TCHAR,100);

			GetDlgItemText(hwndDlg,IDC_EditDefWeiDu,WeiDu_TCHAR,100);

        case IDCANCEL:
          EndDialog(hwndDlg, 0);
          break;
      }
      return TRUE;
  }
  return FALSE;
}





//                                      -
//                 以上对话框过程函数  结束
//-------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////





////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------
//           以下为自定义函数(非菜单响应函数)
//
 



//------------------------------------------------------------------------
//------------------------------------------------------------------------
 LPARAM DoMainCommandMoveTest (HWND hWnd, WORD idItem, HWND hwndCtl,
                             WORD wNotifyCode)
 {
	 int i;
	 for(i=0;i<=5;i++)
	 {
		 Center.x=i*10;
		 Center.y=i*10;
	  SendMessage (hWnd, WM_PAINT, 0, 0);
	 }
	  return 0;
 }

///////////////////////////////////////////////////////////////////////////////////////////////////
//
//          以下为  文件名路径处理函数   
//-----fintbittotchar--------
TCHAR*  IntBitToTCHAR(int i)  //把单个位的数转换为字符
{	 
	TCHAR* tch=new TCHAR[2];
	
	  switch(i)
	  {
		case 0:
           lstrcpy(tch,TEXT("0"));break;
		case 1:
           lstrcpy(tch,TEXT("1"));break;
		case 2:
           lstrcpy(tch,TEXT("2"));break;
		case 3:
           lstrcpy(tch,TEXT("3"));break;
		case 4:
           lstrcpy(tch,TEXT("4"));break;
		case 5:
           lstrcpy(tch,TEXT("5"));break;
		case 6:
           lstrcpy(tch,TEXT("6"));break;
		case 7:
           lstrcpy(tch,TEXT("7"));break;
		case 8:
           lstrcpy(tch,TEXT("8"));break;
		case 9:
           lstrcpy(tch,TEXT("9"));break;
	  }

	  return  tch;  
}


//fintToTCHAR
TCHAR*  intToTCHAR(int m,int bitsnumtag)// 该函数最多可以将三位的整数转换为字符串
                                     //bitsnumtag=2时为xName,=3时为yName
{
	TCHAR* lpstr=new TCHAR[5];
	int p;
	
	// 1
	if(m>=0  &&  m<10)
	{
		switch(bitsnumtag)
		{
		   case 2:     //xName
			    lstrcpy(lpstr,TEXT("0"));//十位补 0
		        lstrcat(lpstr , IntBitToTCHAR(m));//个位
				break;
		   case 3:     //yName
                lstrcpy(lpstr,TEXT("00"));//百位、十位补 0
		        lstrcat(lpstr , IntBitToTCHAR(m));//个位
				break;
		}		
	}

	//2
    if(m<100 && m>=10)
	{

		switch(bitsnumtag)
		{
		   case 2:
				p = m/10;
	        	lstrcpy(lpstr , IntBitToTCHAR(p));//十位
                m = m - p*10;
		        lstrcat(lpstr , IntBitToTCHAR(m));//个位
				break;
		   case 3:
                lstrcpy(lpstr , TEXT("0"));//百位补 0
				p = m/10;
	        	lstrcat(lpstr , IntBitToTCHAR(p));//十位
                m = m - p*10;
		        lstrcat(lpstr , IntBitToTCHAR(m));//个位
				break;
		}
	    
	}

	//3
    if(m>=100 && m<1000)
	{
	    p= m/100;
		lstrcpy(lpstr , IntBitToTCHAR(p));//百位
		m = m - p*100;
		p = m/10;
		lstrcat(lpstr , IntBitToTCHAR(p));//十位
        m = m - p*10;
		lstrcat(lpstr , IntBitToTCHAR(m));//个位
	}
    

	return lpstr; 
	      
}

//                   以上是  文件名路径处理函数                        
////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------fLoadPicToHdc_i      以下为JPEG解压为BMP图像    --------------------------------
//BOOL LoadPicToHdc_i(HDC hdc, LPCTSTR pcszFileName, int hdc_i)
BOOL LoadPicToHdc_i(HDC hdc, LPCTSTR pcszFileName, int hdc_i)
{


     ///////////    i为设备内存的标号
                SAFE_DeleteObject(m_hbitmap);//可以不用,因为本函数结尾已经DeleteObject
                SAFE_DeleteDC(g_hdc[hdc_i])
	            g_hdc[hdc_i] = CreateCompatibleDC(hdc);//Create memory DC to hold Bitmap 	    
				//while(g_hdc[hdc_i]==NULL) { g_hdc[hdc_i] =NULL; g_hdc[hdc_i] = CreateCompatibleDC(hdc); }
				if(g_hdc[hdc_i]==NULL) { wsprintf(L"%s",TEXT("调图时,分配内存失败!")); }
				
	//////////////////////
 
//

	if(PicType==1)//bmp
	{

//		while(m_hbitmap==NULL) //以防  调图没成功
//		{
		   m_hbitmap=SHLoadDIBitmap(pcszFileName); if(m_hbitmap==NULL) {SAFE_DeleteObject(m_hbitmap);  m_hbitmap=SHLoadDIBitmap(pcszFileName); }



		   if(m_hbitmap==NULL) {SAFE_DeleteObject(m_hbitmap);  m_hbitmap=SHLoadDIBitmap(BLKMapName1); }

           if(m_hbitmap==NULL) {SAFE_DeleteObject(m_hbitmap); m_hbitmap=SHLoadDIBitmap(BLKMapName2); }
            
	        // while(m_hbitmap==NULL) { m_hbitmap=SHLoadDIBitmap(BLKMapName); }
	       
			 if(m_hbitmap==NULL) {  wprintf(L"%s",TEXT("调图失败!") );} 
			 
			 SelectObject(g_hdc[hdc_i],m_hbitmap);
            

		   // Clean up
		   //SAFE_DeleteObject(m_hbitmap);//此句用于删除内存变量指针,因为位图选入设备环境后,指针的使命已经结束。
//		}
	}

  
	else if(PicType==2)//jpg
	{
  
	HRESULT hr;
	BYTE    szBuffer[4096] = {0};  //缓冲大小1K 
	HANDLE hFile = INVALID_HANDLE_VALUE;

	DecompressImageInfo	dii;

	hFile = CreateFile(pcszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if (hFile == INVALID_HANDLE_VALUE)
		return FALSE;

	// Fill in the 'DecompressImageInfo' structure
	dii.dwSize = sizeof( DecompressImageInfo );		// Size of this structure
	dii.pbBuffer = szBuffer;						// Pointer to the buffer to use for data
	dii.dwBufferMax = 4096;							// Size of the buffer
	dii.dwBufferCurrent = 0;						// The amount of data which is current in the buffer

	//////////////////////
	     dii.phBM = &m_hbitmap;						// Pointer to the bitmap returned (can be NULL)
	     dii.hdc = g_hdc[hdc_i];								// HDC to use for retrieving palettes
    ///////////////////////
	
	dii.ppImageRender = NULL;						// Pointer to an IImageRender object (can be NULL)
	dii.iBitDepth = 8;//GetDeviceCaps(hdc,BITSPIXEL);	// Bit depth of the output image
	dii.lParam = ( LPARAM ) hFile;					// User parameter for callback functions
	     dii.iScale =100;   //= g_iScale;							// Scale factor (1 - 100)
	     dii.iMaxWidth =1000;  //= g_iMaxWidth;					// Maximum width of the output image
	     dii.iMaxHeight =1000;  //= g_iMaxHeight;					// Maxumum height of the output image
	dii.pfnGetData = GetImageData;					// Callback function to get image data
	dii.pfnImageProgress = ImageProgress;			// Callback function to notify caller of progress decoding the image
	dii.crTransparentOverride = ( UINT ) -1;		// If this color is not (UINT)-1, it will override the


	// transparent color in the image with this color. (GIF ONLY)    
	 // Process and decompress the image data
	 hr = DecompressImageIndirect( &dii );

     SelectObject(g_hdc[hdc_i], m_hbitmap);//Get the bitmap into the compatible device context

	 // Clean up
	 SAFE_DeleteObject(m_hbitmap);//此句用于删除内存变量指针,因为位图选入设备环境后,指针的使命已经结束。
	 CloseHandle( hFile );
	}//jpg


	 return true;
}



//-----------------  fGetImageData-------------------------------------------------
static DWORD CALLBACK GetImageData( LPSTR szBuffer, DWORD dwBufferMax, LPARAM lParam )
{
         DWORD dwNumberOfBytesRead;

⌨️ 快捷键说明

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