a question about LPTSTR and CString(100分)

  • 主题发起人 主题发起人 peiwents
  • 开始时间 开始时间
P

peiwents

Unregistered / Unconfirmed
GUEST, unregistred user!
//I have wrote to "SetWallPaper" Function:<br>//function1:<br>BOOL SetWallPaper(LPTSTR bmpPath)<br>{<br> BOOL res;<br> LPTSTR szFilePath;<br> strcpy(szFilePath,bmpPath);<br> res=SystemParametersInfo(SPI_SETDESKWALLPAPER,0,szFilePath,SPIF_SENDWININICHANGE);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //why here szFilePaht's data lost?<br> return res;<br>}<br>//function2:<br>BOOL SetWallPaper(CString bmpPath)<br>{<br> BOOL res;<br> LPTSTR szFilePath;<br> szFilePath=bmpPath.GetBuffer(100);<br> res=SystemParametersInfo(SPI_SETDESKWALLPAPER,0,szFilePath,SPIF_SENDWININICHANGE);<br> bmpPath.ReleaseBuffer();<br> return res;<br>}<br>// Here i call it<br>void CWallPaperDlg::OnButton1() <br>{<br> BOOL res=SetWallPaper(_T("c://windows//Lets_tech2_800.bmp"));<br> if(!res)<br> {<br> AfxMessageBox("Set WallPaper Failed!");<br> }<br> else<br> ::AfxPostQuitMessage(0); <br>}<br>Why the 2nd function work well,but the 1st one don't?<br>&nbsp;
 
LPTSTR is a MFC type!<br>CString is a MFC Class!
 
To here to have a look: http://www.vckbase.com
 
Agree varphone!
 
后退
顶部