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

📄 yadlg.cpp

📁 这是书上的代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	     if(wparam=IDI_ICON1)
		 {

	       switch(lparam)
		   {
	       case WM_LBUTTONDOWN:
		        AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
		        OnPreviewPaper();
				break;
	        case WM_RBUTTONDOWN:
	           	 OnContextMenu(this);
				 break;
	       default:
		      break;
		   }
	      return 0;
		 }
       return 0;
}


void CYaDlg::OnAddpaper() 
{
	// TODO: Add your control notification handler code here
	CFileDialog file(TRUE,"*","*.bmp;*.jpg");
	if(file.DoModal()==IDOK)
	{  
		CString filename,filepath,fileext;
	    filename=file.GetFileName();
	    filepath=file.GetPathName();
	    fileext=file.GetFileExt();
		if(fileext!="bmp")
		{
			MessageBox("只能加入*.bmp文件!");
			return;
		}
		//MessageBox(filepath);
		
	   int nums=m_list1.GetItemCount();
	   if(nums==20)
	   {
		   AfxMessageBox("最多只能加入20个文件");
		   return;
	   }
	   for(int i=0;i<nums;i++)
	   {//AfxMessageBox(m_list1.GetItemText(i,0));
		  if( strcmp(m_list1.GetItemText(i,0),filename)==0)
		  {
		  AfxMessageBox("文件已经存在!");
			  return;
		  }
	   }
	   m_list1.InsertItem(nums,filename,1);
	  
	  
      CString stringpaper,stringpath;
	  stringpaper.Format("wallpaper%d",nums);
	  stringpath.Format("wallpaperpath%d",nums);
	  //registry
	  AfxGetApp()->WriteProfileInt("paper","currentpaper",0);
	 
	  AfxGetApp()->WriteProfileString("paper",stringpaper,filename);
	  AfxGetApp()->WriteProfileInt("paper","papernum",nums);
	  AfxGetApp()->WriteProfileString("paperpath",stringpath,filepath);
	  AfxGetApp()->WriteProfileInt("paperpath","paperpathnum",nums);

	  OnDrawPaper(filepath);
	 
	}
}

BOOL CYaDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
   Shell_NotifyIcon(NIM_DELETE,&data);
////////////////	
    
	return CDialog::DestroyWindow();
}

 void CYaDlg::OnContextMenu(CWnd* pWnd) 

 {	// TODO: Add your message handler code here
 	
 	CMenu menu;
 	if(menu.LoadMenu(IDR_MENU2))
 	{
 		CMenu *popup=menu.GetSubMenu(0);
 		ASSERT(popup!=NULL);
 		CPoint mouse;
 		GetCursorPos(&mouse);
 		::SetForegroundWindow(data.hWnd);
 
 		popup->TrackPopupMenu(TPM_LEFTALIGN ,mouse.x,mouse.y,pWnd,NULL);
 	}
 
 
}



void CYaDlg::OnDeletepaper() 
{
	// TODO: Add your control notification handler code here
	POSITION pos=m_list1.GetFirstSelectedItemPosition();
	if(pos==NULL)
	{
		MessageBox("请选择要删除的文件!");
		return;
	}
       int ntextbefore=m_list1.GetItemCount();
       int nums=m_list1.GetNextSelectedItem(pos);
	   int backvalue=m_list1.DeleteItem(nums);
	   //m_list1.Update(nums);
       if(backvalue!=0)
	   {
	   CString m_stringnums;
	   m_stringnums.Format("nums%d has been deleted!",nums);
	   MessageBox(m_stringnums); 
	   }
//	}  
	  int ntextafter=m_list1.GetItemCount(); 
	//delete all paper key value,later we will rewrite;
      
	   for(int i=0;i<=ntextbefore;i++)
	   {
		   CString m_stringpaper;
	       m_stringpaper.Format("wallpaper%d",i);
	       
		   AfxGetApp()->WriteProfileString("paper",m_stringpaper,NULL);
		   
		   
	   }
       //delete the choosed item paperpath key
	   CString m_stringpaperpath;
	   m_stringpaperpath.Format("wallpaperpath%d",nums);
	   AfxGetApp()->WriteProfileString("paperpath",m_stringpaperpath,NULL);
	   
	   
    //rewrite regedit file list
	for(int j=0;j<ntextafter;j++)
	{     
		CString m_string;
	    m_string.Format("wallpaper%d",j);
	    AfxGetApp()->WriteProfileString("paper",m_string,m_list1.GetItemText(j,0));
	}
	for(int m=0;m<=ntextafter;m++)
	{   
		CString m_stringpath,m_stringgetpath,m_getpathname;
		if(m>nums)
		{  
            m_stringpath.Format("wallpaperpath%d",m-1);
			m_stringgetpath.Format("wallpaperpath%d",m);
			CString m_getpathname=AfxGetApp()->GetProfileString("paperpath",m_stringgetpath);
			AfxGetApp()->WriteProfileString("paperpath",m_stringpath,m_getpathname);
		}
		
	}     
    //delete last paperpath key
	CString m_laststring;
	m_laststring.Format("wallpaperpath%d",ntextafter);
	AfxGetApp()->WriteProfileString("paperpath",m_laststring,NULL);

	   AfxGetApp()->WriteProfileInt("paper","papernum",ntextafter-1);
	   AfxGetApp()->WriteProfileInt("paperpath","paperpathnum",ntextafter-1);
	   if(m_bitmap.DeleteObject())
	   {
		   m_bitmap.Detach();
	   }
	   return;
}





void CYaDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	POSITION pos=m_list1.GetFirstSelectedItemPosition();
	if(pos==NULL)
	{
		return;
	}
	OnPreviewPaper();
	*pResult = 0;
}



BOOL CYaDlg::OnPreviewPaper()
{
    POSITION pos=m_list1.GetFirstSelectedItemPosition();
 	int index=m_list1.GetNextSelectedItem(pos);
 	CString m_filepathindex,m_filepath;
	m_filepathindex.Format("wallpaperpath%d",index);
	m_filepath=AfxGetApp()->GetProfileString("paperpath",m_filepathindex);
 	if(m_filepath=="")
	{
		CString m_pathnameneed;
		int m_curpaperneed=AfxGetApp()->GetProfileInt("paper","currentpaper",0);
		m_pathnameneed.Format("wallpaperpath%d",m_curpaperneed);
		m_filepath=AfxGetApp()->GetProfileString("paperpath",m_pathnameneed);
	}
	
	return OnDrawPaper(m_filepath);

/*	CDC* pdc=AfxGetApp()->m_pMainWnd->GetWindowDC();
	ASSERT_VALID(pdc);
	
	HBITMAP hbitmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(),m_filepath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_DEFAULTSIZE);
	if(hbitmap)
	{   
		if(m_bitmap.DeleteObject())
		{
			m_bitmap.Detach();
			
		}
		m_bitmap.Attach(hbitmap);
	}
	else
	{
		MessageBox("文件装载出现错误1!请添加文件!");
		return TRUE;
	}
	BITMAP bm;
    int m_value1=m_bitmap.GetBitmap(&bm);
	if(m_value1==0)
	{
		MessageBox("文件装载出现错误2!");
		return TRUE;
	}
	CDC dcmem;
    BOOL m_value2=dcmem.CreateCompatibleDC(pdc);
    if(m_value2==NULL)
	{
		MessageBox("文件装载出现错误3!");
		return TRUE;
	}
	CBitmap* poldbitmap=(CBitmap*)dcmem.SelectObject(m_bitmap);
	CRect rect(537,212,637,312);
	ScreenToClient(&rect);
	rect.NormalizeRect();
    CPoint upleft=rect.TopLeft();
	BOOL m_value3=pdc->StretchBlt(upleft.x+2,upleft.y+20,rect.Width(),rect.Height(),&dcmem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
    if(m_value3==NULL)
	{
		MessageBox("文件装载出现错误4!");
		return TRUE;
	}
	return TRUE;
	*/
}
BOOL CYaDlg::OnHideWindow()
 {
    if(mouseflag==TRUE)
	{
	   // BOOL m_backvalue=SystemParametersInfo(SPI_SETDESKWALLPAPER,0,NULL,SPIF_UPDATEINIFILE);
	    mouseflag=FALSE;
	}
		AfxGetApp()->m_pMainWnd->ShowWindow(SW_HIDE);
    return TRUE;
 }

void CYaDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
    AfxGetApp()->WriteProfileInt("paper","dispmode",m_dispmode.GetCurSel());
 	AfxGetApp()->WriteProfileInt("papertime","updateperiod",m_papertime);
    OnHideWindow();
}
void CYaDlg::OnMenuAbout()
{
	CAboutDlg dlg;
	dlg.DoModal();
}







BOOL CYaDlg::OnDrawPaper(CString m_filepath)
{
		CDC* pdc=AfxGetApp()->m_pMainWnd->GetWindowDC();
	ASSERT_VALID(pdc);
	
	HBITMAP hbitmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(),m_filepath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_DEFAULTSIZE);
	if(hbitmap)
	{   
		if(m_bitmap.DeleteObject())
		{
			m_bitmap.Detach();
			
		}
		m_bitmap.Attach(hbitmap);
	}
	else
	{
		MessageBox("文件装载出现错误1!请添加文件!");
		return TRUE;
	}
	BITMAP bm;
    int m_value1=m_bitmap.GetBitmap(&bm);
	if(m_value1==0)
	{
		MessageBox("文件装载出现错误2!");
		return TRUE;
	}
	CDC dcmem;
    BOOL m_value2=dcmem.CreateCompatibleDC(pdc);
    if(m_value2==NULL)
	{
		MessageBox("文件装载出现错误3!");
		return TRUE;
	}
	CBitmap* poldbitmap=(CBitmap*)dcmem.SelectObject(m_bitmap);
	CRect rect(537,212,637,312);
	ScreenToClient(&rect);
	rect.NormalizeRect();
    CPoint upleft=rect.TopLeft();
	BOOL m_value3=pdc->StretchBlt(upleft.x+2,upleft.y+20,rect.Width(),rect.Height(),&dcmem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
    if(m_value3==NULL)
	{
		MessageBox("文件装载出现错误4!");
		return TRUE;
	}
	return TRUE;


}

⌨️ 快捷键说明

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