求助windows api
  • 板块学术版
  • 楼主dshzsh
  • 当前回复3
  • 已保存回复3
  • 发布时间2020/10/4 08:33
  • 上次更新2023/11/5 12:05:46
查看原帖
求助windows api
200116
dshzsh楼主2020/10/4 08:33

萌新刚学api,求助下面的图像显示出了什么问题

#include <bits/stdc++.h>
#include <windows.h>
#include <tchar.h>
#include <conio.h>
using namespace std;

#define key(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
#define dsh 0xFFF
#define pd(x,y) (x>=0&&y>=0&&x<=maxn&&y<=maxn)

const int maxn=800;
const int inf=1e9;
const int swss[5][2]={{0,0},{0,-1},{0,1},{-1,0},{1,0}};
const int bmpdx[110][2]={{},{60,60},{60,60},{100,100}};
const int gd=569;
class play
{
	public:
		int zb[2];
		int heal;
};
char title[1000]="made by dshzsh";
char injg[1010];
char stjg[1010];
play per;
int fs=30,dx=5;
int r=255,g=0,b=0;

HDC hdc,hdcc;
HPEN hPen;
HWND hwnd;
HANDLE hd;
HDC hMemDC   =CreateCompatibleDC (hdc);
HBITMAP hBmp =CreateCompatibleBitmap (hdc, maxn, maxn);

DWORD Drawing(LPVOID anything);
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
void bfs(int x,int y);
void zhin(int x);
void zhst(string x);
void GiveBmp(int x,int y,char name[],int hi,int we);
void GiveText(int x,int y,char name[],COLORREF color);

void GiveText(int x,int y,char name[],COLORREF color)
{
	HDC pahc;
	PAINTSTRUCT ps;
	pahc=BeginPaint (hwnd, &ps);
	SetTextColor(pahc, color);
	TextOut(pahc, x, y, TEXT(name), _tcslen(name));
	EndPaint (hwnd, &ps);
}
void GiveBmp(int x,int y,char name[],int hi,int we,DWORD rop)//这里//////////////////////////////
{
	HDC mdc;
	HBITMAP bg;
	mdc=CreateCompatibleDC(hdc);
	bg=(HBITMAP)LoadImage(NULL,TEXT(name),IMAGE_BITMAP,we,hi,LR_LOADFROMFILE);
	HGDIOBJ xx=SelectObject(mdc,bg);
	BitBlt(hdcc,x,y,we,hi,mdc,0,0,rop);
	DeleteObject(xx);
	DeleteObject(bg);
	DeleteObject(mdc);
}
void Show()//这里//////////////////////////////
{
	BitBlt(hdc,0,0,800,800,hdcc,0,0,SRCCOPY);
}
void zhst(string x)
{
	int cnt=x.size();
	for(int i=0;i<cnt;i++)
		stjg[i]=x[i];
	while(stjg[cnt]!=0) stjg[cnt++]=0;
}
void zhin(int x)
{
	int cnt=0;
	while(x>0)
	{
		injg[cnt++]=x%10+'0';
		x/=10;
	}
	for(int i=0;i<cnt/2;i++)
		swap(injg[i],injg[cnt-i-1]);
	while(injg[cnt]!=0) injg[cnt++]=0;
}
DWORD Drawing(LPVOID anything)//线程 
{
	//main
	per.zb[0]=0;
	int gx=800;
	while(1)
	{
		if(key('D')) gx-=5;
		if(key('A')) gx+=5;
		if(gx!=per.zb[0]&&gx>400&&gx<1200)
		{
			per.zb[0]=gx;
			GiveBmp(per.zb[0]-1200,0,"sour//BK.bmp",800,1600,SRCCOPY);
			GiveBmp(400-50,gd-100,"sour//per.bmp",100,100,SRCCOPY);
			//MoveWindow(hwnd,-per.zb[0]+1400,10,maxn,maxn,0);
			Show();
		}
		gx=per.zb[0];
	}
	DestroyWindow(hwnd);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	switch(Message)
	{
		case WM_DESTROY:
		{
			CloseHandle(hd);
			DeleteObject(hPen);
			PostQuitMessage(0);
			exit(0);
			break;
		}
		default:
			return DefWindowProc(hwnd, Message, wParam, lParam);
	}
	return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wc;
	MSG msg;

	memset(&wc,0,sizeof(wc));
	wc.cbSize		 = sizeof(WNDCLASSEX);
	wc.lpfnWndProc	 = WndProc;
	wc.hInstance	 = hInstance;
	wc.hCursor		 = LoadCursor(NULL, IDC_ARROW);

	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.lpszClassName = "WindowClass";
	wc.hIcon		 = LoadIcon(NULL, IDI_APPLICATION);
	wc.hIconSm		 = LoadIcon(NULL, IDI_APPLICATION);

	if(!RegisterClassEx(&wc))
	{
		MessageBox(NULL,  "what the fuck?","Error!",MB_ICONEXCLAMATION|MB_OK);
		return 0;
	}

	hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass",title,
						WS_VISIBLE|WS_OVERLAPPEDWINDOW,
	                      600, /* x */
	                      10, /* y */
	                      maxn, /* width */
	                      maxn, /* height */
	                      NULL,NULL,hInstance,NULL);

	if(hwnd == NULL)
	{
		MessageBox(NULL, "what the fuck?","Error!",MB_ICONEXCLAMATION|MB_OK);
		return 0;
	}
	hdc = GetDC(hwnd);
	hdcc=CreateCompatibleDC(hdc);
	hPen = CreatePen(PS_SOLID,2,RGB(255,0,0));
	SelectObject(hdc,hPen);
	hd = CreateThread(NULL,0,Drawing,NULL,0,0);
	
	while(1)
	{
		if(GetMessage(&msg, NULL, 0, 0) > 0)
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return msg.wParam;
}
2020/10/4 08:33
加载中...