動作確認をお願いします

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
heyman
記事: 99
登録日時: 12年前

動作確認をお願いします

#1

投稿記事 by heyman » 11年前

c言語です
プログラムの動作チェックをお願いします
種類はデスクトップマスコットの類ですので
ほかのをすべて閉じてください。
デスクトップ上で右クリックで、表示から、
アイコンの自動整列と等間隔に整列から
チェックを外して使用してください
プログラムは、

コード:

#include <windows.h>
#include <commctrl.h>  
#include <DxLib.h>
#include <stdlib.h>
#pragma comment(lib, "comctl32.lib")


int screen_x =1400;//スクリーンのサイズの変数
int screen_y =770;
int time=0; //時間の変数
int random = 0; //ランダム 変数
int image; //画像 変数
int ghandle [5];
int muki = 0; //向きを決める 0=右、1=左
int move =10, charn=1 ,iti=0 ,stop=0;
int iconind=0;
int time2;
HWND hWnd;
POINT iconPos;

//アイコンの位置を取得する
int iconnoiti()
{
	//デスクトップのアドレスの取得
DWORD dwProcessId;

GetWindowThreadProcessId(hWnd,&dwProcessId);

HANDLE hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,FALSE,dwProcessId);

if(!hProcess) return false;
//プロセスへメモリ空間をコミット
POINT* pnt = (POINT*)VirtualAllocEx(hProcess,
    NULL,4096,MEM_RESERVE | MEM_COMMIT,PAGE_READWRITE);

//アイコンの位置を取得
ListView_GetItemPosition(hWnd,iconind,pnt);//アイコンのインデックスを指定します。今は0です
//メモリをコピー
ReadProcessMemory(hProcess,pnt,&iconPos,sizeof(POINT),NULL);
//アイコンの座標
//iconPos.x
//iconPos.y
VirtualFreeEx(hProcess,pnt,iconind,MEM_RELEASE);
}

//キャラの移動
void charmove(){

int playr_x= 400; //プレイヤーの座標
int playr_y= 300;

if( charn==3){

	if(stop==0)
	{

		if(playr_x>700)
		{
	
		playr_x+=2;
		iconPos.x=playr_x ;
		iconPos.y=playr_y-50 ;
		//アイコンの位置を動かす
		SendMessage(hWnd, LVM_SETITEMPOSITION, (WPARAM)iconind, (LPARAM) MAKELPARAM ( iconPos.x,iconPos.y));

		DrawGraph( playr_x, playr_y, ghandle[0], TRUE );

		}
	if(playr_x<699)
	{
	playr_x-=2;
	iconPos.x=playr_x ;
	iconPos.y=playr_y-50 ;
	DrawGraph( playr_x, playr_y, ghandle[0], TRUE );
	SendMessage(hWnd, LVM_SETITEMPOSITION, (WPARAM)iconind, (LPARAM) MAKELPARAM ( iconPos.x,iconPos.y));//set

	}	

	}
if(iti==1 )
{
	if(playr_x<=10)
	{
	DrawGraph( playr_x, playr_y, ghandle[2], TRUE );
	iconPos.x-=6;
	
	stop=1;
	SendMessage(hWnd, LVM_SETITEMPOSITION, (WPARAM)iconind, (LPARAM) MAKELPARAM ( iconPos.x,iconPos.y));//set
	if(time2!=10)
	{
		time2+=1;
	
	}else
	{
	time2=0;
	iconind+=1;
	charn=0;
	iti=0;
	
	time=0;
	}	
}
if(playr_x>=1626)
{
	DrawGraph( playr_x, playr_y, ghandle[5], TRUE );
	iconPos.x+=50;
	
	stop=1;
	
		if(time2!=10)
		{
	
		time2+=1;
		SendMessage(hWnd, LVM_SETITEMPOSITION, (WPARAM)iconind, (LPARAM) MAKELPARAM ( iconPos.x,iconPos.y));//set
		}else
		{
			time2=0;
		
			charn=0;
			iti=0;
			iconind+=1;
			time=0;
		}	
}	

}	
}

if(100<time && charn==0)
{
	iconnoiti();
	time=0;
	charn =1;
	stop=0;
	iti=0;
}else 
{
	time +=move;
}
//キャラクターは動かない	
if(charn==0)
{
DrawGraph( playr_x, playr_y, ghandle[3], TRUE );//プレイヤーの描写

}
iconnoiti();
if(playr_x != iconPos.x || playr_y-50 != iconPos.y)
{
if(charn==1)
{
	iconnoiti();
	//縦に移動
	{
	if(playr_y>iconPos.y+50)
		{
			DrawGraph( playr_x, playr_y, ghandle[3], TRUE );
			playr_y-=1;
		}
		if(playr_y<iconPos.y+50)
		{
			playr_y+=1;
			DrawGraph( playr_x, playr_y, ghandle[3], TRUE );
		}
	}
	//横に移動
	if(playr_x<iconPos.x)
	{
		playr_x+=1;
		DrawGraph( playr_x, playr_y, ghandle[3], TRUE );
	}
	if(playr_x>iconPos.x)
	{
		playr_x-=1;
		DrawGraph( playr_x, playr_y, ghandle[3], TRUE );
	}

	if(playr_x == iconPos.x && playr_y-50 == iconPos.y)
	{
		iti=1;
		charn=3;
	}
	
}
}

}


