#ifndef __03022006__WIN32INPUTBOX__
#define __03022006__WIN32INPUTBOX__ /* This library is (c) Elias Bachaalany aka lallous <lallousx86@yahoo.com>
You may use this library under the following license agreement: The zlib/libpng License.
---------------------------
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications,
and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. */ #include <windows.h>
#include <tchar.h> class CWin32InputBox; // Structure used to orient the inputbox behavior
struct WIN32INPUTBOX_PARAM
{
friend class CWin32InputBox; //
IN OPTIONAL bool bMultiline; // Pass this as none zero so to use this memory dlg template
IN OPTIONAL LPVOID DlgTemplateData; // Pass this as none ZERO so to load DLGTEMPLATE from resources
IN OPTIONAL LPCTSTR DlgTemplateName; // passing both "DlgTemplateName" and "DlgTemplateData" ZERO will cause
// the dialog to use his default embedded resource // Center on monitor or owner window?
IN OPTIONAL bool bCenter; // Want to add more styles to the dialog?
IN OPTIONAL DWORD dwStylesPlus, dwStylesMinus;
IN OPTIONAL DWORD dwExStylesPlus, dwExStylesMinus; IN LPCTSTR szTitle, szPrompt; // Return buffer
OUT LPTSTR szResult;
IN DWORD nResultSize; // Owner window
HWND hwndOwner;
HINSTANCE hInstance; short xPos, yPos; WIN32INPUTBOX_PARAM();
private:
HWND hDlg;
}; class CWin32InputBox
{
private:
WIN32INPUTBOX_PARAM *_param;
static LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
HWND _hwndEditCtrl; void InitDialog();
void SetParam(WIN32INPUTBOX_PARAM *);
WIN32INPUTBOX_PARAM * GetParam(); public: CWin32InputBox(WIN32INPUTBOX_PARAM *);
~CWin32InputBox(); static INT_PTR InputBoxEx(WIN32INPUTBOX_PARAM *);
static INT_PTR InputBox(
LPCTSTR szTitle,
LPCTSTR szPrompt,
LPTSTR szResult,
DWORD nResultSize,
bool bMultiLine = false,
HWND hwndParent = );
}; #endif
#include "Win32InputBox.h"
#include <stdio.h> #pragma warning (disable: 4312) /*
History
----------
03/02/2006
- Initial version development 03/04/2006
- Lessened the complexity of the class, made it less generic (since its purpose is to be simple)
- Updated the dialog template and made OK button as default button */ typedef struct _MSDN_DLGTEMPLATEEX
{
WORD dlgVer;
WORD signature;
DWORD helpID;
DWORD exStyle;
DWORD style;
WORD cDlgItems;
short x;
short y;
short cx;
short cy;
BYTE _rest[]; // rest of structure
} MSDN_DLGTEMPLATEEX; static bool IsDlgTemplateExtended(DLGTEMPLATE *dlgTemplate)
{
MSDN_DLGTEMPLATEEX *dgExTemplate = (MSDN_DLGTEMPLATEEX *) dlgTemplate; // MSDN excerpt:
//* dlgVer
// Specifies the version number of the extended dialog box template. This member must be 1.
//* signature
// Indicates whether a template is an extended dialog box template.
// If signature is 0xFFFF, this is an extended dialog box template.
// In this case, the dlgVer member specifies the template version number.
// If signature is any value other than 0xFFFF, this is a standard dialog box template that uses the DLGTEMPLATE and DLGITEMTEMPLATE structures. return (dgExTemplate->dlgVer == ) && (dgExTemplate->signature == 0xFFFF);
} // Use alignment if supported by the compiler
#ifdef _MSC_VER
#if _MSC_VER > 1200
__declspec(align())
#endif
#endif // per the MSDN, the DLGTEMPLATE must be DWORD aligned
// this was generated by the DlgResToDlgTemplate tool
static unsigned char definputbox_dlg[] =
{
0x01,0x00,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc8,0x00,0xc8,0x00,0x06,
0x00,0x16,0x00,0x11,0x00,0xe7,0x00,0x6d,0x00,0x00,0x00,0x00,0x00,0x57,0x00,0x69,
0x00,0x6e,0x00,0x33,0x00,0x32,0x00,0x49,0x00,0x6e,0x00,0x70,0x00,0x75,0x00,0x74,
0x00,0x42,0x00,0x6f,0x00,0x78,0x00,0x00,0x00,0x08,0x00,0xbc,0x02,0x00,0x00,0x4d,
0x00,0x53,0x00,0x20,0x00,0x53,0x00,0x68,0x00,0x65,0x00,0x6c,0x00,0x6c,0x00,0x20,
0x00,0x44,0x00,0x6c,0x00,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0x00,0x02,0x50,0x06,0x00,0x04,0x00,0x9d,0x00,0x21,0x00,0xe8,
0x03,0x00,0x00,0xff,0xff,0x82,0x00,0x50,0x00,0x72,0x00,0x6f,0x00,0x6d,0x00,0x70,
0x00,0x74,0x00,0x3a,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x80,0x00,0x81,0x50,0x06,0x00,0x25,0x00,0xd8,0x00,0x0e,0x00,0xe9,
0x03,0x00,0x00,0xff,0xff,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x84,0x10,0xa1,0x50,0x06,0x00,0x37,0x00,0xd8,0x00,0x31,0x00,0xea,
0x03,0x00,0x00,0xff,0xff,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x00,0x03,0x50,0xab,0x00,0x04,0x00,0x33,0x00,0x0e,0x00,0x01,
0x00,0x00,0x00,0xff,0xff,0x80,0x00,0x4f,0x00,0x4b,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x50,0xab,0x00,0x15,0x00,0x33,
0x00,0x0e,0x00,0x02,0x00,0x00,0x00,0xff,0xff,0x80,0x00,0x43,0x00,0x41,0x00,0x4e,
0x00,0x43,0x00,0x45,0x00,0x4c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x00,0x27,0x00,0x08,0x00,0x08,0x00,0xff,
0xff,0xff,0xff,0xff,0xff,0x82,0x00,0x00,0x00,0x00,0x00
}; static LPCTSTR definputbox_buttonnames[] = { _T("OK"), _T("CANCEL") };
static const INT_PTR definputbox_buttonids[] = { IDOK, IDCANCEL }; static const INT
definputbox_id_prompt = ,
definputbox_id_edit1 = ,
definputbox_id_edit2 = ; WIN32INPUTBOX_PARAM::WIN32INPUTBOX_PARAM()
{
bMultiline = false;
hwndOwner = ;
DlgTemplateName = ;
hInstance = (HINSTANCE) ::GetModuleHandle();
DlgTemplateData = definputbox_dlg; bCenter = true; dwStylesPlus = ;
dwExStylesPlus = ;
dwStylesMinus = 0xFFFFFFFF;
dwExStylesMinus = 0xFFFFFFFF; xPos = yPos = -; szResult = ;
nResultSize = ;
} CWin32InputBox::CWin32InputBox(WIN32INPUTBOX_PARAM *param)
{
_param = param;
} CWin32InputBox::~CWin32InputBox()
{ } void CWin32InputBox::SetParam(WIN32INPUTBOX_PARAM *param)
{
_param = param;
} WIN32INPUTBOX_PARAM *CWin32InputBox::GetParam()
{
return _param;
} INT_PTR CWin32InputBox::InputBoxEx(WIN32INPUTBOX_PARAM *param)
{
// Check mandatory parameters
if (param->szResult == )
{
::SetLastError(ERROR_INVALID_PARAMETER);
return ;
} LPDLGTEMPLATE dlgTemplate; if (param->DlgTemplateName != )
{
HMODULE hModule = (HMODULE)param->hInstance;
HRSRC rcDlg = ::FindResource(hModule, MAKEINTRESOURCE(param->DlgTemplateName), RT_DIALOG);
if (rcDlg == NULL)
return ; HGLOBAL hglobalDlg = ::LoadResource(hModule, rcDlg);
if (hglobalDlg == NULL)
return ; dlgTemplate = (LPDLGTEMPLATE) hglobalDlg;
}
else if (param->DlgTemplateData != )
{
dlgTemplate = (LPDLGTEMPLATE) param->DlgTemplateData;
} MSDN_DLGTEMPLATEEX *dlgTemplateEx =
IsDlgTemplateExtended((LPDLGTEMPLATE) dlgTemplate) ? (MSDN_DLGTEMPLATEEX *) dlgTemplate : ; if (dlgTemplateEx != )
{
dlgTemplateEx->exStyle |= param->dwExStylesPlus;
dlgTemplateEx->style |= param->dwStylesPlus;
dlgTemplateEx->exStyle &= param->dwExStylesMinus;
dlgTemplateEx->style &= param->dwStylesMinus; if (param->bCenter)
dlgTemplateEx->style |= DS_CENTER; if (param->xPos != -)
dlgTemplateEx->x = param->xPos;
if (param->yPos != -)
dlgTemplateEx->y = param->yPos;
}
else
{
dlgTemplate->dwExtendedStyle |= param->dwExStylesPlus;
dlgTemplate->style |= param->dwStylesPlus;
dlgTemplate->dwExtendedStyle &= param->dwExStylesMinus;
dlgTemplate->style &= param->dwStylesMinus; if (param->bCenter)
dlgTemplate->style |= DS_CENTER; if (param->xPos != -)
dlgTemplate->x = param->xPos; if (param->yPos != -)
dlgTemplate->y = param->yPos;
} CWin32InputBox inputbox(param); // Resize dialog and SHOW or HIDE multiline
INT_PTR r = ::DialogBoxIndirectParam(param->hInstance, dlgTemplate, param->hwndOwner, (DLGPROC)DlgProc, (LPARAM)&inputbox); return r;
} INT_PTR CWin32InputBox::InputBox(
LPCTSTR szTitle,
LPCTSTR szPrompt,
LPTSTR szResult,
DWORD nResultSize,
bool bMultiLine,
HWND hwndParent)
{
WIN32INPUTBOX_PARAM param; param.szTitle = szTitle;
param.szPrompt = szPrompt;
param.szResult = szResult;
param.nResultSize = nResultSize;
param.bMultiline = bMultiLine; return InputBoxEx(&param);
} void CWin32InputBox::InitDialog()
{
// Set the button captions
for (size_t i=;i<sizeof(definputbox_buttonids)/sizeof(definputbox_buttonids[]);i++)
::SetDlgItemText(_param->hDlg, (int) definputbox_buttonids[i], definputbox_buttonnames[i]); // Set other controls
::SetWindowText(_param->hDlg, _param->szTitle);
::SetDlgItemText(_param->hDlg, definputbox_id_prompt, _param->szPrompt); HWND hwndEdit1 = ::GetDlgItem(_param->hDlg, definputbox_id_edit1);
HWND hwndEdit2 = ::GetDlgItem(_param->hDlg, definputbox_id_edit2); if (_param->bMultiline)
_hwndEditCtrl = hwndEdit2;
else
_hwndEditCtrl = hwndEdit1; ::SetWindowText(_hwndEditCtrl, _param->szResult); RECT rectDlg, rectEdit1, rectEdit2; ::GetWindowRect(_param->hDlg, &rectDlg);
::GetWindowRect(hwndEdit1, &rectEdit1);
::GetWindowRect(hwndEdit2, &rectEdit2); if (_param->bMultiline)
{
::ShowWindow(hwndEdit1, SW_HIDE);
::SetWindowPos(
hwndEdit2,
HWND_NOTOPMOST,
rectEdit1.left - rectDlg.left,
(rectEdit1.top - rectDlg.top) - (rectEdit1.bottom - rectEdit1.top),
,
,
SWP_NOSIZE | SWP_NOZORDER); ::SetWindowPos(
_param->hDlg,
HWND_NOTOPMOST,
,
,
rectDlg.right - rectDlg.left,
rectDlg.bottom - rectDlg.top - (rectEdit1.bottom - rectEdit1.top),
SWP_NOMOVE); }
else
{
::SetWindowPos(
_param->hDlg,
HWND_NOTOPMOST,
,
,
rectDlg.right - rectDlg.left,
rectEdit1.bottom - rectDlg.top + ,
SWP_NOMOVE); ::ShowWindow(hwndEdit2, SW_HIDE);
}
} // Message handler for about box.
LRESULT CALLBACK CWin32InputBox::DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
CWin32InputBox *_this = (CWin32InputBox *) ::GetWindowLong(hDlg, GWL_USERDATA);
WIN32INPUTBOX_PARAM *param = _this ? _this->GetParam() : ; switch (message)
{
case WM_INITDIALOG:
{
::SetWindowLong(hDlg, GWL_USERDATA, (LONG) lParam); _this = (CWin32InputBox *) lParam;
_this->_param->hDlg = hDlg;
_this->InitDialog();
return TRUE;
} case WM_COMMAND:
{
#ifdef _MY_DEBUG
CHAR buf[];
static int i=;
sprintf(buf, "WM_COMMAND: %09d wParam=%08X lParam=%08X\n", i++, wParam, lParam);
OutputDebugString(buf);
#endif
INT_PTR buttonId = LOWORD(wParam);
for (size_t i=;
i<sizeof(definputbox_buttonids)/sizeof(definputbox_buttonids[]);
i++)
{
if (buttonId == definputbox_buttonids[i])
{
::GetWindowText(
_this->_hwndEditCtrl,
_this->_param->szResult,
_this->_param->nResultSize); ::EndDialog(hDlg, buttonId);
return TRUE;
}
}
}
break;
}
return FALSE;
}

