After exiting DoModal, the attached window of CDialog object is destroyed and detached, so there is no problem to call DoModal again.
For a modeless dialog (made with CDialog::Create), unless the CDialog object goes out-of scope or DestroyWindow was called, the window is not destroyed, not even the user pushes OK/Cancel/close button.
So you have to test if the dialog was created before call CDialog::Create.
If yes, then simply show it:
void CFoo::ShowModelessDialog(CDialog& dlg, UINT nResID)
if(!::IsWindow(dlg.m_hWnd)) // thest attached window handle
// create only if not yet created
// ... somewhere ...
// ... and no problem to show again
NOTE: You can test m_hWnd against NULL instead of calling ::IsWindow, as well.
In you use this code
this is not safe, because the dlg object is created in Stack and it will get destroyed
as soon as the function is out of scope.
Create ModeLess Dialogs in Heap or Make Sure that the Object is not out of scope by making is
static or Global/Top Clsss Variale Like.
One Way of Doing It is:
static CMy * Dlg =NULL;
Dlg= new CMy();
Hey, hey, dear Indian Idol!
To be clear.
I didn't suggest to declare a CDialog object locally in a function. Did you see that in may example?
If you pay a little bit more attention, can observe that I prefixed with m_ which suggest that m_dlg is a member of class CFoo.
And your static CMy *Dlg locally declared in OnSomeFunction() smells a C.
And by the way... where you think it's possible to delete *Dlg in order to get rid of memory leaks?
Working on a wizard type dilaog application and taken the idea of creating wizard from the below link
Here having one problem:
what I am doing is that Suppose right now on property page number 3 and performing some operaion, after finishing operation want to jump on the next page (number 4) automatically, without clicking on the Next Button.
For this using SetActivePage(int i) function. but this function throws exception.
One more thing that when I jump from Page 3 to Page 2 it jumps successfully, problem is with the pages ahead.
So Please tell me that how to jump over the next page in the wizard automatically
You get exception because dialog for the 'next' page has not been created yet.
I usually send a 'faked' next button press to the parent of wizard pages and it 'thinks' the user has pressed next button. That seems to always work out well.
I've seen better runs in my shorts! - Patches O'Houlihan
Hi,I have taken FormView,in which i have created ListControl,The client area, "rect" of the FormView is taken is taken as i/p for ListControl Creation.I have handled WM_CONTEXTMENU in the formview,in the ContextMenu,there are two items one is "Print" another is "PntView"..ON_COMMAND of both ID_PRINT and ID_PRIVIEW i have handled in formview.in the respective functions i have called CFormView::OnFilePrint,CFormView::OnFilePrintPriview,i have overriden "Onprepareprinting" and "OnPrint".When i click print in the context menu , it is printing,when i click priview in the context preview is coming,but in the preview when i print button,it is not printing , what could be the reason...
i want to change email address in outlook2003 when the user submit the message. i use IExchExtMessageEvents::OnCheckNames(IExchExtCallback *lpExchangeCallback) to change email-address. my code is following.
And i see the email-address have changed on debugging. but at last, outlook2003 still send message using the old email-address, and abandon my changed email-adddress, why???
who will give me some suggestions?? or is there any other ways to changed email address??
thanks a lot.
my email is: firstname.lastname@example.org
//in VC6, winxp2, outlook2003
class mymail : public IExchExt, public IExchExtMessageEvents
STDMETHODIMP mymail::OnCheckNames(IExchExtCallback *lpExchangeCallback)
HRESULT hRet = S_OK;
LPMESSAGE lpMessage = NULL;
LPMDB lpMdb = NULL;
LPADRLIST pRecipentRows = NULL;
if( pRecipentRows->cEntries == 0 )
for(unsigned long n = 0; n < pRecipentRows->cEntries; n++ )
for(unsigned long i = 0; i < pRecipentRows->aEntries[n].cValues ; i++)
ULONG ulTag = pRecipentRows->aEntries[n].rgPropVals[i].ulPropTag;
if( PR_EMAIL_ADDRESS == ulTag || PR_DISPLAY_NAME == ulTag)
// i get the current email address correctly, such as "email@example.com"
LPSTR pNow = pRecipentRows->aEntries[n].rgPropVals[i].Value.lpszA;
// i want to change email address to "firstname.lastname@example.org"
char* p = "email@example.com";
char* pNewContact = NULL;
MAPIAllocateBuffer(strlen(p)+1, (LPVOID FAR *)&pNewContact);
strcpy((char*)pNewContact, (const char*)p);
pRecipentRows->aEntries[n].rgPropVals[i].Value.lpszA = pNewContact;
hRet = lpExchangeCallback->SetRecipients(pRecipentRows); //is S_OK