|
Hello,
I want to be able to display a dialog (connect to database) before my view is displayed.
The dialog contains my connect information and I've included a variable based on the dialog class in my Document class.
In my main application I put following statement:
cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;
This works fine.
I have a problem to figure out in which function I need to call the GetDocument()->m_dlg.DoModal()
I tried in OnCreate of my view, but I don't know what function to call if I press the cancel button in my dialog so I don't see any document/view. If I call return -1 in CMMyView::OnCreate, I get an error message saying that the creation of my view was not succesful.
If I put the DoModal in OnInitialUpdate I already see the docuemnt window and this is not what I want.
Please help me out on this one
Thanks
Wim Jans
|
|
|
|
|
Not sure if this will help or not, but...;)
Try overriding OnFileNew in either your Doc or your View class. More than likely in your Doc class. Just make sure you return the function to the base class so that It can finish processing it correctly.
If this tip helped it was written by me, if not I don't know who wrote it.
Frank
"Gumbercules? I love that Guy"
- Dr. Zoidberg
|
|
|
|
|
but I don't know what function to call if I press the cancel button in my dialog so I don't see any document/view.
AfxGetMainWnd()->PostMessage ( WM_CLOSE );
--Mike--
http://home.inreach.com/mdunn/
"Make sure that if you are using a blow torch that you don't set anything on fire."
-- Chris Maunder
|
|
|
|
|
Thanks, but this doesn't work like I want it to work.
What I want is: when I choose File/new... (ctrl-n) a dialog is displayed before my mdi child window is displayed. If I close the dialog by pressing cancel, I don't want to see the child window at all. The other document child windows should sill be open however.
I tried to show the dialog in CMyView::OnCreate, but if I try to do AfxGetMainWnd()->PostMessage , I get an debug error.
Is AfxGetMainWnd()->PostMessage ( WM_CLOSE ); not closing the complete application by the way?
After that, I tried to put the code in CMyView::OnInitialUpdate, but then he already displayed my child window before showing my dialog -even if I put CView::OnInitialUpdate at the end.
I think overriding CMyView::OnCreate is perfect (with my basic knowledge so far) for what I want to do, but how can I say: ok, forget about creating this new document, I just don't have enough information. If I return -1 in OnCreate, he will complain about Failed to create empty document'.
As suggested by Frank, I tried to override the OnFileNew in my view class, but this doesn't work if I currently have no open documents. I did this by putting cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;.
Sorry if my explanation is a bit vague, but I'm not a native English speaker.
Thanks for your time.
Wim Jans
|
|
|
|
|
A quick search of MSDN showed that OnFileNew is ACTUALLY a member of CWinApp...Try overriding it in your CWinApp derived class...
ie:
BEGIN_MESSAGE_MAP(CScribbleApp, CWinApp)
.
.
ON_COMMAND(ID_FILE_NEW, OnMyFileNew)
END_MESSAGE_MAP()
void CScribbleApp::OnMyFileNew()
{
OnFileNew();
CFrameWnd* pFrame = (CFrameWnd*)m_pMainWnd;
ASSERT_KINDOF(CFrameWnd, pFrame);
CScribbleView* pView =
(CScribbleView*)pFrame->GetActiveView();
ASSERT_KINDOF(CScribbleView, pView);
pView->GetDocument()->Initialize();
}
This example is straight out of MSDN, specifically you can search MSJ November 1996.
Hope this helps.
Frank
"-We're about to enter the heart..."
"...Where the food is digested."
-Dr. Zoidberg
|
|
|
|
|
After a night of sleep, I found the solution this morning.
I just put the code in CMyDocument::OnNewDocument
if (dlg.DoModal()!=IDOK) return FALSE;
This works, the only problem is that, if I startup the application with a new document, the dialog is displayed beffore my actual application is displayed.
I'll have a look into that.
Thanks anyway, it's good to know people spent there time helping others even on a sunday
Wim
|
|
|
|
|
can anyone please tell me what the simplest way is to see if a ceratin string is in another CString, for example:
i have a CString with value: "coffee smells terrible"
and i want to see if "err" is in that string(in "terrible"), how do i do that?
thanx
Kun
|
|
|
|
|
You can use the Find function of CString. So you would have something like this:
int pos;
CString buffer;
buffer = "coffee smells terrible";
pos = buffer.Find("err");
if(pos != -1)
{
}
This should work for both MFC and WTL.
Steve Maier, MCSD
|
|
|
|
|
|
CString strCoffee = "coffee smells terrible";
int iSearch = strCoffee.find("err");
if (iSearch != -1)
{
//found it.
}
else
{
//couldn't find it.
}
|
|
|
|
|
Ummm, you got the method name case wrong...
CString sBuffer(_T("The coffee smells terrible"));
if (sBuffer.Find("err") >= 0)
{
}
else
{
}
Also, keep in mind that string searches in a CString are case-sensitive, so if that matters, you may want to use the CString::MakeLower() function befoire running your search.
|
|
|
|
|
Hi,
How to totally remove the help button from a wizard
(CPropertySheetEx)? thanks.
p.c.
|
|
|
|
|
One Way:
BOOL CMyPropertySheet::OnInitDialog()
{
CPropertySheetEx::OnInitDialog();
// this hides the Help button
CWnd* pHelpButton = GetDlgItem (IDHELP);
ASSERT (pHelpButton);
if (pHelpButton)
pHelpButton->ShowWindow (SW_HIDE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Bill
|
|
|
|
|
Search MSDN for PSP_HASHELP and PSH_HASHELP
You have to remove those flags from pages/sheet to completely remove help button. You may do this in the constructor.
Paolo
------
"airplane is cool, but space shuttle is even better" (J. Kaczorowski)
|
|
|
|
|
I'm pretty new to ADO and need some guidence. I'm using MS Access 2K. I have
three tables. The tables looks as follows:
UserAccounts
------------
UserAcctID (key, autonumber)
UserAcctData
Queues
------
QueueID (key, autonumber)
QueueName
QueueRights
-----------
UserAcctID (foreign key)
QueueID (foreign key)
Rights
I'm using ADO and DCOM so there's potential of multiple admin users trying
to access and modify the tables at one time. I need to ensure that referential
integrity is ensured, and wondered if developers typically use locking mechanisms
or the referential integrity tool in MS Access, or both.
I also, have the following situations, and am not sure of the best way to resolve
them in terms of locking and ensuring that the keys/data won't be out of sync:
1) When one admin is editing another user's account, another admin cannot edit that
user's account. What's the best way to lock the account? Add a lock timestamp
column to UserAccounts?
Also, is this a user-friendly restriction? Do other administration program lock
another user from editing the same account, or do they allow them to edit it and
then notify them that it has changed when it's time to update and for them to reload
and redo what they've done?
2) When an admin is about to update another user's queue rights, I would need to
lock the entire "Queues" table from being added to while records are being added
or updated to the QueueRights table. What's the best way of accomplishing that?
3) Also are there any good websites and/or books that discusses how to resolve
issues with multiple users and databases?
Thanks in advance for any help!
|
|
|
|
|
Hi,
I want to use a CTabCtrl, not a propery sheet.
What I am looking for is a convenient way to design each of the tab pages, and hide & show them.
What's the common way of using a CTabCtrl to embed pages. Quite shocked by the lack of resources on this topic, or is it actually straight forward?
Cheers Again!
Richard
|
|
|
|
|
Hi
I'm new to c++ and like to know what's the difference between these two declarations:
int something[20];
and
int *something = new int[20]
delete something;
|
|
|
|
|
10 ints.
in the first sample, the 30 ints are allocated on the stack and are therefore cleaned-up automatically when the program leaves the function - so they don't live outside that function. in the second, they are allocated on the heap and you have to clean them up yourself.
one benefit of the first is automatic clean up. one benefit of the second is that the data can have a lifetime longer than that of the function that allocated it.
just a note: in general, it's not nice to allocate large amounts of memory on the stack (30 ints isn't "large").
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Thanks, now I want to check if I unterstand what you just explain
void func1()
{
int something[20];
...
}
void func2()
{
int *something = new int[20];
...
delete something;
}
In func1 the variable isn't available anymore after the function has quit, in func2 it is available even after the function has quit?
|
|
|
|
|
No, because you
a/ did not store the pointer, and
b/ deleted it.
What *is* true is if I had a vector ( an array class in the Standard Template Library ) that stored pointers to ints ( normally it would make no sense to store an int pointer, you may well, however, store a pointer to a struct or class you defined, or something like a bitmap ), then if I did this:
int i = 20;
myvector.push_back(&i);
I would be in trouble, as I would have stored the address of an int that went out of scope and was destroyed. This is one of the two dangers of pointers - if I store a memory address and the contents get deleted, if I try to use it, everything is likely to die in a hurry.
If I did this though:
int * pInt = new int;
pInt = 20;
myvector.push_back(pInt);
then I am fine - the int won't be destroyed as using a pointer put me in control of that, and memory is not leaked ( the other danger, forgetting to delete something or remember the pointer value ( the address in memory it is stored ) ) because my vector takes responsbility for storing the pointer.
The reason one might do this with large objects is because it is super fast to pass a pointer into a function, for example, because you're moving a memory location, not a huge chunk of data.
Hope that helps.
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.
|
|
|
|
|
First off, in the second function you should be using operator delete[], or else your just deleting the first allocated integer -- and thus a memory leak.
void func2() {
int * something = new int[20];
delete [] something;
}
>>>
In func1 the variable isn't available anymore after the function has quit, in func2 it is available even after the function has quit?
<<<
Almost, since you delete the array in func2 it will no longer exist. But had you not called delete the memory would have persisted even after the function went out of scope.
Doing something like this;
int * func2() {
int * something = new int[20];
return something;
}
Would preserve the allocated memory, even after the function goes out of scope.
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
First off, in the second function you should be using operator delete[], or else your just deleting the first allocated integer -- and thus a memory leak.
Ooops - I missed that one. As a matter of interest, while I would never advocate using anything other than delete [] for an array, I am led to believe under VC++ it makes no difference because of the way it is implimented.
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.
|
|
|
|
|
>>>
Ooops - I missed that one. As a matter of interest, while I would never advocate using anything other than delete [] for an array, I am led to believe under VC++ it makes no difference because of the way it is implimented.
<<<
Good call, unless my debugger is missing the leak, it seems to work perfectly... very strange.
>>>
The careful application of terror is also a form of communication.
<<<
Did you by any chance have a talk with my professors? He seems to have adopted the same philosophy
cheers,
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Hello, the codegurus around the world.;)
We can keep the variable by the global variable, reference, and pointer
to keep the variable alive out of the function in especially C.
1) Delcare int something[20] as the global variable.
2) Use the reference by the function parameter.
void func1(int &a[20]);
3) Use the pointer by the funtion parameter
void func2(int *a);
In C++, we can use the member variable by private or protect,
we can simply assign this array or pointer to the new value
inside the function.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
>First off, in the second function you should be
>using operator delete[], or else your just deleting
>the first allocated integer -- and thus a memory
>leak.
This is innacurate. The operator 'delete[]' calls a destructor for each member of an array while the operator 'delete' simply deletes the array itself. For simple types which require no destructor, 'delete' works just fine.
(Note: This is definitely Visual C++ behavior. Some may argue that this isn't strictly ANSI C++ but I disagree and here's why: delete[] indicates that I am deleting an array of objects, delete indicates that I am deleting an object which may, or may not, be an array.
Having said that, I actually use malloc/free for the latter case. It's usually faster and makes for clearer code since it indicates that what I wanted was a chunk of memory, nothing more, nothing less.)
|
|
|
|
|