使用win32 API在列表框中添加项目 [英] Adding items in list box using win32 API

查看:442
本文介绍了使用win32 API在列表框中添加项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我在Win32 API中创建了一个列表框,如下所示

Sir, I have created a list box in Win32 API like this

// list1 is HWND variable
list1 = CreateWindow(L"LISTBOX", NULL, WS_CHILDWINDOW | WS_VISIBLE | LBS_STANDARD,10,150,330,200, hWnd, (HMENU)ID_LISTBOX,hInst, NULL);



它确实成功创建。为避免混淆,我使用了几个cplusplus文件。我在单独的头文件中创建了一个类,并在一个单独的cpp文件中定义它。通过使用头文件,我使用主cpp文件中的对象调用成员函数。



但问题是先生成员函数之一应该添加字符串到名单。我知道当一切都在同一个cpp文件中时,它可以通过SendMessage函数实现。由于我的班级是在不同的.cpp文件中,我不能这样做。



我尝试过:



1.通过在我的代码模块中包含的函数的前向声明之前添加我的变量,将list1作为全局变量。



当我这样做时,我得到未初始化的变量错误



2.是否已将变量移动到新的头文件并使其可供两个cpp文件访问



我收到多个变量声明错误



3.我需要类似变量的东西在其他地方使用和定义所以我使用了存储类(在这种情况下为extern)但是当使用extern时我在目标文件中得到一个奇怪的错误。我很安静确定目标文件不能被人类阅读所以我完全停止研究这个错误和外部变量的使用。




It does created successfully. To avoid confusion I've used several cplusplus files. I have created a class in the separate header file and defined it in a separate cpp file. By using the header file I've called the member functions using objects in my main cpp file.

But the problem is sir one of member function should add strings to the list. I know it can be achieved by SendMessage function when everything is in the same cpp file. Since my class is in the different .cpp file I can't do this.

What I have tried:

1. Made list1 as a global variable by adding my variable before the forward declarations of functions included in my code module.

When I do like this I am getting "uninitialized variable error"

2. Did moved the variable to a new header file and made it accessible to both cpp files

I got "Multiple declarations of variable" error

3. I need of something like the variable to be used and defined somewhere else so I made use of storage classes ("extern" in this case) but when using extern I get a strange error in the object file. I am quiet sure object file can't be read by humans so I did completely stopped researching aboout this error and the usage of extern variables.

Severity	Code	Description	Project	File	Line
Error	LNK2005	"struct HWND__ * list1" (?list1@@3PAUHWND__@@A) already defined in Portable Devices Manager.obj	 Portable Devices Manager	G:\Portable Devices Manager\Portable Devices Manager\ShortCutVirusKiller.obj	





请帮助我先生



Kindly help me with this sir please

推荐答案

  • 在头文件中将您的变量声明为 extern ,例如
// mylist.h
extern HWND  hwndMyList;





  • 只用一个来定义它rce文件,例如
  • // mylist.cpp
    // ...
    HWND hwndMyList;
    // ...





    • 在需要变量的所有其他来源中包含头文件
    • // foo.cpp
      #include "mylist.h"
      //...
      hwndMyList = CreateWindow(/*...*/);
      //... 


      这篇关于使用win32 API在列表框中添加项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