|
I've got an MDI MFC app.
(Irrelevant info in parentheses probably: I have a database class(built from ADO) )
An object 'db' is declared in view1. It opens a database which has to stay open while the program is running. Now I want to run one of the functions of db, in view2. View2 transmits a piece of information that is to be used in the argument list of the function. I need to use the same object, so I cant create a new one (cant open an already open database connection). What is the best mechanism to do this?
I was wondering about:
I only have two views and this tactic worked when I did a sendmessage from view2 to view1. But in the dropdown intellisense after doing pView-> I saw only the names of functions and didnt know if I could get to the db object as above.
Please let me know.
Thank you very much,
ns
The above snippet said that db was not a member of CView. I tried forcing it to be CTrain1View * (totally wrong I know) but was not acceptable to the compiler either.
Do I have to go via Doc variables and a sendMessage?
|
|
|
|
|
ns wrote:
An object 'db' is declared in view1. It opens a database which has to stay open while the program is running.
What stopped you from including 'db' in CYourDoc?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
It didnt want to do simple recordset functions like get record count etc. It bombed if I made it a doc object because the constructor creates all the objects like command and recordset etc. Thats why I put it in the View....
Thanks,
ns
|
|
|
|
|
in general, you should put all data and data manipulation functions in the doc and all data display functions in the view. the view should have very little to do with changing the data (except as is necessary to run the UI). anyway, that's the principle behind doc/view.
i usually send all data-changing UI events from the view to the doc, then let the doc call UpdateAllViews with enough information that the views can correctly show the data change. i rarely let the view actually change (and never store) the data directly.
-c
To explain Donald Knuth's relevance to computing is like explaining Paul's relevance to the Catholic Church. He isn't God, he isn't the Son of God, but he was sent by God to explain God to the masses. /. #3848917
|
|
|
|
|
I really wanted to do that, but as I said in my prev email, simple functions like fields->recordcount etc (native ADO functions) were crashing. The same object instantiated in the view performed fine! I'll try again, but am not confident they will work in the doc...
Thanks for your input,
ns
Gave it one final try as a doc object.....I think it may work! Some functions are anyways. Thanks so very much for the pointers
ns
|
|
|
|
|
While I agree that the db member should be in the doc and not in the view, there's nothing programatically wrong with what you've been doing. IntelliSense cannot show you the members of CTrain1View since your pView is of type CView*, but casting it to CTrain1View* should work:
POSITION pos = pDoc->GetFirstViewPosition();
while (pos!= NULL)
{
CTrain1View* pView = (CTrain1View*)(pDoc->GetNextView(pos));
ASSERT_VALID(pView);
pView->db.MyFunc(arg from view2);
}
But of course, hard-coding a type cast like this is error prone. You could make it a little nicer by checking the type before the cast:
CView* pView = pDoc->GetNextView(pos);
ASSERT_VALID(pView);
if (pView->IsKindOf(CRUNTIME_CLASS(CTrain1View)))
((CTrain1View*)pView)->db.MyFunc(arg from view2);
Still, putting it in the doc is the right thing to do.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
when I run an MDI application and keep clicking down a non-client
area of a window, all other window look dead, which means they
don't draw anything on their client area. This is critical when
I develop a timer based application because all the timer message
are also blocked by keeping down my mouse cursor on a non-client
area of a window.
I want to avoid this. I want to make all windows run although I
keep clicking down the caption bar of a window.
Does anybody know a solution for this problem?
|
|
|
|
|
I am working on a multiple document MFC program and am having a little trouble getting the standard save dialog to work properly. This is the problematic code:
static char BASED_CODE szFilter[] = "Quizbowl Team (*.qbt)|*.qbt|All Files
(*.*)|*.*||";
CFileDialog m_File(TRUE, NULL, NULL, OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT, szFilter, this);
m_File.m_ofn.lpstrTitle = "Open Quizbowl Team";
if(m_File.DoModal() == IDOK)
{
...
((CMainFrame*)GetParent())->SwitchToForm(IDD_TEAMBLD_ROSTER);
...
}
What happens is that as soon as m_File.DoModal() is executed, all of the items in DoDataExchange no longer work. Any help would be appreciated.
|
|
|
|
|
bjenning wrote:
all of the items in DoDataExchange no longer work
Why? Did you call UpdateData(FALSE) somewhere in your program?
|
|
|
|
|
Nope, no UpdateData(FALSE) (no UpdateData(TRUE) in the problem function either). The problem that I am having is when it enters the next dialog. None of the sounds or pictures show up. This is also the case for each of the other dialogs in the project.
|
|
|
|
|
Maybe I'm just being stupid and missing something simple. Do you know of any good example code I could look at to make sure I'm using the CFileDialog class correctly? Thanks for your help.
|
|
|
|
|
Your code looks correct! That's why I guess your problem is somewhere else. I even use
same type of code in my script article.
void CScriptDemoDlg::OnBtnBrowse()
{
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
_T("Script Files (*.js; *.vbs)|*.js;*.vbs|Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"));
if (dlg.DoModal() == IDOK)
{
}
}
As my daughter would say, "... Whatever!"
|
|
|
|
|
I'm using CFormView in my program, and in one of my handlers, I open a new view and attempt to close the current. I call DestroyWindow() to kill the window. When I run it, the new form opens and the old one ends up behind it, but doesn't close. Everything inside the form turns to white, but the frame around it stays and can be repositioned as it normally does. It's as if the form itself has closed, but it has left the frame behind.
Has anyone seen this? I've also tried posting a WM_CLOSE message, but that does nothing at all. Can someone please help?
|
|
|
|
|
Are you destroying the view, or its frame?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
I guess it's the View. How can i destroy the Frame?
|
|
|
|
|
GetParentFrame()->DestroyWindow();
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Ahhh...excellent. Thank you very much.
|
|
|
|
|
Hi there,
I want to write a database program with ADO which it don't needed to install new components in the system for running …
In a word, it must run on Win98 or later …
I wanna know, what's ADO version on Win98 Arabic in default …
I want to know, does Access 97 support Farsi text in the records ???
Thanks in advance.
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
I suspect you'll need to install MDAC regardless.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
|
|
|
|
|
Hello Christian
That's it ... I don't want to install any components like that ...
I just want to use ADO !!!!!!!!
MY PROGRAM MUST WORK ON WIN98 OR LATER !!!
Can i do it ????
I mean without installing MSDAC.
Could u tell what's ADO version in Win98 ?
Please help me ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
OK, I'll wave my magic wand and install MDAC on every W98 machine on the planet. Done.
You can't do it, I can't help you or change that. You'll need MDAC. End of story.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
Cats, and most other animals apart from mad cows can write fully functional vb code. - Simon Walton - 6-Aug-2002
|
|
|
|
|
Hi Christian,
hmmm, yes i think so ...
At least i have to update ODBC and OLEDB drivers ...
And i can do it only by MSDAC !!!
thanks for reply !
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
I have a server and a client app. I want to send some data from server to client without a request from client. How could the client get the data from server with only a event ?
I know I can get if the server use PostMessage function, but only using a wparam (16 bits) and lparam (32 bits).
Thanks,
Cristiano.
|
|
|
|
|
|
Hi. My problem is this:
I create a window using CreateWindowEx(). Then I create other windows[tool windows, document window etc...] All these are in non-MFC. The problem is that, if the user clicks on one of the tool windows, the mother window and all others lose focus[The title bars of those windows become gray]. And similarly if any window is clicked all others lose focus. I hear you saying "so what?". Here is the problem: When I start a DialogBox() only the spawning window is blocked, other windows are not. But I want them all blocked until the DialogBox returns.
I tried an MDI program generated by Visual C++ 6.0's wizard. What I want is exactly that(all windows titles are always highlighted!) but in a non-MFC way.
I tried different combinations of OVERLAPPED, CHILD, POPUP etc. but couldnt get it right. Can anybody help me?
Thanks
Oztan
PS: By the way I think being highlighted is my problem that is why I am talking about it. Actually I dont care which windows are highlighted and which are not, I just want the DialogBox() to block them all.
|
|
|
|