如何在VC++中用纯代码生成按钮等控件?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在VC++中用纯代码生成按钮等控件?相关的知识,希望对你有一定的参考价值。

我用的是VC++ 6.0,知道可以在ApplicationWizard中生成MFC应用程序然后直接添加控件,但我想知道是否可以建议一个Win32 Application的空工程,添加一个C++ Source File,只靠写代码来生成一个按钮、文本框之类的控件?

我觉得既然一个窗体都可以靠纯代码生成,那么控件应该不成问题吧?如果能的话,如何来实现呢?

CuteEditor 6.0 在线html编辑器的领航者
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=144183
ComponentArt.Charting.WebChart.dll
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=144386
ComponentArt.Web.UI 2007.2源代码+实例+DLL
http://bbs.topsage.com/dispbbs_123_161434_1.html
ComponentArt.WebUI.2007.1破解DLL
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143055
ComponentArt.WebUI.2007.1源代码
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143224
ComponentArt.Web.UI.2006.2
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143212
ComponentArt.Web.UI.2006.2源代码
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143219
ComponentArt.Web.UI.2006.1
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=142983
Infragistics NetAdvantage for ASP.NET 2007 Vol 2
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159861
Infragistics NetAdvantage AppStylist 2007 Vol 2
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159859
Infragistics TestAdvantage WinForms 2007 For CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159870
Infragistics TestAdvantage WinForms 2007 for CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159868
Infragistics NetAdvantage for Windows Forms 2007 Vol 2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159863
Infragistics NetAdvantage 2007 for WPF
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159857
Infragistics NetAdvantage 2006 Vol2 CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159814
Infragistics NetAdvantage 2006 Vol2 for CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159854
Infragistics NetAdvantage 2006 Vol2 CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159814
ComponentOne Studio 2007 v1.5 for ASP.NET 2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159753
ComponentOne Studio 2007 v1.5 for ASP.NET 1.x
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159745
ComponentOne Studio 2006 v2 for ASP.NET 2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159739
ComponentOne Studio 2006 v2 for ASP.NET 1.x
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=159734
ComponentOne Studio for Mobile Devices 2007 v1.5 CLR1x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159812
ComponentOne Studio for Mobile Devices 2006 v2 CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159811
ComponentOne Studio for Mobile Devices 2006 v2 CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159807
ComponentOne Studio 2007 v1.5 for .NET CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159802
ComponentOne Studio 2007 v1.5 for .NET CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159798
ComponentOne Studio for .NET 2006 v2 CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159780
ComponentOne Studio for .NET 2006 v2 CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159777
ComponentOne Studio for ActiveX 2007 v1.5
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159727
ComponentOne Studio for ActiveX 2006 v2 CLR2
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159725
ComponentOne Studio for ActiveX 2006 v2 CLR1.x
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=159724
Telerik RadWindow for ASP.NET 2.0 v1.8.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156136
Telerik RadUpload for ASP.NET 2.0 v2.3.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156135
Telerik RadTreeView for ASP.NET 2.0 v6.2.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156134
Telerik RadTabStrip for ASP.NET 2.0 v3.5.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156132
Telerik RadToolbar for ASP.NET 2.0 v1.5.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156133
Telerik RadSplitter for ASP.NET 2.0 v1.2.2.1
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156131
Telerik RadSpell for ASP.NET 2.0 v3.1.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156130
Telerik RadRotator for ASP.NET 2.0 v2.6.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156129
Telerik RadPanelbar for ASP.NET 2.0 v4.2.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156128
Telerik RadMenu for ASP.NET 2.0 v4.2.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156127
Telerik RadInput for ASP.NET 2.0 v2.0.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156126
Telerik RadGrid for ASP.NET 2.0 v4.6.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156125
Telerik RadEditor for ASP.NET 2.0 v7.1.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156124
Telerik RadComboBox for ASP.NET 2.0 v2.7.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156122
Telerik RadDock for ASP.NET 2.0 v1.8.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156123
Telerik RadChart for ASP.NET 2.0 v3.2.1.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156121
Telerik RadCalendar for ASP.NET 2.0 v2.1.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156120
Telerik RadAjax for ASP.NET 2.0 v1.7.2.0
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=156119
telerik r.a.d.upload
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143044
telerik r.a.d.window
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=142980
telerik r.a.d ToolBar
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143077
telerik r.a.d.Chart
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143075
telerik r.a.d.combobox
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143048
DotNetBar for VS2005 6.8.0.1
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=144521
DotnetCharting 4.3破解DLL
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=144388
DotNET Charting WebForms
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=144461
dotnetCharting.WinForms
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=144455
TeeChart for .NET 3.2.2763.26084 完美DLL
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=165932
TeeChart for .NET 3.2.2699.17379 完美DLL
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=165929
DevExpress 7.3.4 完美破解DLL
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=165852
Dxperience 7.3.5 完美破解DLL
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=165851
DevExpress.LocalizationCHS.Dll
http://bbs.topsage.com/dispbbs_121_169983_1.html
NickLee.Web.UI
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=143052
SolpartWebControls
http://bbs.topsage.com/dispbbs.asp?boardID=123&ID=142981
AspNetPager 6.0 for ASP.NET 1.x 自定义分页控件
http://bbs.topsage.com/dispbbs_123_161692_1.html
AspNetPager 6.0 for ASP.NET 2.0 自定义分页控件
http://bbs.topsage.com/dispbbs_123_161696_1.html
数据操作类 Socut.Data.dll for .NET 2.0 v3.1
http://bbs.topsage.com/dispbbs_123_161867_1.html
数据操作类 Socut.Data.dll for .NET 1.x v3.1
http://bbs.topsage.com/dispbbs_123_161866_1.html
Developer Express for .NET v7.3.5.0全套完美无限制版
http://bbs.topsage.com/dispbbs.asp?boardID=121&ID=166512
参考技术A 窗口你应该会了吧?
那你直接在有窗口的情况下,
#define IDC_BUTTON1 1000

