简体   繁体   English

C++ 本机 Win32 简单编辑控件

[英]C++ Native Win32 simple Edit Control

I'm currently experimenting with making a little native Win32 executable.我目前正在尝试制作一个小的本地 Win32 可执行文件。 So no external libraries/wrappers/frameworks.所以没有外部库/包装器/框架。 I added a simple edit control and a button.我添加了一个简单的编辑控件和一个按钮。 The problem is that I can't change the text of an Edit Control in the Properties window of Visual Studio.问题是我无法在 Visual Studio 的属性窗口中更改编辑控件的文本。 The default text is Sample edit box and that doesn't show up in the Properties window (IDC_EDIT1), so I can't change it.默认文本是Sample edit box ,它不会显示在“属性”窗口 (IDC_EDIT1) 中,因此我无法更改它。

How can I change the text of an Edit Control (preferably within the properties window)?如何更改编辑控件的文本(最好在属性窗口中)? Also, is an edit control part of the MFC library?另外,编辑控件是 MFC 库的一部分吗?

Visual Studio's Properties window is part of the graphical UI to create and modify Resource Files . Visual Studio 的属性窗口是图形 UI 的一部分,用于创建和修改资源文件 Resource files are used, among other things, to store dialog templates, including the dialog's child controls.除其他外,资源文件用于存储对话框模板,包括对话框的子控件。 Since the EDITTEXT resource statement doesn't allow for an initial text entry, you cannot statically set one.由于EDITTEXT资源语句不允许初始文本条目,因此您不能静态设置一个。 You will have to set the control text at runtime, either by using the Edit_SetText macro, or by calling SetWindowText directly.您必须在运行时设置控件文本,方法是使用Edit_SetText宏或直接调用SetWindowText

The Edit Control is a standard Windows control, not part of MFC. 编辑控件是标准的 Windows 控件,不是 MFC 的一部分。 MFC provides a wrapper class, CEdit , like it does for all other standard controls. MFC 提供了一个包装类CEdit ,就像它为所有其他标准控件所做的那样。

In your dialog window function use this construct to set text for your control (given its id is ID_BUTTON)在您的对话框窗口函数中,使用此构造为您的控件设置文本(鉴于其 ID 为 ID_BUTTON)

BOOL CALLBACK  DialogProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
     switch (iMsg)
     {
          case WM_INITDIALOG :
               SetDlgItemText ( hDlg, ID_BUTTON, "Button Text" );
               return TRUE ;
     }
     return FALSE ;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM