InputBox

This function is used to get user input as a dialog box.

bool InputBox(
	LPTSTR	pString,
	int		nMaxCount,
	LPCTSTR	pPrompt = NULL,
	LPCTSTR	pTitle = NULL,
	LPCTSTR	pDefault = NULL,
	int		width = 0,
	int		height = 0,
	bool	bHideCancelBtn = true
);

Parameters

pString

Specifies a pointer that receives the user's input to the string.

nMaxCount

Specifies the size of the buffer that pString points to, which limits the length of the user's input. The size of the buffer includes the character ‘\0' that represents the end of the string. When multiple lines of input are allowed, the return that the user types occupies two characters.

pPrompt

Specify the prompt information that appears in the dialog box. '\n' can be used in the prompt message. InputBox's height automatically expands as to how much the message content is prompted. If the value is NULL, no prompt information is displayed.

pTitle

Specify the title bar of InputBox. If NULL, the name of the application is displayed.

pDefault

Specify the default value that appears in the user input area.

width

Specifies the width of InputBox (excluding borders), with a minimum of 200 pixels. If 0, the default width is used.

height

Specifies the height of InputBox (excluding borders). If 0 indicates automatic height calculation, the user input box is only allowed to enter one line, and the input is confirmed by "enter". If it is greater than 0, the height of the user input box automatically expands, allowing you to enter multiple lines of content, and confirms the input information by pressing "ctrl + enter".

bHideCancelBtn

Specify whether to hide the cancel button to prevent the user from canceling the input. If true, InputBox has only one OK button, no close button, and pressing ESC is not valid. if false, InputBox has OK and Cancel buttons that allow the user click close button and press ESC to close the window.

Return Value

Returns whether the user has input. If the user presses OK, returns true, and if the user presses Cancel, returns false.

Examples

The following code prompts the user to enter the radius of the circle and draw the circle:

// Compilation environment: VC2008 and above, Unicode character set.
//
#include <graphics.h>
#include <conio.h>

int main()
{
	// Initialize the graphics window
	initgraph(640, 480);

	// Define string buffers and receive user input
	wchar_t s[10];
	InputBox(s, 10, L"Please enter the radius");

	// Convert user input to numbers
	int r = _wtoi(s);

	// Draw a circle
	circle(320, 240, r);

	// Press any key to exit
	_getch();
	closegraph();

	return 0;
}
(贡献者:Krissi  编辑