win32 sdk inputbox 输入框
来源:互联网 发布:python培训视频 编辑:程序博客网 时间:2024/05/16 15:59
//InputDialog.cpp #include "StdAfx.h"#include ".\inputdialog.h"CInputDialog::CInputDialog(void){}CInputDialog::~CInputDialog(void){} LRESULT CALLBACK InputBoxWndProc(HWND WndHandle, UINT Message, WPARAM wParam, LPARAM lParam){static InputBoxStringType *Results = 0;static HWND InputLabelHandle = 0;static HWND InputHandle = 0;switch(Message){case WM_NCCREATE:{Results = (InputBoxStringType*)((CREATESTRUCT*)lParam)->lpCreateParams;break;}case WM_CLOSE:case WM_DESTROY:{PostQuitMessage(0);break;}case WM_COMMAND:{int NotifyCode = HIWORD(wParam);int ControlId = LOWORD(wParam);HWND ControlHandle = (HWND)lParam;switch(ControlId){case 1001:{InputHandle = ControlHandle;break;}case 1002:{if(InputHandle == 0 || !Results){PostQuitMessage(0);break;}InputBoxCharPointerType Buffer = new InputBoxCharType[256]; GetWindowText(InputHandle, Buffer, 256);*Results = Buffer;PostQuitMessage(0);break;}case 1003:{if(InputHandle == 0 || !Results){PostQuitMessage(0);break;}*Results = InputBoxString("");PostQuitMessage(0);break;}}break;}}return DefWindowProc(WndHandle, Message, wParam, lParam);}InputBoxStringType CInputDialog::ShowInputBox(HWND OwnerWindowHandle, const InputBoxStringType &InputLabel, const InputBoxStringType &InputText, const InputBoxStringType &Title){//WNDCLASS WndClass;HWND DialogHandle = 0;HWND InputLabelHandle = 0;HWND InputHandle = 0;HWND OkButtonHandle = 0, CancelButtonHandle = 0;InputBoxStringType Result = InputBoxString("");//ZeroMemory(&WndClass, sizeof(WNDCLASS));//WndClass.hbrBackground = GetSysColorBrush(COLOR_3DFACE);//WndClass.hIcon = LoadIcon(0, IDI_APPLICATION);//WndClass.hCursor = LoadCursor(0, IDC_ARROW);//WndClass.hInstance = GetModuleHandle(0);//WndClass.lpszClassName = InputBoxString("InputBox");//WndClass.lpfnWndProc = InputBoxWndProc;WNDCLASSEX stdWndClass;RtlZeroMemory(&stdWndClass, sizeof(stdWndClass));stdWndClass.hCursor = LoadCursor(0,IDC_ARROW);stdWndClass.cbSize = sizeof(stdWndClass);stdWndClass.style = CS_HREDRAW|CS_VREDRAW;stdWndClass.lpfnWndProc = InputBoxWndProc;stdWndClass.hbrBackground = (HBRUSH)COLOR_WINDOWFRAME;stdWndClass.lpszClassName = InputBoxString("InputBox");stdWndClass.hInstance = GetModuleHandle(0);RegisterClassEx(&stdWndClass);//RegisterClass(&WndClass);int X = 0, Y = 0;int Width = 0, Height = 0;RECT TempRect;GetWindowRect(GetDesktopWindow(), &TempRect);Width = (int)((float)(TempRect.right - TempRect.left) * 0.25f);Height = 150;X = ((TempRect.right - TempRect.left) / 2) - (Width / 2);Y = ((TempRect.bottom - TempRect.top) / 2) - (Height / 2);DialogHandle = CreateWindowEx(0, InputBoxString("InputBox"), Title.c_str(), WS_OVERLAPPEDWINDOW , X, Y, Width, Height, OwnerWindowHandle, 0, GetModuleHandle(0), (LPVOID)&Result);int LabelX = 5, LabelY = 5;int LabelWidth = InputLabel.length()* 20, LabelHeight = 24;InputLabelHandle = CreateWindowEx(0, InputBoxString("STATIC"), InputLabel.c_str(), WS_CHILD | WS_VISIBLE, LabelX, LabelY, LabelWidth, LabelHeight, DialogHandle, 0, GetModuleHandle(0), 0);int TBoxX = 5, TBoxY = 29;int TBoxWidth = Width - 20, TBoxHeight = 24;InputHandle = CreateWindowEx(0, InputBoxString("EDIT"), InputText.c_str(), WS_BORDER | WS_CHILD | WS_VISIBLE, TBoxX, TBoxY, TBoxWidth, TBoxHeight, DialogHandle, (HMENU)1001, GetModuleHandle(0), 0);int OkBtnX = (Width / 2) - 75, OkBtnY = Height - 60;int OkBtnWidth = 75, OkBtnHeight = 24;OkButtonHandle = CreateWindowEx(0, InputBoxString("BUTTON"), InputBoxString("确定"), WS_CHILD | WS_VISIBLE, OkBtnX, OkBtnY, OkBtnWidth, OkBtnHeight, DialogHandle, (HMENU)1002, GetModuleHandle(0), 0);int CancelBtnX = (Width / 2) + 25, CancelBtnY = Height - 60;int CancelBtnWidth = 75, CancelBtnHeight = 24;CancelButtonHandle = CreateWindowEx(0, InputBoxString("BUTTON"), InputBoxString("取消"), WS_CHILD | WS_VISIBLE, CancelBtnX, CancelBtnY, CancelBtnWidth, CancelBtnHeight, DialogHandle, (HMENU)1003, GetModuleHandle(0), 0);if(!DialogHandle)return Result;//在桌面显示窗口ShowWindow(DialogHandle,SW_SHOWNORMAL);//刷新窗口客户区UpdateWindow(DialogHandle);MSG msg;ZeroMemory(&msg,sizeof(msg));while(msg.message != WM_QUIT){if(GetMessage(&msg, 0, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}}return Result;}
//InputDialog.h#pragma once#include <windows.h>#include <string>#ifdef UNICODEtypedef std::wstring InputBoxStringType;typedef LPWSTR InputBoxCharPointerType;typedef wchar_t InputBoxCharType;#define InputBoxString(x) L##x#elsetypedef std::string InputBoxStringType;typedef LPSTR InputBoxCharPointerType;typedef char InputBoxCharType;#define InputBoxString(x) x#endifclass CInputDialog{public:CInputDialog(void);~CInputDialog(void);InputBoxStringType CInputDialog::ShowInputBox(HWND OwnerWindowHandle, const InputBoxStringType &InputLabel, const InputBoxStringType &InputText, const InputBoxStringType &Title);};
//test#include "InputDialog.h" int _tmain(int argc, _TCHAR* argv[]){CInputDialog dlg;InputBoxStringType Result = dlg.ShowInputBox(0, L"请输入密码:", L"Unknown", L"91wan程序保护");MessageBox(0, Result.c_str(), L"Your name is:", MB_OK);return 0;}
- win32 sdk inputbox 输入框
- MFC InputBox 输入框
- C#输入框InputBox问题
- 通过消息实现自定义输入框(InputBox)
- VBScript实现inputbox多输入框和inputbox和checkbox框
- ZT:通过消息实现自定义输入框(InputBox)
- delphi InputBox输入密码用*代替,怎样让delphi的inputbox输入框显示密码代表符*
- C# inputBox文字输入对话框
- .net C# inputBox文字输入对话框,类似delphi的inputBox
- .net C# inputBox文字输入对话框,类似delphi的inputBox
- C# inputBox文字输入对话框,类似delphi的inputBox
- vb.net 判断inputbox中输入信息
- inputbox输入带星号的内容
- 数据输入——inputbox函数
- .net C# inputBox文字输入对话框,类似delphi的inputBox收藏
- [Win32]Win32 SDK编程系列文章——鼠标输入消息
- C#实现VB6.0的输入窗体InputBox代码
- format,inputbox,格式,输入窗口,判断后自动赋值
- 20130419-Linux试玩随笔-03-安装mysql
- 20130426-Linux试玩随笔-04-CentOS安装
- 20130426-常用站点收藏
- 20130502-Linux试玩随笔-05-Github
- 20130515-Grails In Action-3、建模(01小节)
- win32 sdk inputbox 输入框
- 20130515-Grails In Action-3、建模(02小节)
- 20130515-Grails In Action-3、建模(03小节)
- 20130515-Grails In Action-3、建模(04小节)
- 20130515-Grails In Action-3、建模(05小节)
- 20130516-Grails In Action-3、建模(06小节)
- dp之一维的最大字段和算法
- 20130516-Grails In Action-4、让模型工作(01小节)
- 20130516-Grails In Action-4、让模型工作(02小节)