|
InvalidateRect is only half the process. This call tells Windows that a portion of the window should be repainted the next time a WM_PAINT message is sent to the window. In order to force an immediate repaint after one of the Invalidate* calls, you need to call UpdateWindow() .
Software Zen: delete this;
|
|
|
|
|
Gary Wheeler wrote:
InvalidateRect is only half the process. This call tells Windows that a portion of the window should be repainted the next time a WM_PAINT message is sent to the window. In order to force an immediate repaint after one of the Invalidate* calls, you need to call UpdateWindow().
tried the following with last parameter to Invalidate set to 0 also.
Just paints white over all html controls on the page. Can only get them to show by clicking mouse over each region
BOOL CTestEngine4View::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
//MessageBox("erase");
CRect rcClient;
GetClientRect(&rcClient);
InvalidateRect(&rcClient,1);
UpdateWindow();
return CHtmlView::OnEraseBkgnd(pDC);
}
|
|
|
|
|
Sorry; I didn't read your original post closely enough .
Take a look at this article[^] in the MSDN; it describes the problem you're experiencing, and how to fix it.
Side note: OnEraseBkgnd is called during the window painting process. As a result, calling InvalidateRect and/or UpdateWindow during that process would only confuse the issue. The window is in the process of being drawn, and you're telling it that the entire window needs updated, and then update the window (and Windows says "but I'm already updating it!")...
Software Zen: delete this;
|
|
|
|
|
thanks Gary - i found that OnErase gets called whenever another frame covers a region of an existing frame. By returning 'true' at this point the repaint works fine. (not entirely sure why)
However the article you pointed me too clears things up - thanks alot!
Carl
|
|
|
|
|
Hello
I need to developp an application which controls a card via USB port. Does someone have a good C++ class which defines the USB communication protocol?
Thank's for advance.
|
|
|
|
|
USB is not like serial port. You need kernel driver, or your device should support some standard protocol like HID to use built-in drivers. Check http://www.lvr.com/[^] for more.
|
|
|
|
|
Driver is ok. My device is well recognized by MS windows.
I just need to create a C++ usb class in order to define the communication protocol. Do you have more informations about this?
|
|
|
|
|
jeab. wrote:
I just need to create a C++ usb class in order to define the communication protocol. Do you have more informations about this?
How the device is recognized? Communication depends on device interface, there is no generic way. Many cards/monitor hardware with low traffic implements the hid interface. There you use read/writefile with specially constructed packets called reports. Each device defines its own report format. The link I gave has sample code.
|
|
|
|
|
The driver of the device was given with another application which works with.
I have to use the USB fonctionality of my device (which is controllable with a serial port RS 232) to control it by the application I have to adapt for.
I just want to know the functions I have to declare in my new CUsbCtrl class.
I see 3 functions (USBTxStart, USBTxDone, USBTxAbort) but I don't know how to make them.
|
|
|
|
|
I try your sample code but the file "hidsdi.h" is not given in your package.
|
|
|
|
|
It's not my code. This file is from windows ddk, you need it to compile.
|
|
|
|
|
You need the ddk to compile.
|
|
|
|
|
Hi,
Can anyone tell me how to find if a file is already open.This is to prevent two instances of the same file.
Thanks.
Deepak Samuel.
Deepak Samuel.
|
|
|
|
|
Try to open the file again. If it is opened elsewhere, you'll get an appropriate error.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I would add to David's comment - open the file with the EXCLUSIVE mode !!
'G'
|
|
|
|
|
Hello everyone,
I'm working on a project that involves texture mapping. The idea is that we want to see how the inside of an object looks like. So we have to make a crossection, the system already creates a bitmap of how the object would look like in the inside, but I need to texture map that bitmap on the crossection.
The problem is that the bitmap created still has some black borders and pieces in it. I want those colors to be transparant so that I can still see the rest of my object in 3D.
What I'm thinking of is the following. First we isolate the object inside the bitmap, take a rectangle region out of it and make the black color transparant. Now we've got a rectangle with our object inside of it without any black borders. Now we need to texture map that rectangle onto our object in 3D space. We need to calculate the a rectangle around our object in 3D space to texture map our bitmap to.
Can someone please help me.
I already found some good code for making the black color transparant.
Thanks in advance
zeno81
|
|
|
|
|
Hi There,
I continually find that I start implementing stuff then change my mind or handle some VC event and then decide that I actually what to handle anothe event and so end up with a whole pile of vc++ generated kludge. SO is there a tool that I can run so that I run the app run all the buttons and change all the parameters that I want and then after the app exists it wil colour code it. e.g. red code is not to be touched and blue code is code that hasn't been referenced or is safe to delete. E.g. do I really have to delete the ON_COMMAND_UI the afx mesage On command in the .h and the actual function in the C++ file if I change my mind for one menu item. Am imissing something is there a better way.
Do most people have a huge view class which has all the events they want to handle or do they put that in another class. Do most people actually keep the data not in the document but in the view in doc/view arch so they dont have to prefix all their data with GetDocument()
It seems to me that when changing menu ordering around or even changing a control on a dialog app that it requires a lot of work. How does everyone else do this? Does this mean that I need to design more carefully? Do other people have little test beds? I was thinking of having say a dialog app with buttons for each new test feature I want to add and then adding a class implementing that behavior so I can have little modules of the behavior that I want which I can then add them to the main module. Also do people here use CVS or do they actually use source safe which even MS does not recommened. If people use CVS then how do they cope with e.g. converting a class to a dll and cvs add and removing the correct folders and MS VC++ generated stuff? Why can I use dc->SetBkColor to change the background of most controls but I have to use OnEraseBkgrnd to change the colour of a view in a MDI/SDI app. (Why can't i Use SetBkCOlor for everything) Is having controls in a mdi view a bad idea since you have to manually calculate the offsets rather than a diaog app when you can just plonk them on? Do most people here actually know 5/6 languages inside out or do they only really know 1 or 2 really well. e.g. would people say they know MFC inside out or just subsets of it.
|
|
|
|
|
Lots of questions;
1. No, there is no tool with VC++, you'd need to use some kind of code coverage tool to achieve that, and it wouldn't colour-code.
2. ClassWizard will delete some stuff, if you let it.
3. Depends. Can't speak for everyone else, but I keep document data in the document. The overhead involved in typing disappears at run-time, and the overhead of an extra dereference is worth the encapsulation benefits.
You aren't really an O-O person, are you?
4. If your UI requires a lot of changes, you haven't spent enough time on the design.
5. Yes, lots of small testbed applications. Otherwise how can you be sure it's not an issue with side-effects from something else.
6. SourceSafe works fine, if you accept the fact that it doesn't handle branching in a useful way (i.e. 1.1.2 and 1.2 "in parallel")
7. Simple. No regeneratable files go into the repository, so no NCB, CLW, APS etc, and no MIDL generated files either. Proper rules, and enforcement.
8. Because it doesn't work that way. OnEraseBkgrnd does "what it says on the tin". You aren't using SetBkColor to change the background of a control, mostly. If you do your own drawing you will, and if you handle WM_CTLCOLORxxxx you can but that's because of a design feature (callback) rather than "the way it's done everywhere else".
9. Control placement is your responsibility for anything other than a dialog. If you want to use a dialog template to set up controls in a simple view, I don't see anyone stopping you. You could use ideas and code from sites like this one.
10. Can't speak for everyone else, but I know two or three well, and the
environments I work in quite well too. I don't know MFC inside out, but I know it well enough to navigate the documentation and source code.
'Nuff said.
Steve S
Please do not feed the troll - it bites back
|
|
|
|
|
i have defined a class of "CChildFrame" ,its base class is CMDICHILDWND,
then i define "CChildFrame*p_ADD" in "MainFrm.h",
when i "p_ADD=new CChildFrame();" in "MainFrm.cpp".when run ,point out:
1 error o warning.
but after i "//p_ADD=new CChildFrame();" ,all ok?
please help me
|
|
|
|
|
what error does the compiler really give you ?
TOXCCT >>> GEII power
|
|
|
|
|
vividtang wrote:
then i define "CChildFrame*p_ADD" in "MainFrm.h",
At this point, the CChildFrame-class is known to the compiler?
You either need to have the ChildFrame.h-file #include -ed in MainFrm.h , or you can, as you ar only declaring a pointer to the class, not an instance itself, write
class CChildFrame; just below all includes, but before the class starts. This is called 'forward-declaration' and is the C++ way of telling the compiler: "Shut up, you will know that class when you really need it!".
But you have to keep that promise: When the compiler is asked to construct the instance of CChildFrame , in the new() statement, the class must be fully known. To achieve this, just write
#include "ChildFrame.h" in MainFrame.cpp at the top. Best to put it after all other #include s.
This should then compile cleanly.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
thank you jhwurmbach, i have writen in MainFrm.h and in MainFrm.cpp #include
cchildframe.h,but i didn't work, i have spend for a year for this error.
|
|
|
|
|
vividtang wrote:
but i didn't work
What does that mean? Please post the exact error messages so I can really start to help you.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
jhwurmbach ,thank you again.please help me
below it is my "MainFrm.h"
#include "TheChildFrame.h"
#if !defined(AFX_MAINFRM_H__72AAD2C8_6374_49B1_907D_7CA96509F1F8__INCLUDED_)
#define AFX_MAINFRM_H__72AAD2C8_6374_49B1_907D_7CA96509F1F8__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMainFrame : public CMDIFrameWnd
{
DECLARE_DYNAMIC(CMainFrame)
public:
CMainFrame();
// Attributes
public:
CTheChildFrame *m_pAdd,*m_pChange; // 指向三个功能窗口
BOOL m_bLogin; // 登录状态
BOOL m_bItemAdd,m_bItemChange; // 相应的菜单项及工具栏按钮是否可用
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
// Generated message map functions
protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnUpdateSystemConnect(CCmdUI* pCmdUI);
afx_msg void OnUpdateSystemDisconnect(CCmdUI* pCmdUI);
afx_msg void OnUpdateManageAdd(CCmdUI* pCmdUI);
afx_msg void OnSystemConnect();
afx_msg void OnSystemDisconnect();
afx_msg void OnDestroy();
afx_msg void OnManageAdd();
afx_msg void OnUpdateManagerChange(CCmdUI* pCmdUI);
afx_msg void OnManagerChange();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MAINFRM_H__72AAD2C8_6374_49B1_907D_7CA96509F1F8__INCLUDED_)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
below it is my "MainFrm.cpp"
#include "stdafx.h"
#include "Personnel3.h"
#include "LoginDlg.h"
#include "AddView.h"
#include "ChangeView.h"
#include "MainFrm.h"
//#include "TheChildFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//include "TheChildFrame.h"
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
extern CDatabase db;
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_UPDATE_COMMAND_UI(ID_SYSTEM_CONNECT, OnUpdateSystemConnect)
ON_UPDATE_COMMAND_UI(ID_SYSTEM_DISCONNECT, OnUpdateSystemDisconnect)
ON_UPDATE_COMMAND_UI(ID_MANAGE_ADD, OnUpdateManageAdd)
ON_COMMAND(ID_SYSTEM_CONNECT, OnSystemConnect)
ON_COMMAND(ID_SYSTEM_DISCONNECT, OnSystemDisconnect)
ON_WM_DESTROY()
ON_COMMAND(ID_MANAGE_ADD, OnManageAdd)
ON_UPDATE_COMMAND_UI(ID_MANAGER_CHANGE, OnUpdateManagerChange)
ON_COMMAND(ID_MANAGER_CHANGE, OnManagerChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR,
//ID_INDICATOR_LOGIN,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_bLogin=FALSE; // 缺省未登录
m_bItemAdd=FALSE; // "增加新员工"功能缺省为不可用
m_bItemChange=FALSE; // "人事变动"功能缺省为不可用
//m_bItemSearch=FALSE; // "查询修改"功能缺省为不可用
m_pAdd=m_pChange=NULL;
// 初始化为空
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnUpdateSystemConnect(CCmdUI* pCmdUI)
{ pCmdUI->Enable(!m_bLogin);
}
void CMainFrame::OnUpdateSystemDisconnect(CCmdUI* pCmdUI)
{ pCmdUI->Enable(m_bLogin);
}
void CMainFrame::OnUpdateManageAdd(CCmdUI* pCmdUI)
{ pCmdUI->Enable(m_bItemAdd);
}
void CMainFrame::OnUpdateManagerChange(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bItemChange);
}
void CMainFrame::OnSystemConnect()
{
CLoginDlg dlg;
if(dlg.DoModal()==IDOK)
{
m_bLogin=TRUE; // 已登录
m_bItemAdd=TRUE; // 开放"增加新员工"功能
m_bItemChange=TRUE; // 开放"人事变动"功能
// m_bItemSearch=TRUE; // 开放"查询修改"功能
}
}
void CMainFrame::OnSystemDisconnect()
{
db.Close(); // 关闭数据库
// 关闭所有子框架窗口
if(m_pAdd) m_pAdd->DestroyWindow();
if(m_pChange) m_pChange->DestroyWindow();
//if(m_pSearch) m_pSearch->DestroyWindow();
m_bLogin=FALSE; // 未登录
m_bItemAdd=FALSE; // 禁止"增加新员工"功能
m_bItemChange=FALSE; // 禁止"人事变动"功能
//m_bItemSearch=FALSE; // 禁止"查询修改"功能
// 改变状态栏
//m_wndStatusBar.SetPaneText(1, "尚未登录数据库!请按F2登录");
}
void CMainFrame::OnDestroy()
{
CMDIFrameWnd::OnDestroy();
if(db.IsOpen()) db.Close();
}
void CMainFrame::OnManageAdd()
{
// 创建新子框架和视
m_pAdd=new CTheChildFrame(); /*
CCreateContext context;
context.m_pNewViewClass=RUNTIME_CLASS(CAddView);
if(!m_pAdd->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_PREFIXTITLE ,this, &context )) return;
m_pAdd->InitialUpdateFrame(NULL,TRUE);
m_bItemAdd=FALSE; // 禁止"增加新员工"功能*/
}
void CMainFrame::OnManagerChange()
{
// 创建新子框架和视
// m_pChange = new MainFrmame();
/* CCreateContext context;
context.m_pNewViewClass=RUNTIME_CLASS(CChangeView);
if(!m_pChange->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_PREFIXTITLE ,this, &context )) return;
m_pChange->InitialUpdateFrame(NULL,TRUE);
m_bItemChange=FALSE; // 禁止"人事变动"功能 */
}
below it is "AddView.cpp"
#include "stdafx.h"
#include "Personnel3.h"
#include "AddView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAddView
extern CDatabase db;
IMPLEMENT_DYNCREATE(CAddView, CFormView)
CAddView::CAddView()
: CFormView(CAddView::IDD)
{
//{{AFX_DATA_INIT(CAddView)
m_strDepartment = _T("");
m_strEdulevel = _T("");
m_strJob = _T("");
m_strBirthday = _T("");
m_strEmail = _T("");
m_strID = _T("");
m_strMemo = _T("");
m_strName = _T("");
m_strPasswd = _T("");
m_strSpecialty = _T("");
m_strAddress = _T("");
m_strTel = _T("");
//}}AFX_DATA_INIT
}
CAddView::~CAddView()
{
}
void CAddView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAddView)
DDX_Control(pDX, IDC_ADD_CMB_JOB, m_cJob);
DDX_Control(pDX, IDC_ADD_CMB_EDULEVEL, m_cEdulevel);
DDX_Control(pDX, IDC_ADD_CMB_DEPARTMENT, m_cDepartment);
DDX_CBString(pDX, IDC_ADD_CMB_DEPARTMENT, m_strDepartment);
DDX_CBString(pDX, IDC_ADD_CMB_EDULEVEL, m_strEdulevel);
DDX_CBString(pDX, IDC_ADD_CMB_JOB, m_strJob);
DDX_Text(pDX, IDC_ADD_EDT_BIRTHDAY, m_strBirthday);
DDX_Text(pDX, IDC_ADD_EDT_EMAIL, m_strEmail);
DDX_Text(pDX, IDC_ADD_EDT_ID, m_strID);
DDX_Text(pDX, IDC_ADD_EDT_MEMO, m_strMemo);
DDX_Text(pDX, IDC_ADD_EDT_NAME, m_strName);
DDX_Text(pDX, IDC_ADD_EDT_PASSWD, m_strPasswd);
DDX_Text(pDX, IDC_ADD_EDT_SPECIALTY, m_strSpecialty);
DDX_Text(pDX, IDC_ADD_EDT_ADDRESS, m_strAddress);
DDX_Text(pDX, IDC_ADD_EDT_TEL, m_strTel);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAddView, CFormView)
//{{AFX_MSG_MAP(CAddView)
ON_BN_CLICKED(IDC_ADD_BTN_ADD, OnAddBtnAdd)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAddView diagnostics
#ifdef _DEBUG
void CAddView::AssertValid() const
{
CFormView::AssertValid();
}
void CAddView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CAddView message handlers
void CAddView::Init()
{
// 清空成员变量
m_strID = _T("");
m_strPasswd = _T("");
m_strName = _T("");
m_strBirthday = _T("");
m_strDepartment = _T("");
m_cDepartment.SetCurSel(-1);
m_strJob = _T("");
m_cJob.SetCurSel(-1);
m_strEdulevel = _T("");
m_cEdulevel.SetCurSel(-1);
m_strSpecialty = _T("");
m_strAddress = _T("");
m_strTel = _T("");
m_strEmail = _T("");
m_strMemo = _T("");
// 生成员工号
CString str;
int counter; // 用于计数
CRecordset rs(&db); // 数据集
rs.Open(CRecordset::forwardOnly,
"select COUNTER_VALUE from COUNTER where ID='P'");
rs.GetFieldValue("COUNTER_VALUE", str);
sscanf(str, "%d", &counter); // 获取计数值
rs.Close();
str.Format("P%05d", counter); // 产生标准格式的编号
m_strID=str; // 自动产生员工号
m_strPasswd=str; // 默认密码为员工号
// 设置缺省性别为男
((CButton*)GetDlgItem(IDC_ADD_RADIO_MALE))->SetCheck(TRUE);
UpdateData(FALSE); // 更新界面数据
}
void CAddView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit(FALSE);
GetParentFrame()->SetWindowText("增加新员工"); // 设置标题
CRecordset rs(&db); // 数据集
CString str;
// 设置部门下拉框所取的值为DEPARTMENT表中的值
rs.Open(CRecordset::forwardOnly, "select NAME from DEPARTMENT");
while(!rs.IsEOF())
{
rs.GetFieldValue("NAME", str);
m_cDepartment.AddString(str);
rs.MoveNext();
}
rs.Close();
// 设置职务下拉框所取的值为JOB表中的值
rs.Open(CRecordset::forwardOnly, "select DESCRIPTION from JOB");
while(!rs.IsEOF())
{
rs.GetFieldValue("DESCRIPTION", str);
m_cJob.AddString(str);
rs.MoveNext();
}
rs.Close();
// 设置受教育水平下拉框所取的值为EDU_LEVEL表中的值
rs.Open(CRecordset::forwardOnly, "select DESCRIPTION from EDU_LEVEL");
while(!rs.IsEOF())
{
rs.GetFieldValue("DESCRIPTION", str);
m_cEdulevel.AddString(str);
rs.MoveNext();
}
rs.Close();
Init(); // 调用初始化函数
}
void CAddView::OnAddBtnAdd()
{ CString str,strSQL;
int counter; // 用于计数
CRecordset rs(&db); // 数据集
UpdateData(); // 更新数据
if(m_strName.IsEmpty()) // 姓名为空则返回
{
AfxMessageBox("姓名不能为空!");
return;
}
// 累加员工编号计数器
rs.Open(CRecordset::forwardOnly,"select COUNTER_VALUE from COUNTER where ID='P'");
rs.GetFieldValue("COUNTER_VALUE", str);
sscanf(str, "%d", &counter); // 获取计数值
rs.Close(); // 关闭数据集
counter++; // 计数值加1
str.Format("%d", counter); // 转换为字符串
strSQL="update COUNTER set COUNTER_VALUE=" + str + " where ID='P'"; // 设置SQL语句
db.ExecuteSQL(strSQL); // 执行
// 增加员工个人信息记录
CString strPasswd,strSex,strDepID,strJobID,strEduID;
// 判断生日是否为空
if(m_strBirthday.IsEmpty()) m_strBirthday="1900-1-1"; // 缺省值
// 加密密码
strPasswd=m_strPasswd;
// 判断性别
if(((CButton*)GetDlgItem(IDC_ADD_RADIO_MALE))->GetCheck()) strSex="M";
else strSex="F";
// 得到部门ID
rs.Open(CRecordset::forwardOnly,
"select ID from DEPARTMENT where NAME='" + m_strDepartment +"'");
rs.GetFieldValue("ID", strDepID);
rs.Close();
// 得到职务代码
rs.Open(CRecordset::forwardOnly,
"select CODE from JOB where DESCRIPTION='" + m_strJob +"'");
rs.GetFieldValue("CODE", strJobID);
rs.Close();
// 得到受教育水平代码
rs.Open(CRecordset::forwardOnly,
"select CODE from EDU_LEVEL where DESCRIPTION='" + m_strEdulevel +"'");
rs.GetFieldValue("CODE", strEduID);
rs.Close();
// 写SQL语句
strSQL="insert into PERSON(ID,PASSWD,NAME,SEX,\
BIRTHDAY,DEPARTMENT,JOB,EDU_LEVEL,SPECIALTY,\
ADDRESS,TEL,EMAIL,REMARK) \
values('"
+ m_strID + "','" // ID
+ strPasswd + "','" // PASSWD
+ m_strName + "','" // NAME
+ strSex + "','" // SEX
+ m_strBirthday + "','" // BIRTHDAY
+ strDepID + "','" // DEPARTMENT
+ strJobID + "','" // JOB
+ strEduID + "','" // EDU_LEVEL
+ m_strSpecialty + "','" // SPECIALTY
+ m_strAddress + "','" // ADDRESS
+ m_strTel + "','" // TEL
+ m_strEmail + "','" // EMAIL
+ m_strMemo + "')"; // REMARK
db.ExecuteSQL(strSQL); // 执行
// 获取人事变动记录号并累加
rs.Open(CRecordset::forwardOnly,
"select COUNTER_VALUE from COUNTER where ID='C'");
rs.GetFieldValue("COUNTER_VALUE", str);
sscanf(str, "%d", &counter); // 获取计数值
rs.Close(); // 关闭数据集
counter++; //计数值加1
str.Format("%d", counter); // 转换为字符串
strSQL="update COUNTER set COUNTER_VALUE=" + str + " where ID='C'"; // 设置SQL语句
db.ExecuteSQL(strSQL); // 执行
// 追加人事变动记录
str.Format("%d",counter); // 计数值转换为字符串
CTime time=CTime::GetCurrentTime();
CString strNow=time.Format("%Y-%m-%d %H:%M:%S");
// 写SQL语句
strSQL="insert into PERSONNEL(ID,PERSON,CHANGE,\
RECORD_TIME,DESCRIPTION)\
values("
+ str + ",'" // ID
+ m_strID + "','" // PERSON
+ "0" + "','" // CHANGE - 加入公司代码
+ strNow + "','" // RECORD_TIME
+ "加入公司')"; // DESCRIPTION
db.ExecuteSQL(strSQL);
// 重新初始化窗口
Init();
}
void CAddView::OnDestroy()
{
CFormView::OnDestroy();
((CMainFrame*)AfxGetMainWnd())->m_bItemAdd=TRUE; // 开放"增加新员工"功能
((CMainFrame*)AfxGetMainWnd())->m_pAdd=NULL; // 清空窗口指针
}
|
|
|
|
|
jhwurmbach ,thank you again.please help me,only write m_pAdd=new TheChildFrame(),1 error o warning,
below it is my "MainFrm.h" in short
#include "TheChildFrame.h"
class CMainFrame : public CMDIFrameWnd
{
DECLARE_DYNAMIC(CMainFrame)
public:
CMainFrame();
// Attributes
public:
CTheChildFrame *m_pAdd,*m_pChange; // BOOL m_bLogin;
BOOL m_bItemAdd,m_bItemChange;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
below it is my "MainFrm.cpp"
#include "stdafx.h"
#include "Personnel3.h"
#include "LoginDlg.h"
#include "AddView.h"
#include "ChangeView.h"
#include "MainFrm.h"
//include "TheChildFrame.h"
extern CDatabase db;
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_UPDATE_COMMAND_UI(ID_SYSTEM_CONNECT, OnUpdateSystemConnect)
ON_UPDATE_COMMAND_UI(ID_SYSTEM_DISCONNECT, OnUpdateSystemDisconnect)
ON_UPDATE_COMMAND_UI(ID_MANAGE_ADD, OnUpdateManageAdd)
ON_COMMAND(ID_SYSTEM_CONNECT, OnSystemConnect)
ON_COMMAND(ID_SYSTEM_DISCONNECT, OnSystemDisconnect)
ON_WM_DESTROY()
ON_COMMAND(ID_MANAGE_ADD, OnManageAdd)
ON_UPDATE_COMMAND_UI(ID_MANAGER_CHANGE, OnUpdateManagerChange)
ON_COMMAND(ID_MANAGER_CHANGE, OnManagerChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
m_bLogin=FALSE; m_bItemAdd=FALSE; m_bItemChange=FALSE; m_bItemSearch=FALSE; m_pAdd=m_pChange=NULL;
}
CMainFrame::~CMainFrame()
{
}
void CMainFrame::OnUpdateSystemConnect(CCmdUI* pCmdUI)
{ pCmdUI->Enable(!m_bLogin);
}
void CMainFrame::OnUpdateSystemDisconnect(CCmdUI* pCmdUI)
{ pCmdUI->Enable(m_bLogin);
}
void CMainFrame::OnUpdateManageAdd(CCmdUI* pCmdUI)
{ pCmdUI->Enable(m_bItemAdd);
}
void CMainFrame::OnUpdateManagerChange(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bItemChange);
}
void CMainFrame::OnSystemConnect()
{
CLoginDlg dlg;
if(dlg.DoModal()==IDOK)
{
m_bLogin=TRUE; m_bItemAdd=TRUE; m_bItemChange=TRUE; m_bItemSearch=TRUE;
}
}
void CMainFrame::OnSystemDisconnect()
{
db.Close(); if(m_pAdd) m_pAdd->DestroyWindow();
if(m_pChange) m_pChange->DestroyWindow();
//if(m_pSearch) m_pSearch->DestroyWindow();
m_bLogin=FALSE; m_bItemAdd=FALSE; m_bItemChange=FALSE; m_bItemSearch=FALSE;
}
void CMainFrame::OnDestroy()
{
CMDIFrameWnd::OnDestroy();
if(db.IsOpen()) db.Close();
}
void CMainFrame::OnManageAdd()
{
// 创建新子框架和视
m_pAdd=new CTheChildFrame(); /*
CCreateContext context;
context.m_pNewViewClass=RUNTIME_CLASS(CAddView);
if(!m_pAdd->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_PREFIXTITLE ,this, &context )) return;
m_pAdd->InitialUpdateFrame(NULL,TRUE);
m_bItemAdd=FALSE; // 禁止"增加新员工"功能*/
}
|
|
|
|
|