Weird problem with DoModal

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
PMH4514Asked:
Who is Participating?
 
Jaime OlivaresSoftware ArchitectCommented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
Review your dialog template attributes, also if you have an OnInitDialog() function implemented, you can post here to review.
0
 
PMH4514Author Commented:
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
PMH4514Author Commented:
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
 
PMH4514Author Commented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
>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
 
PMH4514Author Commented:
>>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
 
PMH4514Author Commented:
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
 
Jaime OlivaresSoftware ArchitectCommented:
try these:
1) return FALSE in the OnInitDialog(),  or...
2) Put the SetFocus() in an OnActivate() event.
0
 
PMH4514Author Commented:
>>return FALSE in the OnInitDialog(),  or...

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

thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.