|
In yout CFormView derived Class, you can use the C++ Class Wizard to make you a Handler for the Message 'OnInitialUpdate'.
In the body of this message-handler function, you can do the calls needed.
OnInitialUpdate() is the right function for all first-time initialisations of views and their childs.
|
|
|
|
|
I know that,but I don't know how to set FlexGrid's DataSource so that connect to the RDC(Remote Data Ctrl).
How to pragrammically set its DataSource attribute?
Sincerely,Pole.
|
|
|
|
|
Hello,
I’m trying to load A listbox object with table names from an access database file. I’m working with two dialogs. One is my main Dialog and the other is a dialog with a listbox object attached to it. When I try to add table names
To the list box an ASSERTION happens. I believe the Dialog with the listbox is destroyed before the AddString() function can load the table names. If this is true is there away around this? Any help would be much appreciated.
Thanks
Karl
<br />
void CLoadTablesDlg::OnButtonOpen() <br />
{<br />
CTableDlg dlgTable;<br />
<br />
_RecordsetPtr m_pRstOpenSchema;<br />
_ConnectionPtr m_pConnection;<br />
<br />
TCHAR szFilters[] = _T("Access files(*.mdb) | *.mdb | All files(*.*) | *.*||");<br />
<br />
CFileDialog dlg (TRUE, _T("mdb"), _T("*.mdb"),<br />
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);<br />
<br />
if(dlg.DoModal () == IDOK)<br />
m_sFileName = dlg.GetPathName();<br />
<br />
HRESULT hr;<br />
<br />
_bstr_t strCnn("Provider=Microsoft.Jet.OLEDB.3.51; Data Source= " + m_sFileName + ";");<br />
<br />
try<br />
{<br />
hr = m_pConnection.CreateInstance(__uuidof(Connection));<br />
if(SUCCEEDED(hr))<br />
{<br />
m_pConnection->Open(strCnn, "", "", adModeUnknown);<br />
m_pRstOpenSchema = m_pConnection->OpenSchema(adSchemaTables);<br />
<br />
while (!(m_pRstOpenSchema->adoEOF))<br />
{<br />
_bstr_t table_name = m_pRstOpenSchema->Fields->GetItem("TABLE_NAME")->Value;<br />
<br />
CString strTableName = (LPCSTR)table_name;<br />
dlgTable.m_lstTables.AddString(strTableName);<br />
m_pRstOpenSchema->MoveNext();<br />
}<br />
<br />
}<br />
}<br />
catch (_com_error &e)<br />
{<br />
_bstr_t bstrSource(e.Source());<br />
_bstr_t bstrDescription(e.Description());<br />
TRACE( "Exception thrown for classes generated by #import" );<br />
TRACE( "\tCode = %08lx\n", e.Error());<br />
TRACE( "\tCode meaning = %s\n", e.ErrorMessage());<br />
TRACE( "\tSource = %s\n", (LPCTSTR) bstrSource);<br />
TRACE( "\tDescription = %s\n", (LPCTSTR) bstrDescription);<br />
}<br />
catch(...)<br />
{<br />
TRACE( "*** Unhandled Exception ***" );<br />
}<br />
<br />
}<br />
|
|
|
|
|
You can call AddString only after DoDataExchange was called (it's called by CDialog::OnInitDialog) and before dialog ends modal state.
You'll have to add strings in DoDataExchange or in InitDialog.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
Russ Freeman wrote:
I want to add a toolbar to a view and I would like it to use the command routing for enabling and disabling of buttons
You don't route commands through toolbar. All you need to do is ensure that CToolBar::OnUpdateCmdUI is called - it will use MFC routing for enabling/disabling buttons.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
Hi,
I'm trying to send a piece of mail using Simple MAPI's MAPISendMail function and, the linker is complaining that it can't find the function.
I'm linking to mapi32.lib, but this seems not to contain the function (mapi32.dll does, however, because I can access it from GetProcAddress). Does anyone know what the problem is?
Thanks,
Rich
|
|
|
|
|
I had the same problem in the past. You've got to do the lynking dynamically yourself (Microsoft admits the error here[^]. Here's some lines for the program I wrote back then, I guess it'll save you some tedious coding:
#include <mapi.h>
static HINSTANCE hMAPI=NULL;
#undef MAPILogon
#undef MAPILogoff
#undef MAPISendMail
#undef MAPISendDocuments
#undef MAPIFindNext
#undef MAPIReadMail
#undef MAPISaveMail
#undef MAPIDeleteMail
#undef MAPIFreeBuffer
#undef MAPIAddress
#undef MAPIDetails
#undef MAPIResolveName
#define MAPILogon (*lpfnMAPILogon)
#define MAPILogoff (*lpfnMAPILogoff)
#define MAPISendMail (*lpfnMAPISendMail)
#define MAPISendDocuments (*lpfnMAPISendDocuments)
#define MAPIFindNext (*lpfnMAPIFindNext)
#define MAPIReadMail (*lpfnMAPIReadMail)
#define MAPISaveMail (*lpfnMAPISaveMail)
#define MAPIDeleteMail (*lpfnMAPIDeleteMail)
#define MAPIFreeBuffer (*lpfnMAPIFreeBuffer)
#define MAPIAddress (*lpfnMAPIAddress)
#define MAPIDetails (*lpfnMAPIDetails)
#define MAPIResolveName (*lpfnMAPIResolveName)
static LPMAPILOGON lpfnMAPILogon=NULL;
static LPMAPILOGOFF lpfnMAPILogoff=NULL;
static LPMAPISENDMAIL lpfnMAPISendMail=NULL;
static LPMAPISENDDOCUMENTS lpfnMAPISendDocuments=NULL;
static LPMAPIFINDNEXT lpfnMAPIFindNext=NULL;
static LPMAPIREADMAIL lpfnMAPIReadMail=NULL;
static LPMAPISAVEMAIL lpfnMAPISaveMail=NULL;
static LPMAPIDELETEMAIL lpfnMAPIDeleteMail=NULL;
static LPMAPIFREEBUFFER lpfnMAPIFreeBuffer=NULL;
static LPMAPIADDRESS lpfnMAPIAddress=NULL;
static LPMAPIDETAILS lpfnMAPIDetails=NULL;
static LPMAPIRESOLVENAME lpfnMAPIResolveName=NULL;
if((hMAPI=LoadLibrary("MAPI32.DLL"))==NULL)
{
}
if(
(lpfnMAPILogon=(LPMAPILOGON)GetProcAddress(hMAPI,"MAPILogon"))==NULL||
(lpfnMAPILogoff=(LPMAPILOGOFF)GetProcAddress(hMAPI,"MAPILogoff"))==NULL||
(lpfnMAPISendMail=(LPMAPISENDMAIL)GetProcAddress(hMAPI,"MAPISendMail"))==NULL||
(lpfnMAPISendDocuments=(LPMAPISENDDOCUMENTS)GetProcAddress(hMAPI,"MAPISendDocuments"))==NULL||
(lpfnMAPIFindNext=(LPMAPIFINDNEXT)GetProcAddress(hMAPI,"MAPIFindNext"))==NULL||
(lpfnMAPIReadMail=(LPMAPIREADMAIL)GetProcAddress(hMAPI,"MAPIReadMail"))==NULL||
(lpfnMAPISaveMail=(LPMAPISAVEMAIL)GetProcAddress(hMAPI,"MAPISaveMail"))==NULL||
(lpfnMAPIDeleteMail=(LPMAPIDELETEMAIL)GetProcAddress(hMAPI,"MAPIDeleteMail"))==NULL||
(lpfnMAPIFreeBuffer=(LPMAPIFREEBUFFER)GetProcAddress(hMAPI,"MAPIFreeBuffer"))==NULL||
(lpfnMAPIAddress=(LPMAPIADDRESS)GetProcAddress(hMAPI,"MAPIAddress"))==NULL||
(lpfnMAPIDetails=(LPMAPIDETAILS)GetProcAddress(hMAPI,"MAPIDetails"))==NULL||
(lpfnMAPIResolveName=(LPMAPIRESOLVENAME)GetProcAddress(hMAPI,"MAPIResolveName"))==NULL){
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Hi, everyone!
I wondered where the variable __STDC__ is defined.
I write a simple C program to test it, before include
other .h files, the variable is already defined.
(I use #ifdef to test the existence)
I have two question about the variable:
1. Where is the variable defined?
2. What is the function of the variable?
Cheers,
George
|
|
|
|
|
__STDC__ isn't a variable. It's a predefined preprocessor macro. Your Visual C++ help would tell you that __STDC__ Indicates full conformance with the ANSI C standard. Defined as the integer constant 1 only if the /Za compiler option is given and you are not compiling C++ code; otherwise is undefined. .
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
Thanks, Tomasz my old friend!
I still have a question. Who should
define value of the macro? The source code
developer by hand? Or the system will
automatically add the setup of the macro
to the source code?
Cheers,
George
|
|
|
|
|
George Ma wrote:
Or the system will automatically add the setup of the macro to the source code?
'The system' isn't going to add the macro to sourc code. It will be predefined given the conditions described in MSDN. You can use the macro for preprocessor directives like #ifdef.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
Thanks, Tomasz pal!
I think the macro is defined at the compling time,
am I correct?
Cheers,
George
|
|
|
|
|
Hello,
This might be a stupid question . I'm trying to save and load settings in my program using CFileDialog. The problem is that opening the file I've saved fails most of the times, but not always. I'm assuming that it is because of a sharing violation, because CFileException gets a value 0xb, which means CFileException::sharingViolation. Please correct me if I'm wrong. lOsError got a value 0x20, but I can't find what that means.
So my question is, why does'nt the opening succeed? If it's because of sharing violation, what might be causing it? Not closing the file last time it was used might be, but I think it's something else, because opening fails randomly, like if I try to open it two times a row, the first trying fails and the next one succeeds.
Here's how I'm trying to do it:
void SettingsDlg::OnLoadButton()
{
UpdateData();
CString cstrFileName;
CFileDialog FileDlg(TRUE,
"cnf",
NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR,
"Configuration files (*.cnf)|*.cnf|All files (*.*)|*.*||");
if ( FileDlg.DoModal() == IDOK )
{
cstrFileName = FileDlg.GetPathName();
CFile* pFile = new CFile();
ASSERT (pFile != NULL);
CFileException *pExc = new CFileException(TRUE);
if ( !pFile->Open(cstrFileName, CFile::modeRead | CFile::shareExclusive, pExc) )
{
MessageBox("Error: Unable to open the file.");
delete pFile;
pFile = 0;
return;
}
bool bReading = true;
CArchive* pArchive = NULL;
try
{
pFile->SeekToBegin();
UINT uMode = (bReading ? CArchive::load : CArchive::store);
pArchive = new CArchive (pFile, CArchive::load);
ASSERT (pArchive != NULL);
}
catch (...)
{
MessageBox("Error: Unable to read from the file");
pFile->Close();
delete pFile;
pFile = 0;
return;
}
Serialize(*pArchive);
UpdateData(FALSE);
delete pArchive;
pArchive = 0;
pFile->Close();
delete pFile;
pFile = 0;
}
}
Please, help me
-Janetta
|
|
|
|
|
The error codes you've posted are indeed related to sharing violation - some other process has the file open, and you're trying to access the exclusive access to file (CFile::shareExclusive flag does this).
You may check www.sysinternals.com[^] and download their 'Handle' utility which displays information about open files.
On the other hand, you may just drop 'shareExclusive' flag.
BTW: why on Earth are you allocating your CFile and CArchive objects on the heap? You can just use local variables.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
Tomasz Sowinski wrote:
On the other hand, you may just drop 'shareExclusive' flag.
I'm using that already, or am I doing it in a wrong way? It's used like this: if ( !pFile->Open(cstrFileName, CFile::modeRead | CFile::shareExclusive, pExc) )
I'll check the address you gave.
Thanks,
-Janetta
|
|
|
|
|
Sorry - I wasn't too clear. By dropping I meant removing the flag and using CFile::modeRead without shareExclusive or modeRead with shareDenyNone.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
Ok, now I understood. And it helped. I'll go through the link later anyway, it seemed interesting.
Thanks.
-Janetta
|
|
|
|
|
Search MSDN for IActiveScript and IActiveScriptSite.
This should give you a starting point for including Windows Scripting. There is a very good article by Don Box on MSDN too. (I haven't got a link to hand but it should come up in your search)
Michael
Programming is great. First they pay you to introduce bugs into software. Then they pay you to remove them again.
|
|
|
|
|
|
Tcl/TK is perfect for this kind of stuff!
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Easy question
Where (header-file) can I find the minimum and maximum ranges for all the types in c++? Something like DOUBLE_MAX or INT_MIN ...
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
limits.h for integers and float.h for floating point numbers.
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
That's the C solution, but in C++ you can use the numeric_limits class defined in <limits> . for example:
#include <limits>
using namespace std;
numeric_limits<int>::min();
numeric_limits<float>::max();
|
|
|
|
|
markkuk wrote:
That's the C solution, but in C++ you can use the numeric_limits class defined in <limits>.
Good point. But I have to admit that I hate to type std::numeric_limits<int>::max()
Tomasz Sowinski -- http://www.shooltz.com
Free your mind and your ass will follow.
|
|
|
|
|
INT_MAX is indeed much shorter
tnx!
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|