无法跳出循环

0

我想写一个文本输入的程序,这是一部分代码,已经创建了画布并画好了按钮。我希望就是在输入的时候,如果点击退出按钮就可以结束这个程序,但是没有效果,不知道是哪里出了问题。(头文件什么的都没有问题,按钮也都能够运行,就是这个跳不出循环一直解决不了)。望大佬帮帮~

#include <stdio.h>

{
	MOUSEMSG k;
	char s[10000] = {0};//储存字符串
	int len = 0;
	wchar_t ch;//显示字符串
	settextstyle(18, 10, _T("宋体"));
	int x = 0;
	int num = 0;
  while(1)
  {
	   k=GetMouseMsg();
		while (x < 480)//限制在文本框内输入输出
	{   
		while(x < 10)//限制在文本框内输入输出
		{
			x = x + 1;
		}
		ch = _getwch();
		if(ch == '\b')//退格键
			{
				clearrectangle(x+1,50+25*num,x+19,80+25*num);
				x = x - 9;
				continue;
			}
	    
		if(ch == '\r' )  //回车键
			{
				break;
			}
		if (!(ch >= 32 && ch <= 126))//字母数字及部分符号
			{
				ch = 0;
			}
		outtextxy(x+10, 50+25*num, ch);

		//将显示的字符串存储起来
			s[len] = ch;
			len++;
		x += (ch < 256) ? 9 : 18;
		if(k.x >= 500)//跳出循环    这里好像就进不去,不知道为什么
		{
		 if(k.uMsg == WM_LBUTTONDOWN)
		{
			break;
		 }
		}
	}
	 x= 0;
	 num++;
	 if(k.x >= 500)//跳出循环
     {
      if(k.uMsg == WM_LBUTTONDOWN)
	  {
		 break;
	  }
     }
  }
}
ava
Curiosity*

2021-12-27

0
#include <graphics.h>
#include <stdio.h>
#include <conio.h>

void main()
{
	initgraph(900, 700);
	MOUSEMSG k;
	char s[10000] = { 0 };//储存字符串
	int len = 0;
	wchar_t ch;//显示字符串
	settextstyle(18, 10, _T("宋体"));
	int x = 0;
	int num = 0;
	rectangle(100, 10, 200, 50);
	bool gameover = false;
	while (!gameover)
	{
		while (x < 480)//限制在文本框内输入输出
		{
			if (x < 10)//限制在文本框内输入输出
			{
				x = 10;
			}
			if (_kbhit())
			{
				ch = _getwch();
				if (ch == '\b')//退格键
				{
					clearrectangle(x + 1, 50 + 25 * num, x + 19, 80 + 25 * num);
					x = x - 9;
					continue;
				}

				if (ch == '\r')  //回车键
				{
					break;
				}
				if (!(ch >= 32 && ch <= 126))//字母数字及部分符号
				{
					ch = 0;
				}
				outtextxy(x + 10, 50 + 25 * num, ch);

				//将显示的字符串存储起来
				s[len] = ch;
				len++;
				x += (ch < 256) ? 9 : 18;
			}

			if (MouseHit())
			{
				k = GetMouseMsg();
				if (k.uMsg == WM_LBUTTONDOWN && k.x >= 100 && k.x <= 200 && k.y > 10 && k.y < 50)//跳出循环
				{
					gameover = true;
					break;
				}
			}

		}
		x = 0;
		num++;
	}

	closegraph();
}

程序可以考虑使用一个 while 就好

ava
xiongfj ◑◑

2021-12-27

非常感谢!这下没有问题了~ -  Curiosity*  2021-12-27
技术讨论社区
相关提问