Here is the stand alone implementation that I use:
Code:
#include <windows.h>
#include "resource.h"
//Global variables
int QueryLen;
char *QueryCaption, *QueryText, *QueryDst;
BOOL CALLBACK QueryDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
SetWindowText(hwndDlg, QueryCaption);
SetDlgItemText(hwndDlg, IDC_QUERY_TEXT, QueryText);
SetDlgItemText(hwndDlg, IDC_QUERY_EDIT, QueryDst);
return TRUE;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDOK:
{
GetWindowText(GetDlgItem(hwndDlg, IDC_QUERY_EDIT), QueryDst, QueryLen);
EndDialog(hwndDlg, IDOK);
return TRUE;
}
case IDCANCEL:
{
EndDialog(hwndDlg, IDCANCEL);
return TRUE;
}
}
}
}
return FALSE;
}
bool InputBox(char *caption, char *text, char *dst, int len)
{
QueryCaption = caption;
QueryText = text;
QueryDst = dst;
QueryLen = len;
return (DialogBox(0, MAKEINTRESOURCE(IDD_DLG_QUERY), 0, QueryDlgProc) == IDOK);
}
This is the code for the dialog:
Code:
IDD_DLG_QUERY DIALOGEX 0, 0, 186, 90
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,129,7,50,14
PUSHBUTTON "Cancel",IDCANCEL,129,24,50,14
LTEXT "Destination:",IDC_QUERY_TEXT,14,22,111,18
EDITTEXT IDC_QUERY_EDIT,15,52,155,15,ES_AUTOHSCROLL
END
And of course your resource.h should have:
Code:
#define IDD_DLG_QUERY 1
#define IDC_QUERY_TEXT 1001
#define IDC_QUERY_EDIT 1002
You can use the function like this:
Code:
char caption[MAX_PATH];
strcpy(caption, "caption text");
if (InputBox("Set Caption", "Title:", caption, sizeof(caption)))
{
MessageBox(0, caption, caption, 0);
}