int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int showCmd)
{


  ChangeWindowMode(TRUE); 

	//ウィンドウを透明にする
	SetBackgroundColor(0,0,0);
    SetUseBackBufferTransColorFlag(TRUE);

    SetTransColor(0,0,0);
    
    DxLib_Init();
	SetWindowSize( screen_x, screen_y ); //ウィンドウのサイズ
	SetGraphMode( screen_x,screen_y,32 ); //解像度
    SetDrawScreen( DX_SCREEN_BACK ); //裏画面にする
image = LoadDivGraph("ninngen.png",6,3,2,64,64,ghandle);//画像の読み込み

hWnd = FindWindow("ProgMan",NULL);
hWnd = GetWindow(hWnd,GW_CHILD);
hWnd = GetWindow(hWnd,GW_CHILD);
if(!hWnd)return -1;

while(!ScreenFlip() && !ClearDrawScreen() && !ProcessMessage() && !CheckHitKey(KEY_INPUT_ESCAPE)){


iconnoiti();
SendMessage(hWnd, LVM_SETITEMPOSITION, (WPARAM)iconind, (LPARAM) MAKELPARAM ( iconPos.x,iconPos.y));//set
charmove();


ScreenFlip();
}

DxLib_End();
return 0;
}
画像ファイルと同じとこに入れて使ってください
あと、プログラムがきたないので、見やすくしてくれたらうれしいです。
添付ファイル
ninngen.png
ninngen.png (1.64 KiB) 閲覧数: 1852 回

アバター
みけCAT
記事: 6734
登録日時: 14年前
住所: 千葉県
連絡を取る:

Re: 動作確認をお願いします

#2

投稿記事 by みけCAT » 11年前

heyman さんが書きました:あと、プログラムがきたないので、見やすくしてくれたらうれしいです。
まずインデントを整えましょう。
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)

heyman
記事: 99
登録日時: 12年前

Re: 動作確認をお願いします

#3

投稿記事 by heyman » 11年前

ミスりました

コード:

int screen_x =1300;//スクリーンのサイズの変数 1400
int screen_y =700; //770
int time=0; //時間の変数
int random = 0; //ランダム 変数
int image; //画像 変数
int ghandle [5];
int muki = 0; //向きを決める 0=右、1=左
int move =10, charn=1 ,iti=0 ,stop=0;
int iconind=0;
int time2;
int playr_x= 400; //プレイヤーの座標
int playr_y= 300;
HWND hWnd;
POINT iconPos;

//アイコンの位置を取得する
int iconnoiti(void)
{
	//デスクトップのアドレスの取得
DWORD dwProcessId;

GetWindowThreadProcessId(hWnd,&dwProcessId);

HANDLE hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,FALSE,dwProcessId);

if(!hProcess) return false;
//プロセスへメモリ空間をコミット
POINT* pnt = (POINT*)VirtualAllocEx(hProcess,
    NULL,4096,MEM_RESERVE | MEM_COMMIT,PAGE_READWRITE);

//アイコンの位置を取得
ListView_GetItemPosition(hWnd,iconind,pnt);//アイコンのインデックスを指定します。今は0です
//メモリをコピー
ReadProcessMemory(hProcess,pnt,&iconPos,sizeof(POINT),NULL);
//アイコンの座標
//iconPos.x
//iconPos.y
VirtualFreeEx(hProcess,pnt,iconind,MEM_RELEASE);
}

//キャラの移動
void charmove(){



if( charn==3)
{

	if(stop==0)
	{

		if(playr_x>700)
		{
	
		playr_x+=2;
		iconPos.x=playr_x ;
		iconPos.y=playr_y-50 ;
		//アイコンの位置を動かす
		SendMessage(hWnd, LVM_SETITEMPOSITION, (WPARAM)iconind, (LPARAM) MAKELPARAM ( iconPos.x,iconPos.y));

		DrawGraph( playr_x, playr_y, ghandle[0], TRUE );

		}
		if(playr_x<699)
		{
		playr_x-=2;
		iconPos.x=playr_x ;
		iconPos.y=playr_y-50 ;
		DrawGraph( playr_x, playr_y, ghandle[0], TRUE );
		SendMessage(hWnd, LVM_SETITEMPOSITION, (WPARAM)iconind, (LPARAM) MAKELPARAM ( iconPos.x,iconPos.y));//set

		}	

	}
	if(iti==1 )
	{
		if(playr_x<=10)
		{
			DrawGraph( playr_x, playr_y, ghandle[2], TRUE );
			iconPos.x-=6;
		
			stop=1;
			SendMessage(hWnd, LVM_SETITEMPOSITION, (WPARAM)iconind, (LPARAM) MAKELPARAM ( iconPos.x,iconPos.y));//set
			if(time2!=10)
			{
				time2+=1;
		
			}else
			{
				time2=0;
				iconind+=1;
				charn=0;
				iti=0;
		
				time=0;
			}	
		}
		if(playr_x>=1626)
		{
			DrawGraph( playr_x, playr_y, ghandle[5], TRUE );
			iconPos.x+=50;
		
			stop=1;
	
			if(time2!=10)
			{
	
				time2+=1;
				SendMessage(hWnd, LVM_SETITEMPOSITION, (WPARAM)iconind, (LPARAM) MAKELPARAM ( iconPos.x,iconPos.y));//set
			}else
			{
				time2=0;			
			
				charn=0;
				iti=0;
				iconind+=1;
				time=0;
			}	
		}	

	}	
}

if(100<time && charn==0)
{
	iconnoiti();
	time=0;
	charn =1;
	stop=0;
	iti=0;
}else 
{
	time +=move;
}
//キャラクターは動かない	
if(charn==0)
{
	DrawGraph( playr_x, playr_y, ghandle[3], TRUE );//プレイヤーの描写

}
iconnoiti();
if(playr_x != iconPos.x || playr_y-50 != iconPos.y)
{
	if(charn==1)
	{
		iconnoiti();
		//縦に移動
		if(playr_y>iconPos.y+50)
		{
			DrawGraph( playr_x, playr_y, ghandle[3], TRUE );
			playr_y-=1;
		}
		if(playr_y<iconPos.y+50)
		{
			playr_y+=1;
			DrawGraph( playr_x, playr_y, ghandle[3], TRUE );
		}

		//横に移動
		if(playr_x<iconPos.x)
		{
			playr_x+=1;
			DrawGraph( playr_x, playr_y, ghandle[3], TRUE );
		}
		if(playr_x>iconPos.x)
		{
			playr_x-=1;
			DrawGraph( playr_x, playr_y, ghandle[3], TRUE );
		}

		if(playr_x == iconPos.x && playr_y-50 == iconPos.y)
		{
			iti=1;
			charn=3;
		}
		
	
	}
}

}


int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine, int showCmd)
{

ChangeWindowMode(TRUE); 

//ウィンドウを透明にする
SetBackgroundColor(0,0,0);
SetUseBackBufferTransColorFlag(TRUE);

SetTransColor(0,0,0);
    
DxLib_Init();
SetWindowSize( screen_x, screen_y ); //ウィンドウのサイズ
SetGraphMode( screen_x,screen_y,32 ); //解像度
SetDrawScreen( DX_SCREEN_BACK ); //裏画面にする
image = LoadDivGraph("ninngen.png",6,3,2,64,64,ghandle);//画像の読み込み

hWnd = FindWindow("ProgMan",NULL);
hWnd = GetWindow(hWnd,GW_CHILD);
hWnd = GetWindow(hWnd,GW_CHILD);
if(!hWnd)return -1;

while(!ScreenFlip() && !ClearDrawScreen() && !ProcessMessage() && !CheckHitKey(KEY_INPUT_ESCAPE))
{


	iconnoiti();
	SendMessage(hWnd, LVM_SETITEMPOSITION, (WPARAM)iconind, (LPARAM) MAKELPARAM ( iconPos.x,iconPos.y));//set
	charmove();
	ScreenFlip();
}

DxLib_End();
return 0;
}



です すいません

閉鎖

“C言語何でも質問掲示板” へ戻る