|
First, I really appreciate that you spend your time to read my question.
Hi! I try to build a class that has several functions. Some of them will return string.
But my complier say I have something wrong.
The complier show the message that undefine error.
Please help me to figure out. Thank you.
I paste my complete code below
// filename:studentinfo.h
class studentinfo
{
public:
void set_lastname(string);
void set_firstname(string);
void set_ssn(string);
void set_age(int);
void set_phone(string);
string show_lastname();
string show_firstname();
string show_ssn();
int show_age();
string show_phone();
private:
string lastname;
string firstname;
string ssn;
int age;
string phone;
};
// filename:studentinfo.cpp
#include <iostream>
#include <string>
#include "studentinfo.h"
//--------------------------------------------------------------------------------
// The following functions declare for my class.
//--------------------------------------------------------------------------------
string studentinfo::show_lastname()
{
return lastname;
}
string studentinfo::show_firstname()
{
return firstname;
}
string studentinfo::show_ssn()
{
return ssn;
}
int studentinfo::show_age()
{
return age;
}
string studentinfo::show_phone()
{
return phone;
}
void studentinfo::set_lastname(string text)
{
lastname=text;
}
void studentinfo::set_firstname(string text)
{
firstname=text;
}
void studentinfo::set_ssn(string text)
{
ssn=text;
}
void studentinfo::set_age(int number)
{
age=number;
}
void studentinfo::set_phone(string text)
{
phone=text;
}
|
|
|
|
|
Are you sure it's string not CString?
|
|
|
|
|
|
The standard string type is std::string , you can add using namespace std; after the includes to avoid adding the std:: prefix everywhere.
|
|
|
|
|
is there any way to guarantee a PC thread run at 200ms+_100ms period interval? Timer or multimedia timer seems don't fit.
|
|
|
|
|
Well, there's always the Sleep() funtion. I'm not sure how gurenteed the amount of time it waits is though.
Edit: Just checked. It's not gurenteed to resume excecution after the given time period, but you could probobly fix that with a heavy priority boost or something.
|
|
|
|
|
Yes I set the thread to high priority, it still won't guarantee. by the way, what is heavy priority boost?
|
|
|
|
|
I told you in a previous post that you can't have any such guarantees with a non-realtime OS like Windows. If you don't trust me, read this article[^].
Can you use some RTOS, like QNX[^]?
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
I have a win32 app and copy MFC code into it.
but the app can not be compiled now because of MFC classes.
MFC is in "Use MFC in a static library".
how to change settings for compiling?
thx
includeh10
|
|
|
|
|
Create two Win32 apps, tick 'use MFC' for one. Diff the files, and make sure you have all those things set in your own code.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi there!
I've got a problem with a simple, self-written DialogBar.
The DialogBar is not amazing at all, it simply displays a Dialog in a dockable ControlBar and is part of a DLL. If I try to create the DialogBar (in my MainFrame-Class), it fails and the control bar can not be created.
After a little research, I found out that the following line in the MFC-Core failed:
<br />
HWND hWnd = ::CreateWindowEx(cs.dwExStyle, cs.lpszClass,<br />
cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy,<br />
cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams);<br />
Another strange thing I found out while researching:
<br />
m_wndDialog.Create("bla fasel", this, 123456, WS_VISIBLE|WS_CHILD|CBRS_FLYBY|CBRS_SIZE_DYNAMIC|CBRS_TOOLTIPS)<br />
In that line a pointer to the parent window is passed to the Create() method (here this) of the DialogBar which is in the DLL.
If I verify the this-pointer before I enter the Create() method the member m_hWnd is valid and seems to be correct. But if I enter the Create() method (is a call to the DLL method), the m_hWnd of the parent window pointer becomes NULL.
Anybody out there with a solution to the problem?
Thanks in advance!
Axel
|
|
|
|
|
While coding in C# in the Visual Studio .NET 2003 IDE, one is able to mark regions using #region and #endregion.
Is a similar option available when coding in Visual C++?
|
|
|
|
|
you should be able to right-click in your editor window, go to 'Outlining' on the popup menu, and get a list of options there.
Who are all these people and what are they doing in my house?...Me in 30 years, inside a grocery store
My articles[^]
bdiamond
|
|
|
|
|
Hi
I have some 4 views all derived from CFormView. There is no system default menu in all. But i want to hang one menu in one of the view like Tools-->Copy.
I tried some options but it is failed. Can anybody tell me how to create this menu using CMenu class or with some other method??
Thanks in advance
Shailesh
|
|
|
|
|
Hello,
Given a CDocument object, how does one do about knowing the ID of the resource (the IDR_resource ) which was associated to the document template?
Thanks,
David
|
|
|
|
|
I have a project that is taking WAAAAYYYY too much time to compile... ( IMHO )
all files are C++ and are using precompile headers.
I use Program Database ( Zi ), minimal build ( and link ).
the only thing that I'm not sure, is that some of my source files are in subfolders of the main project file, and do
#include "../stdafx.h"
can that be a problem ?
also, there's a vc7.idb and vc7.pdb that are created ( and recreated ) quite often, I assume that the .pdb is the program database, but is it supposed to be recreated at every couple of files ?
THanks.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
With minimal build and link enabled, it can take longer and longer to compile and link because certain files are hashed, instead of being rewitten every time. You might try a FULL rebuild (or rebuild all) periodically to keep this thrashing to a minimum. I see this same problem with VC 6.0 when I have incremental link enabled.
The PDB must correlate the lines in your source with the locations on the executables, so it is common for that to rebuild each time you recompile and relink.
|
|
|
|
|
BOOL Cfirstw32mfcApp::InitInstance()
{
SetRegistryKey(_T("Natural_Demon"));
...
..
..
}
this works perfect ...
the data retrieved from the registry is nicely update in the GUI
BOOL Cfirstw32mfcDlg::OnInitDialog()
{
..
...
...
..
EDIT1 = AfxGetApp()->GetProfileString("Settings", "email", "your login");
EDIT2 = AfxGetApp()->GetProfileString("Settings", "password", "details here..");
return FALSE; // return TRUE unless you set the focus to a control
}
this works perfectly ...
HRESULT Cfirstw32mfcDlg::OnButtonOK(IHTMLElement* /*pElement*/)
{
AfxGetApp()->WriteProfileString("Settings", "email", "hi");
AfxGetApp()->WriteProfileString("Settings", "password", "do");
return NULL;
}
but why doesn't this work ...?
HRESULT Cfirstw32mfcDlg::OnButtonOK(IHTMLElement* /*pElement*/)
{
UpdateData(FALSE);
AfxGetApp()->WriteProfileString("Settings", "email", EDIT1);
AfxGetApp()->WriteProfileString("Settings", "password", EDIT2);
return NULL;
}
if i do this ...
UpdateData();, UpdateData(FALSE); or this UpdateDialogControls(this, FALSE);
nothing works
EDIT1 en EDIT2 are empty and the registry get's updated with empty values.
where am i mistaking here?
thnx in advance.
kind regards,
marco
|
|
|
|
|
Your Data Exchange handler function might not be set up correctly.
The Data Exchange might be overwriting the data in your edit field controls, or no member variables are setup to write into the controls.
It looks like you fill them in OnInitDialog, but you should do that in DoDataExchange.
|
|
|
|
|
this is what i got and all those intents u see in code don't work
thank for your time and kind regards,
marco
// firstw32mfcDlg.h : header file
//
#pragma once
// Cfirstw32mfcDlg dialog
class Cfirstw32mfcDlg : public CDHtmlDialog
{
// Construction
public:
Cfirstw32mfcDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_FIRSTW32MFC_DIALOG, IDH = IDR_HTML_FIRSTW32MFC_DIALOG };
CString EDIT1;
CString EDIT2;
CString m_EDIT1;
CString m_EDIT2;
CString m_TEMP_EDIT1;
CString m_TEMP_EDIT2;
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
HRESULT OnButtonOK(IHTMLElement *pElement);
HRESULT OnButtonCancel(IHTMLElement *pElement);
//HRESULT OnChangeEdit1(IHTMLElement *pElement);
//HRESULT OnEnChangeEdit2(IHTMLElement *pElement);
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
DECLARE_DHTML_EVENT_MAP()
public:
//char m_EDIT1;
//char m_EDIT2;
//afx_msg void OnEnChangeEdit1();
//afx_msg void OnEnChangeEdit2();
};
-----------------------------------------------
// firstw32mfcDlg.cpp : implementation file
//
#include "stdafx.h"
#include "firstw32mfc.h"
#include "firstw32mfcDlg.h"
#include ".\firstw32mfcdlg.h"
//#include <atlbase.h>
//#include <afxpriv.h>
#include <oleauto.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// Cfirstw32mfcDlg dialog
BEGIN_DHTML_EVENT_MAP(Cfirstw32mfcDlg)
DHTML_EVENT_ONCLICK(_T("ButtonOK"), OnButtonOK)
DHTML_EVENT_ONCLICK(_T("ButtonCancel"), OnButtonCancel)
//DHTML_EVENT_ONCHANGE(_T("email"), OnChangeEdit1 )
//DHTML_EVENT_ONCHANGE(_T("password"), OnEnChangeEdit2 )
END_DHTML_EVENT_MAP()
Cfirstw32mfcDlg::Cfirstw32mfcDlg(CWnd* pParent /*=NULL*/)
: CDHtmlDialog(Cfirstw32mfcDlg::IDD, Cfirstw32mfcDlg::IDH, pParent)
//, m_EDIT1(0)
//, m_EDIT2(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void Cfirstw32mfcDlg::DoDataExchange(CDataExchange* pDX)
{
CDHtmlDialog::DoDataExchange(pDX);
DDX_DHtml_ElementInnerText(pDX, _T("email"), EDIT1);
DDX_DHtml_ElementInnerText(pDX, _T("password"), EDIT2);
DDX_DHtml_ElementInnerText(pDX, _T("Temp_Text1"), m_EDIT1);
DDX_DHtml_ElementInnerText(pDX, _T("Temp_Text2"), m_EDIT2);
}
BEGIN_MESSAGE_MAP(Cfirstw32mfcDlg, CDHtmlDialog)
ON_WM_SYSCOMMAND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// Cfirstw32mfcDlg message handlers
BOOL Cfirstw32mfcDlg::OnInitDialog()
{
CDHtmlDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
EDIT1 = AfxGetApp()->GetProfileString("Settings", "email", "your login");
EDIT2 = AfxGetApp()->GetProfileString("Settings", "password", "details here..");
UpdateData(FALSE);
return FALSE; // return TRUE unless you set the focus to a control
}
void Cfirstw32mfcDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDHtmlDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void Cfirstw32mfcDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<wparam>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDHtmlDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR Cfirstw32mfcDlg::OnQueryDragIcon()
{
return static_cast<hcursor>(m_hIcon);
}
HRESULT Cfirstw32mfcDlg::OnButtonOK(IHTMLElement* /*pElement*/)
{
UpdateData(TRUE);
//CString strEmail = SysAllocString(GetElementText( _T("email")));
//CString strEmail = GetWindowText(EDIT2);
//AfxGetApp()->WriteProfileString("Settings", "email", strEmail);
/*
BSTR bstr = SysAllocString(GetElementText( _T("email")));
CStringW str = bstr;
SysFreeString(bstr);
*/
if(!GetElementText( _T("email")))
{
m_EDIT1=("FALSE");
UpdateData(FALSE);
}
else
{
m_EDIT1=("TRUE");
UpdateData(FALSE);
}
BSTR bstr = SysAllocString(GetElementText( _T("email")));
CString str = CString(bstr);
SysFreeString(bstr);
m_EDIT1=str;
UpdateData(FALSE);
CString strEmail = "email";
AfxGetApp()->WriteProfileString("Settings", "email", str);
//AfxGetApp()->WriteProfileString("Settings", "email", EDIT1);
//AfxGetApp()->WriteProfileString("Settings", "email", );
AfxGetApp()->WriteProfileString("Settings", "password", EDIT2);
//UpdateData(FALSE);
return NULL;
}
HRESULT Cfirstw32mfcDlg::OnButtonCancel(IHTMLElement* /*pElement*/)
{
UpdateData();
if(m_EDIT1)
{
AfxGetApp()->WriteProfileString("Settings", "email", m_EDIT1);
}
else
{
m_EDIT1=_T("i failed");
UpdateData();
}
if(m_EDIT2)
{
AfxGetApp()->WriteProfileString("Settings", "password", m_EDIT2);
}
else
{
m_EDIT2=_T("i failed too");
UpdateData(FALSE);
}
//UpdateData(FALSE);
return NULL;
/*
GetElementText(_T("email"));
if(GetElementText(_T("email")))
{
EDIT1=_T("works");
}
else
{
EDIT1=_T("it doesn't work");
}
AfxGetApp()->WriteProfileString("Settings", "email", EDIT1);
GetElementText(_T("password"));
AfxGetApp()->WriteProfileString("Settings", "password", EDIT2);
OnCancel();
return S_OK;
//return 0;
*/
}
//HRESULT Cfirstw32mfcDlg::OnChangeEdit1(IHTMLElement* /*pElement*/)
//{
// //UpdateData(FALSE);
// //AfxGetApp()->WriteProfileString("Settings", "email", EDIT1);
// //AfxGetApp()->WriteProfileString("Settings", "email", "gsdsgj");
//return FALSE;
//}
//HRESULT Cfirstw32mfcDlg::OnEnChangeEdit2(IHTMLElement* /*pElement*/)
//{
// //UpdateData(FALSE);
// ///AfxGetApp()->WriteProfileString("Settings", "password", EDIT2);
//return FALSE;
//}
|
|
|
|
|
You should be able to do all your data sets and retrievals within the DoDataExchange
similar to something like this:
void Cfirstw32mfcDlg::DoDataExchange(CDataExchange* pDX)
{
CDHtmlDialog::DoDataExchange(pDX);
// data TO controls, means LOAD strings with your existing data or default values
// you need to do this BEFORE the DDX_DHtml_ElementInnerText calls
if( !pDX->m_bSaveAndValidate ){
EDIT1 = AfxGetApp()->GetProfileString("Settings", "email", "your login");
EDIT2 = AfxGetApp()->GetProfileString("Settings", "password", "details here..");
}
// these calls presumably set or get the data from the controls into your string variables
DDX_DHtml_ElementInnerText(pDX, _T("email"), EDIT1);
DDX_DHtml_ElementInnerText(pDX, _T("password"), EDIT2);
DDX_DHtml_ElementInnerText(pDX, _T("Temp_Text1"), m_EDIT1);
DDX_DHtml_ElementInnerText(pDX, _T("Temp_Text2"), m_EDIT2);
// data FROM controls, means SAVE data from the controls to your storage
// you need to do this AFTER the DDX_DHtml_ElementInnerText calls
if( pDX->m_bSaveAndValidate ){
GetElementText(_T("email"));
AfxGetApp()->WriteProfileString("Settings", "email", EDIT1);
GetElementText(_T("password"));
AfxGetApp()->WriteProfileString("Settings", "password", EDIT2);
}
}
If the DoDataExchange is correctly implemented, you don't even need to have the OnOK handler, since the DoDataExchange will be called for you (I am pretty sure) and you definitely don't need the Cancel, because the UpdatData (and thus DoDataExchange) is not called at all.
|
|
|
|
|
How do you determine the column on a listCtrl when you say double-click on the list.
I use the following to find the row:-
POSITION p = m_cAList.GetFirstSelectedItemPosition ();<br />
int row = m_cAList.GetNextSelectedItem (p);
I did think the use GetSelectedColumn() but GetSelectedColumn() gives the error:-
c:\C_Example\GenericDlg.cpp(602): error C2039: 'GetSelectedColumn' : is not a member of 'CListCtrl'
I have the listCtrl setup as a table with grid lines on and was going to use:-
int col = m_cAList.GetSelectedColumn();<br />
int index = (row * 16) + col;
To obtain the position in the table.
Help?!?
|
|
|
|
|
Do you have a handler for the NM_DBLCLK message? If so, look at the iItem and iSubItem members of the NMITEMACTIVATE structure that is sent to the handler function.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Getting a bit lost here, Yes do have a handler for the double-click on the listCtrl:-
void CGenericDlg::OnNMDblclkList(NMHDR *pNMHDR, LRESULT *pResult)<br />
{<br />
<br />
POSITION p = m_cAList.GetFirstSelectedItemPosition ();<br />
m_cAList.GetNextSelectedItem (p);<br />
int row = m_cAList.GetNextSelectedItem (p);
Just wanted to know how to get the column here.
But if I now do (I think this is what you suggested)
NMITEMACTIVATE *lpnmitem = (LPNMITEMACTIVATE) pNMHDR;<br />
<br />
int col = lpnmitem->iSubItem;<br />
<br />
int row = lpnmitem->iItem;
Here the col is OK but the row is always set to -1.
|
|
|
|
|
sweep123 wrote:
Just wanted to know how to get the column here.
ASAIK, you cannot find both row and column this directly. Use GetNextSelectedItem to retrieve the selected item index (the 'row') and the pNMHDR to retrieve the 'column' (as you did in your second method).
As for
sweep123 wrote:
Here the col is OK but the row is always set to -1.
-1 is the normal return value if you consider a subitem (see MSDN:
iItem Index of the list view item. If the item index is not used for the notification, this member will contain -1.)
-> you can only get information about one item _OR_ one subitem. Your list ctrl is not a grid, it is indeed a list.
~RaGE();
|
|
|
|
|