<font color=red>VC 的自定义类模块怎么写??</font> (100分)

  • 主题发起人 主题发起人 cat.yy
  • 开始时间 开始时间
比如做了一个类叫CLabel,并且在一个PROJECT里测试通过。
在另外一个PROJECT中,
选中FILE VIEW,
在Source Files上点击右键选Add files to folder将label.cpp加入,(文件最好和Project同目录)
在Header Files上点击右键选Add files to folder将label.h加入,(文件最好和Project同目录)
选中Classes,就可以看见CLabel类
在dlg的.h文件中加入#include "Label.h"
如果要将CLabel加入Class Wizard列表:
需要将project目录下的.clw用notepad打开修改一下例如
;
CLW file contains information for the MFC ClassWizard
[General Info]
Version=1
LastClass=CTotalDlg
LastTemplate=CDialog
NewFileInclude1=#include "stdafx.h"
NewFileInclude2=#include "Total.h"
NewFileInclude3=#include "Label.h"
ClassCount=3
Class1=CTotalApp
Class2=CTotalDlg
Class3=CLabel
ResourceCount=3
Resource2=IDD_TOTAL_DIALOG
Resource1=IDR_MAINFRAME
Resource3=IDD_TOTAL_DIALOG (Japanese)
[CLS:CTotalApp]
Type=0
HeaderFile=Total.h
ImplementationFile=Total.cpp
Filter=N
[CLS:CTotalDlg]
Type=0
HeaderFile=TotalDlg.h
ImplementationFile=TotalDlg.cpp
Filter=D
LastObject=CTotalDlg
BaseClass=CDialog
VirtualFilter=dWC

[DLG:IDD_TOTAL_DIALOG]
Type=1
ControlCount=3
Control1=IDOK,button,1342242817
Control2=IDCANCEL,button,1342242816
Control3=IDC_STATIC,static,1342308352
Class=CTotalDlg
[DLG:IDD_TOTAL_DIALOG (Japanese)]
Type=1
Class=CTotalDlg
ControlCount=44
Control1=IDC_st1,static,1342308865
Control2=IDC_st2,static,1342308865
Control3=IDC_st3,static,1342308865
Control4=IDC_st4,static,1342308865
Control5=IDC_label_11,static,1342308865
Control6=IDC_label_21,static,1342308865
Control7=IDC_label_31,static,1342308865
Control8=IDC_label_41,static,1342308865
Control9=IDC_label_51,static,1342308865
Control10=IDC_label_61,static,1342308865
Control11=IDC_label_71,static,1342308865
Control12=IDC_label_81,static,1342308865
Control13=IDC_label_91,static,1342308865
Control14=IDC_label_A1,static,1342308865
Control15=IDC_label_12,static,1342308865
Control16=IDC_label_22,static,1342308865
Control17=IDC_label_32,static,1342308865
Control18=IDC_label_42,static,1342308865
Control19=IDC_label_52,static,1342308865
Control20=IDC_label_62,static,1342308865
Control21=IDC_label_72,static,1342308865
Control22=IDC_label_82,static,1342308865
Control23=IDC_label_92,static,1342308865
Control24=IDC_label_A2,static,1342308865
Control25=IDC_label_13,static,1342308865
Control26=IDC_label_23,static,1342308865
Control27=IDC_label_33,static,1342308865
Control28=IDC_label_43,static,1342308865
Control29=IDC_label_53,static,1342308865
Control30=IDC_label_63,static,1342308865
Control31=IDC_label_73,static,1342308865
Control32=IDC_label_83,static,1342308865
Control33=IDC_label_93,static,1342308865
Control34=IDC_label_A3,static,1342308865
Control35=IDC_label_14,static,1342308865
Control36=IDC_label_24,static,1342308865
Control37=IDC_label_34,static,1342308865
Control38=IDC_label_44,static,1342308865
Control39=IDC_label_54,static,1342308865
Control40=IDC_label_64,static,1342308865
Control41=IDC_label_74,static,1342308865
Control42=IDC_label_84,static,1342308865
Control43=IDC_label_94,static,1342308865
Control44=IDC_label_A4,static,1342308865
[CLS:CLabel]
Type=0
HeaderFile=label.h
ImplementationFile=label.cpp
BaseClass=CStatic
关键在于[General Info]段中的东西。[CLS:CLabel]如果没有,在ClassWizard中选择Clabel
时将会自动出现提示,也可以在这时选择.h和.cpp文件。
还有一种方法比较土一些:先不要将label.h和label.cpp拷贝到project的目录,
在ClassWizard中建个CLabel的类,然后将label.h和label.cpp覆盖上去即可。
不过#include还是要加的。
 
多人接受答案了。
 
后退
顶部