資源簡介
瘋狂桌面貪吃蛇,操作桌面的圖標(biāo)組成貪吃蛇,非常好玩

代碼片段和文件信息
////////////////////////////////////////////////
//?KeyHookApp.cpp文件
#include?“resource.h“
#include?“KeyHookApp.h“
#include?“KeyHookLib.h“
#include?
#include?
#include?
#include?
using?namespace?std;?
#pragma?comment(lib?“09KeyHookLib“)
CMyApp?theApp;
BOOL?CMyApp::InitInstance()
{
CMainDialog?dlg;
m_pMainWnd?=?&dlg;
dlg.DoModal();
return?FALSE;
}
CMainDialog::CMainDialog(CWnd*?pParentWnd):CDialog(IDD_MAIN?pParentWnd)
{
}
BEGIN_MESSAGE_MAP(CMainDialog?CDialog)
ON_MESSAGE(HM_KEY?OnHookKey)
ON_WM_TIMER()
END_MESSAGE_MAP()
void?CMainDialog::OnGetDesktopInfo()
{
HWND????hDesk;???
????RECT????rc;???
????hDesk=GetDesktopWindow()->GetSafeHwnd();???
????::GetWindowRect(hDesk&rc);?
DeskWidth=rc.right-rc.left;
DeskHeight=rc.bottom-rc.top;
}
void?CMainDialog::OnTimer(UINT?nIDEvent)?
{
int?i;
for(?i=HasEat;i>0;i--)?//移動貪吃蛇除頭部以外的部分
{
EatIconPos[i][0]=EatIconPos[i-1][0];
EatIconPos[i][1]=EatIconPos[i-1][1];
}
switch(Dir)
{
case?0:
EatIconPos[0][1]=(EatIconPos[0][1]-1?+DeskHeight?/?IconHeight)?%?(DeskHeight?/?IconHeight);
break;
case?1:
EatIconPos[0][1]=(EatIconPos[0][1]+1)?%?(DeskHeight?/?IconHeight);
break;
case?2:
EatIconPos[0][0]=(EatIconPos[0][0]-1+DeskWidth?/?IconWidth)?%?(DeskWidth?/?IconWidth);
break;
case?3:
EatIconPos[0][0]=(EatIconPos[0][0]+1)?%?(DeskWidth?/?IconWidth);
break;
}
if(EatIconPos[0][0]==EatIconPos[HasEat+1][0]?&&?EatIconPos[0][1]?==EatIconPos[HasEat+1][1])
{ //吃到了食物
HasEat++;
if(HasEat==IconNum-1)
{
CDialog::OnCancel();
}
srand(time(NULL));
int?xy;
con:
x=rand()%(DeskWidth?/?IconWidth);
y=rand()%(DeskHeight?/?IconHeight);
for(int?i=0;i<=HasEat;i++)
{
if(x==EatIconPos[i][0]?&&?y==EatIconPos[i][1])
{
goto?con;
}
}
EatIconPos[HasEat+1][0]=x;
EatIconPos[HasEat+1][1]=y;
}
?
for(?i=0;i<=HasEat+1;i++)
{
OnSetDeskIcon(hwndSysListView32iEatIconPos[i][0]*IconWidthEatIconPos[i][1]?*?IconHeight);
}
CDialog::OnTimer(nIDEvent);
}
BOOL?CMainDialog::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(theApp.LoadIcon(IDI_MAIN)?FALSE);
OnGetDesktopInfo();
OnGetDeskIconInfo();
hwndParent?=?::FindWindow(?“Progman“?“Program?Manager“?);?
hwndSHELLDLL_DefView?=?::FindWindowEx(?hwndParent?NULL?“SHELLDLL_DefView“?NULL?);
hwndSysListView32?=?::FindWindowEx(?hwndSHELLDLL_DefView?NULL?“SysListView32“?“FolderView“?);
for(int?i=0;i {
OnSetDeskIcon(hwndSysListView32i-1000);
}
Dir=1;
HasEat=0;
srand(time(NULL));
for(i=0;i<2;i++)
{
EatIconPos[i][0]=rand()%(DeskWidth?/?IconWidth);
EatIconPos[i][1]=rand()%(DeskHeight?/?DeskHeight);
}
//?安裝鉤子
if(!SetKeyHook(TRUE?0?m_hWnd))
MessageBox(“安裝鉤子失敗!“);
SetTimer(?100?100?NULL);
return?TRUE;
}
void?CMainDialog::OnCancel()
{
//?卸載鉤子
SetKeyHook(FALSE);
for(int?i
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3913??2012-02-19?14:18??瘋狂桌面圖標(biāo)貪吃蛇\09KeyHookApp.dsp
?????文件????????547??2004-12-01?17:46??瘋狂桌面圖標(biāo)貪吃蛇\09KeyHookApp.dsw
?????文件????1359972??2012-02-19?20:39??瘋狂桌面圖標(biāo)貪吃蛇\09KeyHookApp.exe
?????文件?????204872??2004-12-01?20:08??瘋狂桌面圖標(biāo)貪吃蛇\09KeyHookLib.dll
?????文件???????2134??2004-12-01?20:08??瘋狂桌面圖標(biāo)貪吃蛇\09KeyHookLib.lib
?????文件???????6984??2012-02-19?12:10??瘋狂桌面圖標(biāo)貪吃蛇\KeyHookApp.cpp
?????文件????????787??2012-02-18?22:55??瘋狂桌面圖標(biāo)貪吃蛇\KeyHookApp.h
?????文件???????3774??2004-12-01?19:01??瘋狂桌面圖標(biāo)貪吃蛇\KeyHookApp.ICO
?????文件???????2513??2012-02-18?21:56??瘋狂桌面圖標(biāo)貪吃蛇\KeyHookApp.rc
?????文件????????453??2004-12-01?20:07??瘋狂桌面圖標(biāo)貪吃蛇\KeyHookLib.h
?????文件????1359972??2012-02-19?20:39??瘋狂桌面圖標(biāo)貪吃蛇\Release\09KeyHookApp.exe
?????文件?????204872??2004-12-01?20:08??瘋狂桌面圖標(biāo)貪吃蛇\Release\09KeyHookLib.dll
?????文件????????550??2004-12-01?19:01??瘋狂桌面圖標(biāo)貪吃蛇\resource.h
?????文件????????188??2012-02-19?19:36??瘋狂桌面圖標(biāo)貪吃蛇\操作說明.txt
?????目錄??????????0??2012-02-19?20:40??瘋狂桌面圖標(biāo)貪吃蛇\Release
?????目錄??????????0??2012-02-19?20:40??瘋狂桌面圖標(biāo)貪吃蛇
-----------?---------??----------?-----??----
??????????????3151531????????????????????16
評論
共有 條評論