请让我修复程序中的ug [英] Please let me fix the ug in the program

查看:48
本文介绍了请让我修复程序中的ug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个程序中我将

bar[19].y - 20

更改为

bar[19].y + 20

矩形现在变为向上移动的白板而不是向上移动的矩形。代码中的错误请告诉我?谢谢。



< b>我尝试过:



the rectangle now changes to white sheet moving upwards instead of rectangle moving upwards.What is the bug in the code please let me know?Thank you.

What I have tried:

#ifndef UNICODE
#define UNICODE
#endif 

#include<windows.h>
#include<string.h>
int px = 100, py = 100,i = 0;
POINT m;
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void check();
struct box { int x; int y; int width; }bar[20];
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
	// Register the window class.
	const wchar_t CLASS_NAME[] = L"Game";

	WNDCLASS wc = {};

	wc.lpfnWndProc = WindowProc;
	wc.hInstance = hInstance;
	wc.lpszClassName = CLASS_NAME;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	RegisterClass(&wc);

	// Create the window.

	HWND hwnd = CreateWindowEx(
		0,                              // Optional window styles.
		CLASS_NAME,                     // Window class
		L"Catch Me If You Can",    // Window text
		WS_OVERLAPPEDWINDOW,            // Window style

										// Size and position
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

		NULL,       // Parent window    
		NULL,       // Menu
		hInstance,  // Instance handle
		NULL        // Additional application data
	);

	if (hwnd == NULL)
	{
		return 0;
	}

	ShowWindow(hwnd, nCmdShow);

	// Run the message loop.
	MSG msg = {};
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return 0;
}
void check()
{
	GetCursorPos(&m);
	if (m.x <10 && m.y <10) { px = 250; py = 250; }
	
}


LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	HBRUSH cr = CreateSolidBrush(RGB(250, 125, 50));
	HBRUSH wr = CreateSolidBrush(RGB(255,255,255));
	HBRUSH bkfill = CreateSolidBrush(RGB(230, 230, 230));
	HANDLE hold;
	HPEN pen = CreatePen(PS_NULL, 0, 1);
	switch (uMsg)
	{
	//case WM_CREATE:
		
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;

	case WM_PAINT:
	{
		//InvalidateRect(hwnd, 0, TRUE);
		//px = 100, py = 100,i=0;
		
		hdc = BeginPaint(hwnd, &ps);
		SendMessage(hwnd, WM_CREATE, NULL, NULL);
		FillRect(hdc, &ps.rcPaint, cr);
		SelectObject(hdc, pen);
		for (i = 0; i < 20; i++)
		{
			bar[i].y = 100 + i * 20;
			bar[i].width = 2 * (i + 1) * 150 / 20;
			bar[i].x = 250-bar[i].width/2;         //or we could use  bar[i].x = 350-(i+1)*150/20;
		}
		SelectObject(hdc, wr);
		Rectangle(hdc, bar[1].x, bar[1].y, bar[1].x + bar[1].width, bar[1].y - 20);
		while (bar[19].y != 30)
		{
			SelectObject(hdc, cr);
			Rectangle(hdc, bar[19].x, bar[19].y--, bar[19].x + bar[19].width, bar[19].y - 20);
			SelectObject(hdc, wr);
			Rectangle(hdc, bar[19].x, bar[19].y, bar[19].x + bar[19].width, bar[19].y - 20);
			Sleep(4);
		}
		/*for (i = 0; i < 20; i++)
			Rectangle(hdc, bar[i].x, bar[i].y, bar[i].x + bar[i].width, bar[i].y + 20);*/
		EndPaint(hwnd, &ps);
	}
   
	}
	
	return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

推荐答案

通过该更改,您可以为矩形提供不同的签名高度,因此底线是在另一边绘制的。



如果要移动矩形,则必须更改原点的y坐标而不是高度。



播放一下Rectangle函数以更好地显示变化。
With that change you give the rectangle a different signed heigth and so the bottom line is drawn on the other side.

If you want to move the rectangle you must change the y-coordinate of the origin and not the heigth.

Play a bit the the Rectangle function to better visualize the changes.


这篇关于请让我修复程序中的ug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