Win32InputBox,C接口的,实现类似VB的InputBox的功能的更多相关文章

  1. js 实现类似php函数number_format的功能

    今天同事在做一个功能的时候需要使用js来实现类似php函数number_format的功能,最后就有了下面的方法,可以实现了: /** * number_format * @param number ...

  2. SharePoint 2010 类似人人网站内信功能实施

    简介:用SharePoint代码加实施的方式,完成类似人人网站内信功能,当然,实现的比较简单,样式也比较难看,只为给大家一个实施的简单思路,如有谬误,还请见谅.当然,还有就是截图比较长,当然为了让大家 ...

  3. MVC实现类似QQ的网页聊天功能-ajax(下)

    此篇文章主要是对MVC实现类似QQ的网页聊天功能(上)的部分代码的解释. 首先说一下显示框的滚动条置底的问题: 结构很简单一个大的div(高度一定.overflow:auto)包含着两个小的div第一 ...

  4. springmvc+ztree v3实现类似表单回显功能

    在做权限管理系统时,可能会用到插件zTree v3,这是一个功能丰富强大的前端插件,应用很广泛,如异步加载菜单制作.下拉选择.权限分配等.在集成SpringMVC中,我分别实现了zTree的添删改查, ...

  5. 大数据学习day15----第三阶段----scala03--------1.函数(“_”的使用, 函数和方法的区别)2. 数组和集合常用的方法(迭代器,并行集合) 3. 深度理解函数 4 练习(用java实现类似Scala函数式编程的功能(不能使用Lambda表达式))

    1. 函数 函数就是一个非常灵活的运算逻辑,可以灵活的将函数传入方法中,前提是方法中接收的是类型一致的函数类型 函数式编程的好处:想要做什么就调用相应的方法(fliter.map.groupBy.so ...

  6. VS "15" 预览 5 中 VB 15 新增的功能

    VS "15" 预览 5 给 VB 带来了更新.这次的更新内容有3个: * 值元组 ValueTuple这个功能能把一组计算结果成组返回.为了使用这个功能,我们要安装 System ...

  7. 【VB技巧】VB ListView 控件功能使用详解

    来源:http://lcx.cc/?i=494 ListView控件 在工具箱上击鼠标右键,选择快捷菜单的Components(部件)项,在控件列表中选择Microsoft Windows Commo ...

  8. Python 清理HTML标签类似PHP的strip_tags函数功能(二)

    没有发现Python 有现成的类似功能模块,所以昨天写了个简单的 strip_tags 但还有些问题,今天应用到采集上时进行了部分功能的完善, 1. 对自闭和标签处理 2. 以及对标签参数的过滤 fr ...

  9. JMeter实现登录初始化(类似LR的init函数功能实现)

    1.项目背景 在做项目的性能测试过程中,发现系统的登录功能非常慢,所以,在涉及到登录才能操作的场景,尽量避开登录操作 解决方案: 首选设置“登录并生成签名值”线程组

随机推荐

  1. vue项目1-pizza点餐系统5-全局守卫

    一.导航守卫描述 当问我们点击主页.菜单等非登陆和注册按钮都会提示先登陆然后跳转到登陆界面. 1.在main.js中引入全局守卫 //全局守卫 //to是要进入那个路由,from是从那个路由出来,ne ...

  2. Android--ViewPager点击按钮切换下一页

    不再重写一遍了,看csdn: https://blog.csdn.net/qq_42866164/article/details/101346058

  3. ntsysv - 用于配置运行级别的简单接口

    总览 SYNOPSIS ntsysv [--back] [--level <levels>] 描述 DESCRIPTION ntsysv 是个用于配置运行级别服务(也可通过 chkconf ...

  4. Codeforces Round #430 (Div. 2) - B

    题目链接:http://codeforces.com/contest/842/problem/B 题意:给定一个圆心在原点(0,0)半径为r的大圆和一个圆内的圆环长度d,然后给你n个小圆,问你有多少个 ...

  5. Tengine 补充

    Tengine 补充 开机启动 chkconfig --list chkconfig --add nginx chkconfig nginx on 时间问题 service ntpd status 虚 ...

  6. IsDate(expression)函数

    IsDate 函数 返回 Boolean 值指明某表达式是否可以转换为日期. IsDate(expression) expression 参数可以是任意可被识别为日期和时间的日期表达式或字符串表达式. ...

  7. 用element-ui进行文件的上传

    在进项的项目中,我使用vue配合element搭建的项目,现在需要用到上传文件的写法!现在列举下我的项目中所使用的上传文件的方法! <el-upload style="display: ...

  8. 安装了sql-alchemy但导入sql_alchemy时失败

    问题描述:按成flask-sqlalchemy成功了,但是项目导入flask_alchemy时出错 但是,发现在代码中还是导入不了 之后发现问题,到file->setting->proje ...

  9. 失控的未来交通工具 (LOJ 508,带权并查集,数论)

    LOJ 508 失控的未来交通工具 (带权并查集 + 数论) $ solution: $ 很综合的一道难题.看了让人不知所措,数据范围又大,题目描述又不清晰.只能说明这道题有很多性质,或者很多优化. ...

  10. 用户界面控件Telerik UI for WinForms发布R2 2019|附下载

    Telerik UI for WinForms拥有适用Windows Forms的110多个令人惊叹的UI控件.所有的UI for WinForms控件都具有完整的主题支持,可以轻松地帮助开发人员在桌 ...