有类似MessageBox但是可以有一个输入文本框的吗?

VB里面有,但是我用的是VC。就和MessageBox差不多,就多了一个可以输入内容的文本框。麻烦各位了。急用。... VB里面有,但是我用的是VC。就和MessageBox差不多,就多了一个可以输入内容的文本框。麻烦各位了。急用。 展开
 我来答
ACde卡卡88888
推荐于2016-03-01 · TA获得超过135个赞
知道答主
回答量:91
采纳率:0%
帮助的人:46万
展开全部
!下面是一个例子:

/* 注意,InputBox函数是C++语法,只能用于C++,不能用于C */

/********************************************/
/* InputBox.h */
/********************************************/
BOOL _InitInputBox(HWND hParent); // 可选,不过在调用InputBox函数之前最好调用一下该函数,
// 该函数是初始化InputBox,主要就是传入一个父窗口句柄。
void _SetNumber(BOOL fIsNumber); // 可选,该函数是设置Edit只能输入数字
void _SetLowerCase(BOOL fIsLowerCase); // 可选,该函数是设置Edit只能输入小写字母
void _SetUpperCase(BOOL fIsUpperCase); // 可选,该函数是设置Edit只能输入大写字母
void _SetMaxLine(unsigned int nLineSize); // 可选,该函数是设置Edit可以输入最大字符数,默认最大是256个字符,不能超过这个数。

/*********************************************************/
/* InputBox函数 */
/* lpWndMsg ; 必选参数,用于提示用户 */
/* lpWndTitle ; 可选参数, 设置对话框默认标题 */
/* lpDefValue ; 可选参数,设置Edit默认值 */
/* xPos ; 可选参数,如果为零则居中窗口 */
/* yPos ; 可选参数,如果为零则居中窗口 */
/* lpHelpFile ; 可选参数,打开*.hlp帮助文件 */
/* nHelpIndex ; 可选参数,但如果设置了lpHelpFile参数, */
/* ; 这个参数就是Help文件的索引 */
/* 如果函数成功,返回一个char *指针,包含用户输入的内容 */
/*********************************************************/
char *_InputBox(char *lpWndMsg,
char *lpWndTitle = "工程!",
char *lpDefValue = "",
int xPos = 0,
int yPos = 0,
char *lpHelpFile = "",
int nHelpIndex = 0);

#define InputBox _InputBox
#define SetNumber _SetNumber
#define InitInputBox _InitInputBox
#define SetLowerCase _SetLowerCase
#define SetUpperCase _SetUpperCase
#define SetMaxLine _SetMaxLine

/******************************************************/
/* InputBox.cpp */
/******************************************************/
#include <windows.h>