CButton m_Button
void OnMyButton();

添加消息相应函数
ON_BN_CLICKED(IDC_BUTTON1, OnMyButton)

CRect rect(0,0,100,100);
m_Button.Create("111", WS_CHILD | WS_VISIBLE | WS_TABSTOP , rect, this, IDC_BUTTON1 );

最后
void XXX::OnMyButton()

……
本回答被提问者采纳
参考技术B 有很多办法的。
楼上的算是一种办法
CWnd* wnd;
wnd.CreateEx(0,_T("BUTTON"),"xxx"...);
这也是一种办法。
参考技术C //类定义里
CButton m_btn ;

//类实现
if ( m_btn.Create(...) )

m_btn.MoveWindow(...);
m_btn.ShowWindow( SW_SHOW );

QT如何获得对话框中控件的指针?

QT如何获得对话框中控件的指针? 比如获得对话框中一个按钮的指针,VC中的GetDlgItem()可以实现该功能,QT中用什么函数呢。假设按钮是用qt creator拖入的,不是用代码创建的。

qt的ui其实在编译的时候也是生成了一个c++类的,生成类在ui_XXX.h 中,可以通过直接继承的方式来获取ui类里面各控件的指针。qt createor添加ui类时会自动生成一个如 Ui::MainWindow *ui这般的ui指针,通过ui指针即可访问对话框中的控件指针。 参考技术A

    QT界面都会有一个对应的ui指针,再通过ui执行控件的ObjectName,就是改空间的指针了。

    比如界面一个 QPushButton 的名称是 btn,则可以这样获取他的指针 ui->btn

    想改变它的text,可以如此 : ui->btn->setText("确定");

参考技术B 用ui->引用就行

以上是关于如何在VC++中用纯代码生成按钮等控件?的主要内容,如果未能解决你的问题,请参考以下文章

VC++如何改变按钮背景色

在VC6.0做的MFC程序,如何在BS中用浏览器打开

如何在VC++6.0下添加一个按钮控件

如何在VC++6.0下删除一个按钮控件?

VC++(MFC)中动态创建和管理按钮控件,怎么做?

在VC++如何使控件大小修改为规定的大小?