|
[snip]
There is another way to do this and use the generic recordset that is posted in the Database section.
[/snip]
What do you mean?
This is my first venture into doing anythign with databases (at least programatically, I HAVE used Access before )
I tried to look into the Enroll MFC sample, but it requires some database that you can't download from online (and I can't find my VStudio stuff right now...)
Adam
cabadam@houston.rr.com
|
|
|
|
|
In the Code Project's General section - Database area, there is an artical called "The CGeneric Database class".
What this does is allow you to use the CGeneric recordset without binding the columns the way Class Wizard does. You can either set/get the column data via the calls like GetBool( "Column Name" ); or GetBool( column number );
This is a Dynamic way to use DAO vs the static way that Class Wizard does it. Also if you add new fields to the table, you don't have to rework the code, just add the new Get/Set routines.
|
|
|
|
|
Visual Studio 6.0 Wizard don't support Access 2000. You must convert to Access 97 or use ODBC instead (Use CRecordset instead of CDaoRecordset)
|
|
|
|
|
How do I "paint" text/CString in an ActiveX window? A sample code will be helpful...Thanks!
|
|
|
|
|
Could somebody who's got the most recent Platform SDK please send me a couple of small files? I can't justify downlaoding the whole damned thing (or even a specific category) just for two files! Especially not from the UK on a 56k (~4kbs) connection I still havent' been able to order the CD, so this is my only option.
The files are:
DBGHELP.LIB
DBGHELP.DLL
.. and the header (if there is one).
Please post here if you can send them to me after sending them to stop me getting a mail box full of them.
Thanks in advance,
David Wulff
dwulff@battleaxesoftware.com
|
|
|
|
|
David, they’re on their way.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
I've finally figured out how to create a DAO Database, add the tables and add the fields to the tables, but I can't figure out how to add an index to a field.
Can someone give me a tumbnail sketch of how to attach an index to a field in a new database?
Thanks!
Richard
|
|
|
|
|
You do not add an Index to a field, but rather add the index to the CDaoTableDef using the field information. Use CDaoIndexInfo, CDaoIndexFieldInfo to define the index and then use CDaoTableDef::CreateIndex() to create the index in the table definition.
|
|
|
|
|
I'm having a heck of a time with this one guys so any points in the right direction or helpful tips will be greatly appreciated. I have used this 3rd party control a ton of times in Visual Basic (no flames ), it is written using VC++ and ATL. It compiles and builds fine, however, I get this error in occsite.cpp when running the application in debug mode "Unhandled Exception", and it breaks here:
DWORD COleControlSite::ConnectSink(REFIID iid, LPUNKNOWN punkSink)
{
ASSERT(m_pObject != NULL);
LPCONNECTIONPOINTCONTAINER pConnPtCont;
if ((m_pObject != NULL) &&
>>BREAK<< -> SUCCEEDED(m_pObject->QueryInterface(IID_IConnectionPointContainer,
(LPVOID*)&pConnPtCont)))
{
ASSERT(pConnPtCont != NULL);
LPCONNECTIONPOINT pConnPt = NULL;
DWORD dwCookie = 0;
if (SUCCEEDED(pConnPtCont->FindConnectionPoint(iid, &pConnPt)))
{
ASSERT(pConnPt != NULL);
pConnPt->Advise(punkSink, &dwCookie);
pConnPt->Release();
}
pConnPtCont->Release();
return dwCookie;
}
Here are the steps I have taken to get to this point. Added the control to a Dialog based application. Clicked on project->Add to project->Components and control. I click on the control in the Registered ActiveX controls (Oh, I used MFC and classwizard with dynamic link to MFC, and ActiveX support checked, and tried it with Automation support) select the control. Use the toolbox drag the control to a dialog, then use class wizard to assign it to a variable of type Control -> Class Name.
VC generated 4 wrapper classes, and then I build the app, no errors no problems, but when I hit F5 I get the error message above.
My assumption that all ActiveX controls, built on the COM architecture, are supposed to be interchangeable between enviornments. Is it possible this is not the case? Please post any help you can here, or feel free to email me, but I'm stumped on this one. I may have to use the C++ wrapper for the control, but shouldn't this step work?!?!
Thanks in Advance for any help!
Sam C
----
Systems Manager
Hospitality Marketing Associates
|
|
|
|
|
The above shouldn't say break, should of said ASSERTION in big bold letters
If anyone even has a guess to why this is happening or can explain to me why ActiveX controls aren't universal please do. Thanks.
Sam C
----
Systems Manager
Hospitality Marketing Associates
|
|
|
|
|
I need access to a CListBox variable which is in View.h, m_ctrlMyListBox, from various of my other classes. How can I get that?
|
|
|
|
|
You can access your view from anywhere like this:
CFrameWnd *pFrameWnd = (CFrameWnd *)AfxGetMainWnd();
ASSERT (pFrameWnd != NULL && pFrameWnd->IsKindOf(RUNTIME_CLASS(CMDIFrameWnd)));
pFrameWnd = ((CMDIFrameWnd *)pFrameWnd)->GetActiveFrame();
CMyView * pView = (CMyView*)pFrameWnd->GetActiveView();
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
Hi,
I have a dialog box, I've placed a tree control in it.
How can I populate that tree?I need to place items from a .dat file into that tree? I just don't know the basic syntax of doing it...
How do you add items?
Thanks!
P.S.
I'm new at this. Tried to use a sample from msdn, but the only thing that it does is gives me a tree with only "united states" in it.
Thanks again
// Gain a pointer to our tree control
CTreeCtrl* pCtrl = (CTreeCtrl*) GetDlgItem(IDC_TREE1);
ASSERT(pCtrl != NULL);
// Insert a root item using the structure. We must
// initialize a TVINSERTSTRUCT structure and pass its
// address to the call.
TVINSERTSTRUCT tvInsert;
tvInsert.hParent = NULL;
tvInsert.hInsertAfter = NULL;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = _T("United States");
HTREEITEM hCountry = pCtrl->InsertItem(&tvInsert);
// Insert subitems of that root. Pennsylvania is
// a state in the United States, so its item will be a child
// of the United States item. We won't set any image or states,
// so we supply only the TVIF_TEXT mask flag. This
// override provides nearly complete control over the
// insertion operation without the tedium of initializing
// a structure. If you're going to add lots of items
// to a tree, you might prefer the structure override
// as it affords you a performance win by allowing you
// to initialize some fields of the structure only once,
// outside of your insertion loop.
HTREEITEM hPA = pCtrl->InsertItem(TVIF_TEXT,
_T("Pennsylvania"), 0, 0, 0, 0, 0, hCountry, NULL);
// Insert the "Washington" item and assure that it is
// inserted after the "Pennsylvania" item. This override is
// more appropriate for conveniently inserting items with
// images.
HTREEITEM hWA = pCtrl->InsertItem(_T("Washington"),
0, 0, hCountry, hPA);
// We'll add some cities under each of the states.
// The override used here is most appropriate
// for inserting text-only items.
pCtrl->InsertItem(_T("Pittsburgh"), hPA, TVI_SORT);
pCtrl->InsertItem(_T("Harrisburg"), hPA, TVI_SORT);
pCtrl->InsertItem(_T("Altoona"), hPA, TVI_SORT);
pCtrl->InsertItem(_T("Seattle"), hWA, TVI_SORT);
pCtrl->InsertItem(_T("Kalaloch"), hWA, TVI_SORT);
pCtrl->InsertItem(_T("Yakima"), hWA, TVI_SORT);
|
|
|
|
|
Ah, the basic problem of the parent doesn't know that it has any children attached. Change your tvInsert.mask to include TVIF_CHILDREN and set the tvInsert.cChildren either true or false depending on if the parent has any children.
Another way is to create parents with no children, then when you add children to a parent, tell the parent that it now has children. When you add a child to a parent, call a function like UpdateParentItem( HTREEITEM hParent );
void UpdateParentItem( HTREEITEM hParent )
{
// Can't use ItemHasChildren() because it will always return
// the value of the item.cChildren variable.
// Need to get the first child and update the parent as needed.
// Getting the first child of a parent will always return either
// NULL if no children exist or the handle to the first child
// regardless of the item.cChildren variable.
HTREEITEM hChild = m_pTree->GetChildItem( hParent );
// Set up the item structure
TV_ITEM item;
ZeroMemory( &item, sizeof(TV_ITEM) );
item.hItem = hParent;
item.mask = TVIF_CHILDREN;
item.cChildren = hChild != NULL;
// Update the parent node to reflect the children state.
m_pTree->SetItem( &item );
}
Also make sure that when the tree control is created you set the TVS_HASBUTTONS or you will not see the plus/minus button on the parent. You would have to double click the parent to see if there is any children.
|
|
|
|
|
What are the issues involved with using multiple inheritence on MFC classes such as CDocument?
if I wanted to do this:
class CMyDocument : public CDocument, public iSomeAbstractClass
{
...
};
where iSomeAbstractClass is just a pure virtual class.
Should that work? What problems might I expect? Currently, when I try this I get compile errors out of my ON_MESSAGE handlers in the CMyDocument Message Map. The issue seems to be that it cannot convert from CMyDocument* to CWnd*.
|
|
|
|
|
ON_MESSAGE handler is for CWnd-derived objects only. CDocument is derived from CCmdTarget and can only have ON_COMMAND and friends in its message map.
The message handler macros in VC6 are not type safe, making CYourDoc a class with multiple bases only helps this error to surface at compile time.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hmmm, thats very interesting. I actually inherited all this crap, er, I mean code when I took this job last year. I had never paid much attention to what the message maps they had in the document classes were doing. Now that you mention that, it makes perfect sense. Thanks.
|
|
|
|
|
Tomasz, on further investigation I find that allowing a CDocument derived class to contain an ON_MESSAGE handler for another window appears to work fine, type safe or not. What our code does is this (I didn't write it!):
// In a seperate thread:
::PostMessage( hOurMainFrameWnd,AMessageID, NULL, NULL );
// Primary thread...
// COurDocument MESSAGE MAP...
ON_MESSAGE( AMessageID,OnMessage )
COurDocument ::OnMessage( .... )
{
// This is reached just fine.
}
We have worked our way around this issue, but I am just curious to know what your opinion is of this methodology? My input to my boss is that the CDocument/CMainFrame interaction here was bad design - but it does seem to work.
|
|
|
|
|
1) I can't reproduce the behavior you've described. I've added ON_MESSAGE macro to CDocument-derived messagemap. It doesn't get called when I'm sending/posting the message. Could you have a look at the stack when breakpoint is hit inside CYourDoc::OnMessage?
2) Here's how ON_MESSAGE is defined in VC 6:
#define ON_MESSAGE(message, memberFxn) \
{ message, 0, 0, 0, AfxSig_lwl, \
(AFX_PMSG)(AFX_PMSGW)(LRESULT (AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM))&memberFxn },
<pre>
The function should be a member of CWnd-derived class; I've heard that VC7 uses static_cast instead of old-style casting, your code may not compile under VC7.
3) There's a topic called "Message Categories" in VC help that explicitly says that non-CWnd objects derived from CCmdTarget can't handle messages other than WM_COMMAND. My understanding was that only WM_COMMAND is routed to document and app, but your experience denies that. I'd really like to see who's calling CYourDoc::OnMessage :-D
Tomasz Sowinski -- <a href="http://www.shooltz.com">http://www.shooltz.com</a>
|
|
|
|
|
Very curious indeed. I'm actually surprised, and concerned, that ours is working (although my boss isn't). We have a work around for the original problem, so its no longer an issue (until VC7 I suppose!). But if I get time I am going to look into this, just to satisfy my curiosity.
Thanks much, Stan.
|
|
|
|
|
|
Thanks. That's pretty much exactly what I was hoping to find.
|
|
|
|
|
This is my code:
-----------------------------------
void CMainDlg::OnButtonData()
{
CDemo dlg;
dlg.DoModal();
}
----------------------------------
and all is right.(not warnings or errors by compailer)
but when I press on cancle in run time in the Demo dialog I gets error message:
"illegal operation..." and all the program shut down .
This is the cod of OnCancle:
______________________________________
void CDemo::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
_______________________________________
Maybe it is because I need to give the constructor of Demo dlg the pointer to main CWnd ??? How do I this ???
|
|
|
|
|
You don't need to pass in the HWND, if NULL it just uses the desktop window.
Are there any controls on the demo dialog that may not be created or instantiated correctly?
|
|
|
|
|
This might not matter at all, but people generally call DoModal in an "if" statement, such as:
if (dlg.DoModal() == IDOK)
{
//do stuff
}
This way, when they hit cancel the program doesn't try to do anything you don't want. It seems like there might be some code that you only want executed when they click "OK", so you might try putting that inside the if block.
Jake
|
|
|
|
|