简体   繁体   English

Win32 C ++从元素获取文本

[英]Win32 C++ getting text from elements

While this question has probably been asked a thousand times before (pretty sure of it I have read a thousand answers). 尽管这个问题可能已经被问了一千遍了(很确定的是,我已经阅读了一千个答案)。 I still don't get it. 我还是不明白。

Lets say I have a function that creates a ComboBox like this: 可以说我有一个创建像这样的ComboBox的函数:

  scopeComboSelector=CreateCombobox(hwnd,
                                    GetModuleHandle(0),
                                    CBS_DROPDOWNLIST,
                                    re,
                                    IDCC_DROPDOWNLIST_SCOPE_SELECTOR,
                                    _T("Scopes"));

Where "re" is a positioning rectangle. 其中“ re”是定位矩形。 And IDCC_DROPDOWNLIST_SCOPE_SELECTOR (pretty long name) is the id of the combobox. IDCC_DROPDOWNLIST_SCOPE_SELECTOR(长名称)是组合框的ID。 Now the point is, I can actually fill this "drop down select list" but I have no clue as how I can simply get the currently selected value as a string. 现在的要点是,我实际上可以填写此“下拉选择列表”,但是我不知道如何直接将当前选择的值作为字符串获取。

I have seen about 10 ways to do it, which all give errors straight away (need to Convert to LPWSTR -> fixing results in more terror). 我已经看到了大约10种方法,所有这些方法都会立即产生错误(需要转换为LPWSTR->解决更多错误的结果)。

Maybe I'm just to used to Java where one can simply say: 也许我只是习惯了Java,可以简单地说:

 textfield.getText();

How would one achieve this in Win32 C++ (microsoft visual studio)? 如何在Win32 C ++(Microsoft Visual Studio)中实现这一目标?

Edit 编辑

Code I've used: 我使用的代码:

  char userName[_MAX_PATH+1];
  GetDlgItemTextW(scopeComboSelector,
                  IDCC_DROPDOWNLIST_SCOPE_SELECTOR,
                 (LPWSTR)userName,
                  200);

Returns: userName == empty 返回:userName ==空

Update 更新资料

Now using: GetDlgItemText(). 现在使用:GetDlgItemText()。 Debugger tells me the value of userName = "" 调试器告诉我userName =“”的值

The documentation has a C style Windows 9x code example. 文档有一个C风格的Windows 9x代码示例。

You need simply to replace C with C++ and Windows 9x silly T macros with wchar_t and friends. 您只需要用wchar_t和好友用C ++和Windows 9x傻T宏替换C。

It's always a good idea to read the documentation. 阅读文档始终是一个好主意。

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

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