如何用MSFlexGrid的Create在程序中动态建立控件

lingfeng8888 2003-12-17 12:39:10
Create有两个原型,请分别说明。最主要的是参数有CFile * pPersist和BOOL bStorage的使用和说明。
...全文
156 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
lingfeng8888 2003-12-18
  • 打赏
  • 举报
回复
难道没有人能解决吗
lingfeng8888 2003-12-18
  • 打赏
  • 举报
回复
望高手帮忙解决
lingfeng8888 2003-12-17
  • 打赏
  • 举报
回复
自己顶一下
lingfeng8888 2003-12-17
  • 打赏
  • 举报
回复
如果只是把控件放在对话框上,使用都可以,但动态建立时,如果不使用后面那三个参数,建成后,也可以往里填数据,跟一般的使用没什么别的不同,但更具体的没有试到。不知道这样还需不需要打什么补丁包吗?
carbon107 2003-12-17
  • 打赏
  • 举报
回复
难到你的MSFlexGrid还要打上什么补丁包不成吗???
carbon107 2003-12-17
  • 打赏
  • 举报
回复
bstrLicKey :
Optional license key data. This data is needed only for creating controls that require a run-time license key. If the control supports licensing, you must provide a license key for the creation of the control to succeed. The default value is NULL.

好像与什么认证有关,由于从来也没有用过这个参数, 也不知如何处理
lingfeng8888 2003-12-17
  • 打赏
  • 举报
回复
真的不好意思,“其它那两个参数,只要设置CFile* pPersist != NULL, 则必须BOOL bStorage = TRUE,就会返回0(即不成功),否则会出错。”,今天在VC7的情况下,使用CFile* pPersist != NULL也可以BOOL bStorage = FALSE而不出错。
总之,希望大家帮想想办法给予解决。
lingfeng8888 2003-12-17
  • 打赏
  • 举报
回复
看了carbon107(<软件开发思想.h>) 在楼上的解释,BSTR bstrLicKey是一个许可键值,问题是如何得到它。其它那两个参数,只要设置CFile* pPersist != NULL, 则必须BOOL bStorage = TRUE,就会返回0(即不成功),否则会出错。现在希望得到一个BSTR bstrLicKey的正确值,以便进一步试验。
lingfeng8888 2003-12-17
  • 打赏
  • 举报
回复
carbon107(<软件开发思想.h>) 和zhucde(【风间苍月】)

在VC7中现在已经可以做到与VC6下的情况一样了,就是使用后面三个参数时就是返回0,即不成功,关键是最后那个参数(BSTR bstrLicKey),本人对这个类型不熟,能不能给解释一下。
zhucde 2003-12-17
  • 打赏
  • 举报
回复
是挺烦的,在VC7里竟然不能显示,
会不会不是参数的原因,而是其它原因?

找找看.
lingfeng8888 2003-12-17
  • 打赏
  • 举报
回复
关键是这个函数的使用,特别是需要重设后面三个参数的使用。
Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
pPersist, bStorage, bstrLicKey); }
因为考虑到MSFlexGrid的可用记录数是根据机器内存的大小而定的,想通过这个函数建立一个能自动存储的控件,看看能不能实现大记录的使用。只是一直没有使用成功。
在后面三个参数缺省的情况下,可以建立成功,但如果使用后面三个参数时,就返回0,表示不成功。
以上的现象为在VC6的环境中。今天在VC7下,后面三个参数缺省也无法显示。
zhucde 2003-12-17
  • 打赏
  • 举报
回复
最后两个参数默认,一般就这样用的,
还真找不到说明这两个参数的.
carbon107 2003-12-17
  • 打赏
  • 举报
回复
CFile* pPersist = NULL, //
BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL

一般就默认用了,你是要改写默认的参数值吗??
carbon107 2003-12-17
  • 打赏
  • 举报
回复
上面写的程序断用的是第二种形式的函数

1.virtual BOOL Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd, UINT nID,
CCreateContext* pContext = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }

lpszClassName //要注册的类名
lpszWindowName //窗口名
dwStyle //窗口的类型
rect //要显示此控件的矩形大小
pParentWnd //父类指针
nID //其对应的ID
pContext //扩展内容
通过这些参数的设定
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }
返回时要调用CreateControl()函数

2. BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
pPersist, bStorage, bstrLicKey); }

CFile* pPersist = NULL, //
BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL

pPersist :

A pointer to a CFile containing the persistent state for the control. The default value is NULL, indicating that the control initializes itself without restoring its state from any persistent storage. If not NULL, it should be a pointer to a CFile-derived object that contains the control's persistent data, in the form of either a stream or a storage. This data could have been saved in a previous activation of the client. The CFile can contain other data, but must have its read-write pointer set to the first byte of persistent data at the time of the call to CreateControl.
bStorage :

Indicates whether the data in pPersist should be interpreted as IStorage or IStream data. If the data in pPersist is a storage, bStorage should be TRUE. If the data in pPersist is a stream, bStorage should be FALSE. The default value is FALSE.

bstrLicKey :
Optional license key data. This data is needed only for creating controls that require a run-time license key. If the control supports licensing, you must provide a license key for the creation of the control to succeed. The default value is NULL.
zhucde 2003-12-17
  • 打赏
  • 举报
回复
比如在View里加入此控件:
先添加此ActiveX控件,(project->Add to Project->Components and Controls->Registered ActiveX Control->Microsoft FlexGrid Control, version 6.0,然后insert)
添加好后,在xxView.h中加入:
#include "msflexgrid.h"

同时在publuc中加入:
CMSFlexGrid m_fgrid;

然后在xxxView.cpp中加入WM_CREATE消息,
int CAaView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

m_fgrid.Create(NULL, WS_VISIBLE,

CRect(50,50,800,800), this, 0);//用this指针作为指向父窗口的指针//

m_fgrid.SetCols(2);

m_fgrid.SetRows(10);

m_fgrid.SetTextMatrix(0,0,"编号");

m_fgrid.SetTextMatrix(0,1,"姓名");

return 0;
}
carbon107 2003-12-17
  • 打赏
  • 举报
回复
引用过来CMSFlexGrid

在程序的头文件里定义
MSFlexGrid m_grid;
在程序的初始化写入

CRect rect(100, 100, 500, 500);
m_grid.Create("dfdfdf", WS_CHILD, rect, this, ID_GRID);
m_grid.ShowWindow(SW_SHOW);

就显示出来了
carbon107 2003-12-17
  • 打赏
  • 举报
回复
你说的是这两个函数吧
一个为虚函数
1.virtual BOOL Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd, UINT nID,
CCreateContext* pContext = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }

一个为普通函数
2. BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
pPersist, bStorage, bstrLicKey); }

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