📄 yadlg.cpp
字号:
// yaDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ya.h"
#include "yaDlg.h"
#include "shellapi.h"
#include"winuser.h"
#include"dbt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CYaDlg dialog
CYaDlg::CYaDlg(CWnd* pParent /*=NULL*/)
: CDialog(CYaDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CYaDlg)
m_papertime = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
mouseflag=FALSE;
m_image.Create(16,16,ILC_COLOR,1,20);
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_curpaper=0;
m_currentdate=0;
}
void CYaDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CYaDlg)
DDX_Control(pDX, IDC_LIST1, m_list1);
DDX_Control(pDX, IDC_DISPMODE, m_dispmode);
DDX_Control(pDX, IDC_SPIN1, m_spin1);
DDX_Text(pDX, IDC_PAPERTIME, m_papertime);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CYaDlg, CDialog)
//{{AFX_MSG_MAP(CYaDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ADDPAPER, OnAddpaper)
ON_BN_CLICKED(IDC_DELETEPAPER, OnDeletepaper)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_USER+1,OnStatusIcon)
ON_MESSAGE(WM_USER+2,OnHideWindow)
ON_COMMAND(ID_MENUABOUT,OnMenuAbout)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CYaDlg message handlers
BOOL CYaDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
PostMessage(WM_USER+2);
//system pane icon
HICON icon=AfxGetApp()->LoadIcon(IDI_ICON1);
data.cbSize=sizeof(NOTIFYICONDATA);
data.hIcon=icon;
data.hWnd=m_hWnd;
strcpy(data.szTip,"this is a really cry");
data.uCallbackMessage=WM_USER+1;
data.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
data.uID=88;
if(!Shell_NotifyIcon(NIM_ADD,&data))
MessageBox("wa,buxingyai");
//spin control
m_spin1.SetRange(1,30);
m_spin1.SetPos(1);
//add icon in imagelist
m_image.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
m_image.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
//initialize list box
m_list1.SetImageList(&m_image,LVSIL_SMALL);
m_list1.SetIconSpacing(40,80);
//////////////
/////////////read data from regedit
int nums=AfxGetApp()->GetProfileInt("paper","papernum",0);
if(nums!=0)
{
for(int i=0;i<=nums;i++)
{
CString string,getstring;
string.Format("wallpaper%d",i);
getstring=AfxGetApp()->GetProfileString("paper",string);
m_list1.InsertItem(i,getstring,1);
}
}
int mode=AfxGetApp()->GetProfileInt("paper","dispmode",0);
m_dispmode.SetCurSel(mode);
//UpdateData(FALSE);
//////////////////////////////////////////when open the computer it can check if need
//////////////////////////////////////////change the wallpaper,if need ,will do it
m_curpaper=AfxGetApp()->GetProfileInt("paper","currentpaper",0);
if(m_curpaper>=nums)
m_curpaper=-1;
////////////
m_list1.SetHotItem(m_curpaper);
// OnPreviewPaper();
/////////////
int m_getcurpaperindex=0;
m_papertime=AfxGetApp()->GetProfileInt("papertime","updateperiod",1);
int m_lastupdatetime=AfxGetApp()->GetProfileInt("papertime","lastupdatetime",0);
//initialize viarable m_date
m_date=COleDateTime::GetCurrentTime();
m_currentdate=m_date.GetDayOfYear();
BOOL m_changeflag=FALSE;
if(m_currentdate-m_lastupdatetime>=m_papertime)
{
m_changeflag=TRUE;
}
if(m_currentdate-m_lastupdatetime<0)
{
int year=m_date.GetYear()-1;
if(year%1000==0)
{
if(year%400==0) year=366;
else year=365;
}
else
{
if(year%4==0) year=366;
else year=365;
}
if(year-m_lastupdatetime+m_currentdate>=m_papertime)
m_changeflag=TRUE;
}
if(m_changeflag)
{
AfxGetApp()->WriteProfileInt("papertime","lastupdatetime",m_currentdate);
m_getcurpaperindex=AfxGetApp()->GetProfileInt("paper","currentpaper",0);
CString m_curstring;
m_curstring.Format("wallpaperpath%d",m_getcurpaperindex);
CString m_getcurpaperpath=AfxGetApp()->GetProfileString("paperpath",m_curstring);
CString m_tile,m_style;
switch(m_dispmode.GetCurSel())
{
case 1:
m_tile.Format("%d",1);
m_style.Format("%d",0);
break;
case 2:
m_tile.Format("%d",0);
m_style.Format("%d",2);
break;
default:
m_tile.Format("%d",0);
m_style.Format("%d",0);
break;
}
TCHAR szData[MAX_PATH],szTile[MAX_PATH],szStyle[MAX_PATH];
wsprintf(szData,m_getcurpaperpath);
wsprintf(szTile,m_tile);
wsprintf(szStyle,m_style);
HKEY hkey1,hkey2;
::RegOpenKeyEx(HKEY_CURRENT_USER,"Control Panel",0,KEY_SET_VALUE,&hkey1);
::RegOpenKeyEx(hkey1,"desktop",0,KEY_SET_VALUE,&hkey2);
::RegSetValueEx(hkey2,"Wallpaper",0,REG_SZ,(LPBYTE)szData,lstrlen(szData)+1);
::RegSetValueEx(hkey2,"TileWallpaper",0,REG_SZ,(LPBYTE)szTile,lstrlen(szTile)+1);
::RegSetValueEx(hkey2,"WallpaperStyle",0,REG_SZ,(LPBYTE)szStyle,lstrlen(szStyle)+1);
::RegCloseKey(hkey2);
::RegCloseKey(hkey1);
mouseflag=TRUE;
++m_curpaper;
AfxGetApp()->WriteProfileInt("paper","currentpaper",m_curpaper);
SystemParametersInfo(SPI_SETDESKWALLPAPER,0,NULL,0);
::RegOpenKeyEx(HKEY_CURRENT_USER,"Control Panel",0,KEY_SET_VALUE,&hkey1);
::RegOpenKeyEx(hkey1,"desktop",0,KEY_SET_VALUE,&hkey2);
::RegSetValueEx(hkey2,"Wallpaper",0,REG_SZ,(LPBYTE)szData,lstrlen(szData)+1);
::RegSetValueEx(hkey2,"TileWallpaper",0,REG_SZ,(LPBYTE)szTile,lstrlen(szTile)+1);
::RegSetValueEx(hkey2,"WallpaperStyle",0,REG_SZ,(LPBYTE)szStyle,lstrlen(szStyle)+1);
::RegCloseKey(hkey2);
::RegCloseKey(hkey1);
}
return TRUE; // return TRUE unless you set the focus to a control
}
void CYaDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CYaDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
OnPreviewPaper();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CYaDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
LRESULT CYaDlg::OnStatusIcon(WPARAM wparam, LPARAM lparam)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -