Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Weird problem with DoModal

Posted on 2005-05-12
10
Medium Priority
?
611 Views
Last Modified: 2013-11-20
I have a simple dialog that I open with DoModal()

      CDlgLabel dlg(this);
      INT_PTR nRet = -1;
      nRet =       dlg.DoModal();

and it runs, but it doesn't become visible until I press the ALT key.  I'm not trapping this key anywhere. Any ideas why this might be the case?

thanks
-Paul
0
Comment
Question by:PMH4514
  • 6
  • 4
10 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13988263
Review your dialog template attributes, also if you have an OnInitDialog() function implemented, you can post here to review.
0
 

Author Comment

by:PMH4514
ID: 13989207
I'll just post all the code.. it's a very simple dialog.. a single text field and ok/cancel.

 I open it after creating an instance of CShapeArrow so the user can supply a text label.  


#if !defined(AFX_DLGARROWLABEL_H__A5A36211_AC99_4007_B2DA_ADCD281D9D0F__INCLUDED_)
#define AFX_DLGARROWLABEL_H__A5A36211_AC99_4007_B2DA_ADCD281D9D0F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DlgArrowLabel.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CDlgArrowLabel dialog

// forward reference
class CShapeArrow;

class CDlgArrowLabel : public CDialog
{
// Construction
public:
  CDlgArrowLabel(CShapeArrow* a_pArrow, CWnd* pParent = NULL);   // standard constructor

// Dialog Data
  //{{AFX_DATA(CDlgArrowLabel)
  enum { IDD = IDD_DLG_ARROW_LABEL };
  CString  m_strLabel;
  // NOTE: the ClassWizard will add data members here
  //}}AFX_DATA


// Overrides
  // ClassWizard generated virtual function overrides
  //{{AFX_VIRTUAL(CDlgArrowLabel)
  protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  //}}AFX_VIRTUAL

// Implementation
protected:

  // Generated message map functions
  //{{AFX_MSG(CDlgArrowLabel)
  afx_msg void OnUpdateLabel();
  virtual BOOL OnInitDialog();
  virtual void OnOK();
  virtual void OnCancel();

//}}AFX_MSG
  DECLARE_MESSAGE_MAP()

private:
      CShapeArrow*      m_pArrow;

};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DLGARROWLABEL_H__A5A36211_AC99_4007_B2DA_ADCD281D9D0F__INCLUDED_)



// DlgArrowLabel.cpp : implementation file
//

#include "stdafx.h"
#include "vs2000ui.h"
#include "ShapeArrow.h"
#include "DlgArrowLabel.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgArrowLabel dialog


CDlgArrowLabel::CDlgArrowLabel(CShapeArrow* a_pArrow, CWnd* pParent /*=NULL*/)
      : CDialog(CDlgArrowLabel::IDD, pParent)
{
  //{{AFX_DATA_INIT(CDlgArrowLabel)
  // NOTE: the ClassWizard will add member initialization here
  //}}AFX_DATA_INIT

  ASSERT(a_pArrow);

  m_strLabel      = _T("");
  m_pArrow      = a_pArrow;

}


void CDlgArrowLabel::DoDataExchange(CDataExchange* pDX)
{
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CDlgArrowLabel)
    DDX_Text(pDX, IDC_ARROW_LABEL, m_strLabel);
    DDV_MaxChars(pDX, m_strLabel, 40);
    // NOTE: the ClassWizard will add DDX and DDV calls here
  //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgArrowLabel, CDialog)
  //{{AFX_MSG_MAP(CDlgArrowLabel)
  ON_EN_UPDATE(IDC_ARROW_LABEL, OnUpdateLabel)
  //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgArrowLabel message handlers

void CDlgArrowLabel::OnOK()
{
  UpdateData(TRUE);
  m_pArrow->SetLabel(m_strLabel);
  CDialog::OnOK();
}

BOOL CDlgArrowLabel::OnInitDialog()
{
  CDialog::OnInitDialog();
      

  ASSERT(m_pArrow);

  CString strText;
  strText.Empty();
  strText = m_pArrow->GetLabel();
  SetDlgItemText(IDC_ARROW_LABEL, strText);

  UpdateData(FALSE);

  return TRUE;  
}

void CDlgArrowLabel::OnCancel()
{
  CDialog::OnCancel();
}

void CDlgArrowLabel::OnUpdateLabel()
{
  m_pArrow->SetLabel(m_strLabel);
  GetDlgItem(IDOK)->EnableWindow(TRUE);
}
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 200 total points
ID: 13989303
Well, appears to be good, maybe your dialog template, but you can try a dirty method:

BOOL CDlgArrowLabel::OnInitDialog()
{
// all your stuff here
   SetWindowPos(NULL,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_SHOWWINDOW);   // <--- This

  return TRUE;  
}

Or, if a window is covering the dialog persistently:

BOOL CDlgArrowLabel::OnInitDialog()
{
// all your stuff here
   SetWindowPos((&CWnd::wndTopMost ,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);   // <--- This

  return TRUE;  
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:PMH4514
ID: 13989361
This worked:
SetWindowPos(NULL,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_SHOWWINDOW);   // <--- This

This did not:
SetWindowPos(&CWnd::wndTopMost ,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);   // <--- This

only problem is that the dialog is at the top-left. I followed it with CenterWindow()  but then I see it appear top-left and quickly move. Is there a one step way to center it or do I have to calculate a desired position? (not a big deal if I do)


0
 

Author Comment

by:PMH4514
ID: 13989372
also - you mentioned "dialog template" - I'm not exactly clear what you're referring to.

Oh, and I bet this has something to do with the fact that the area over which the this dialog is opening, is occupied by a DirectDraw surface ?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13989400
>only problem is that the dialog is at the top-left. I followed it with CenterWindow()  but then I see it appear top-left and quickly
> move. Is there a one step way to center it or do I have to calculate a desired position? (not a big deal if I do)
Calculate proper x and y and do this:
SetWindowPos(NULL,x,y,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_SHOWWINDOW);

> also - you mentioned "dialog template" - I'm not exactly clear what you're referring to
I refer to the dialog design attributes like visible or maybe others.

>Oh, and I bet this has something to do with the fact that the area over which the this dialog is opening, is occupied by a DirectDraw surface ?
Yes, I think this is the problem
0
 

Author Comment

by:PMH4514
ID: 13989428
>>Calculate proper x and y and do this:

gotcha.. actually in this case, as you may visualize, this dialog is a small prompt for a label for an "arrow" which the user places at a click-point, so I'm just popping it right at that location.. "nicer" that way

>>I refer to the dialog design attributes like visible or maybe others.
oh. ok, that's what I thought.

Thanks again Jamie!
0
 

Author Comment

by:PMH4514
ID: 13989585
follow up (sorry)

      GetDlgItem(IDC_ARROW_LABEL)->SetFocus();

following the SetWindowPos - doesn't seem to work..  I just want to give focus automatically to the single text field. any thoughts?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13989722
try these:
1) return FALSE in the OnInitDialog(),  or...
2) Put the SetFocus() in an OnActivate() event.
0
 

Author Comment

by:PMH4514
ID: 13989776
>>return FALSE in the OnInitDialog(),  or...

that did it.. (I even knew that, somehow it slipped me :)

thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question