int WINAPI WndProc(HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
BOOL _InitVar();
HWND _CreateWindow(HINSTANCE hInst);
int _Run(HWND hWnd);

HINSTANCE _hInstance;
char *_lpWndMsg;
char *_lpWndTitle;
char *_lpDefValue;
int _xPos;
int _yPos;
char *_lpHelpFile;
int _nHelpIndex;
HWND _hParent;
HWND _hDesktop;
HWND _hEdit, _hBtnOk, _hBtnCancel, _hBtnHelp;
HWND _hMsgText;
RECT _st_rcDesktop;
RECT _st_rcWnd;
HFONT _hWndFont;
char _szBuffer[256];
char *_lpWndFontName = "宋体";
UINT _nMaxLine = 255;
UINT _nEditStyle = WS_BORDER | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL | ES_AUTOVSCROLL;

BOOL _InitInputBox(HWND hParent)
{
if (!hParent)
return FALSE;
_hParent = hParent;
if (!_hInstance)
return _InitVar();
return TRUE;
}

BOOL _InitVar()
{
_hInstance = ::GetModuleHandle(NULL);
_hDesktop = ::GetDesktopWindow();
::GetWindowRect(_hDesktop,&_st_rcDesktop);
if (!_xPos)
_xPos = (_st_rcDesktop.right - 365) / 2;
if (!_yPos)
_yPos = (_st_rcDesktop.bottom - 130) / 2;
return TRUE;
}

int WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hWndDc;
WORD uBtnID;
switch(uMsg)
{
case WM_DESTROY:
if (_hWndFont)
::DeleteObject(_hWndFont);
::PostQuitMessage(0);
break;
case WM_CREATE:
_hMsgText = ::CreateWindowEx(0,
"Static",
_lpWndMsg,
WS_CHILD | WS_VISIBLE,
5,
5,
275,
70,
hWnd,
(HMENU)1000,
_hInstance,
0);
_hBtnOk = ::CreateWindowEx(0,
"Button",
"确定(&K)",
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
285,
5,
65,
20,
hWnd,
(HMENU)IDOK,
_hInstance,
0);
_hBtnCancel = ::CreateWindowEx(0,
"Button",
"取消(&C)",
WS_CHILD | WS_VISIBLE,
285,
30,
65,
20,
hWnd,
(HMENU)IDCANCEL,
_hInstance,
0);
_hBtnHelp = ::CreateWindowEx(0,
"Button",
"帮助(&H)",
WS_CHILD | WS_VISIBLE,
285,
55,
65,
20,
hWnd,
(HMENU)IDHELP,
_hInstance,
0);
_hEdit = ::CreateWindowEx(WS_EX_CLIENTEDGE,
"Edit",
_lpDefValue,
_nEditStyle,
5,
80,
350,
20,
hWnd,
(HMENU)2000,
_hInstance,
0);
::SendMessage(_hEdit,EM_SETLIMITTEXT,_nMaxLine,0);
_hWndFont = ::CreateFont(12,
6,
0,
0,
12,
0,
0,
0,
GB2312_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH,
_lpWndFontName);
if (!::lstrlen(_lpHelpFile))
ShowWindow(_hBtnHelp,SW_HIDE);
hWndDc = ::GetDC(hWnd);
::SelectObject(hWndDc,_hWndFont);
::ReleaseDC(hWnd,hWndDc);
::SendDlgItemMessage(hWnd,1000,WM_SETFONT,(WPARAM)_hWndFont,0);
::SendDlgItemMessage(hWnd,2000,WM_SETFONT,(WPARAM)_hWndFont,0);
::SendDlgItemMessage(hWnd,IDOK,WM_SETFONT,(WPARAM)_hWndFont,0);
::SendDlgItemMessage(hWnd,IDCANCEL,WM_SETFONT,(WPARAM)_hWndFont,0);
::SendDlgItemMessage(hWnd,IDHELP,WM_SETFONT,(WPARAM)_hWndFont,0);
break;
case WM_KEYDOWN:
if (wParam == VK_RETURN)
::SendMessage(hWnd,WM_COMMAND,IDOK,0);
break;
case WM_SETFOCUS:
::SetFocus(_hEdit);
break;
case WM_COMMAND:
uBtnID = LOWORD(wParam);
switch(uBtnID)
{
case IDOK:
::GetDlgItemText(hWnd,2000,_szBuffer,256);
::DestroyWindow(hWnd);
break;
case IDCANCEL:
::DestroyWindow(hWnd);
break;
case IDHELP:
::WinHelp(hWnd,_lpHelpFile,HELP_INDEX,_nHelpIndex);
break;
};
break;
default:
return ::DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return (TRUE);
}

HWND _CreateWindow(HINSTANCE hInst)
{
WNDCLASSEX st_WndClass;
HWND hWnd;
::RtlZeroMemory(&st_WndClass,sizeof(st_WndClass));
st_WndClass.cbSize = sizeof(st_WndClass);
st_WndClass.hInstance = hInst;
st_WndClass.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
st_WndClass.hCursor = LoadCursor(0, IDC_ARROW);
st_WndClass.hIcon = LoadIcon(0, IDI_APPLICATION);
st_WndClass.hIconSm = st_WndClass.hIcon;
st_WndClass.lpfnWndProc = (WNDPROC)&WndProc;
st_WndClass.lpszClassName = "InputBox_Class";
st_WndClass.style = CS_HREDRAW | CS_VREDRAW;
::RegisterClassEx(&st_WndClass);
hWnd = ::CreateWindowEx(0,
"InputBox_Class",
_lpWndTitle,
WS_DLGFRAME | WS_SYSMENU | WS_VISIBLE,
_xPos,
_yPos,
365,
130,
_hParent,
0,
hInst,
0);
return hWnd;
}

int _Run(HWND hWnd)
{
MSG st_Msg;
if (!hWnd)
return 0;
::ShowWindow(hWnd,SW_SHOW);
::UpdateWindow(hWnd);
while(::GetMessage(&st_Msg,0,0,0))
{
if (st_Msg.message == WM_KEYDOWN)
{
if (st_Msg.wParam == VK_RETURN)
::SendMessage(hWnd,st_Msg.message,st_Msg.wParam,st_Msg.wParam);
}
::TranslateMessage (&st_Msg) ;
::DispatchMessage (&st_Msg) ;
}
return st_Msg.wParam;
}

char *_InputBox(char *lpWndMsg,
char *lpWndTitle,
char *lpDefValue,
int xPos,
int yPos,
char *lpHelpFile,
int nHelpIndex)
{
_lpWndMsg = lpWndMsg;
_lpWndTitle = lpWndTitle;
_lpDefValue = lpDefValue;
_xPos = xPos;
_yPos = yPos;
_lpHelpFile = lpHelpFile;
_nHelpIndex = nHelpIndex;
if (!_hInstance)
_InitVar();
_Run(_CreateWindow(_hInstance));
return _szBuffer;
}

void _SetNumber(BOOL fIsNumber)
{
if (fIsNumber)
_nEditStyle |= ES_NUMBER;
}
void _SetLowerCase(BOOL fIsLowerCase)
{
if (fIsLowerCase)
_nEditStyle |= ES_LOWERCASE;
}
void _SetUpperCase(BOOL fIsUpperCase)
{
if (fIsUpperCase)
_nEditStyle |= ES_UPPERCASE;
}
void _SetMaxLine(unsigned int nLineSize)
{
if (nLineSize)
if (nLineSize < _nMaxLine)
_nMaxLine = nLineSize;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式