Solved

Problem Inserting Items on TabCtrl

Posted on 2004-04-30
11
275 Views
Last Modified: 2013-11-20

IMPLEMENT_DYNAMIC(CObjektDlg, CDialog)
CObjektDlg::CObjektDlg(CWnd* pParent /*=NULL*/)
      : CDialog(CObjektDlg::IDD, pParent)
{
      od_TabCtrl.InsertItem(0,"test");
}

It gives me a runtime error... why?
0
Comment
Question by:dkloeck
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 4

Expert Comment

by:r2far
ID: 10959454
Never used a tab control so if the problem lies with the control i can't help.

However, with many controls, calls to member functions cause runtime errors if the control has not yet been created.

The control should not be touched until OnInitialUpdate() function, and not till after, in that function, the contrtol is created.  This is of course unless the dialog creates the control, but even then, handle the control method calls in InitialUpdate() at the earliest.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 10959480
Move this code to OnInitDialog function.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 10959530
dkloeck, at the time the CObjektDlg contructs, its member od_TabCtrl (I presume it's a member) does not have a hWnd. This happens only after dialog creation. So try overriding OnInitDialog for your CObjektDlg and insert the item in tabctrl there.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:dkloeck
ID: 10959648
I wrote:

BOOL CObjektDlg::OnInitDialog()
{
      od_TabCtrl.InsertItem(0,"test");
      return TRUE;
}

but it still gives the same error
0
 
LVL 16

Expert Comment

by:nonubik
ID: 10959696
What error do you get? How is od_TabCtrl defined?
0
 
LVL 10

Author Comment

by:dkloeck
ID: 10959730
// ObjektDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Winlinx2.h"
#include "ObjektDlg.h"


// CObjektDlg dialog

IMPLEMENT_DYNAMIC(CObjektDlg, CDialog)
CObjektDlg::CObjektDlg(CWnd* pParent /*=NULL*/)
      : CDialog(CObjektDlg::IDD, pParent)
{
}

BOOL CObjektDlg::OnInitDialog()
{
      od_TabCtrl.InsertItem(0,"test");
      return TRUE;
}

CObjektDlg::~CObjektDlg()
{
}

void CObjektDlg::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      DDX_Control(pDX, IDC_TAB1, od_TabCtrl);
}


BEGIN_MESSAGE_MAP(CObjektDlg, CDialog)
      ON_WM_CREATE()
END_MESSAGE_MAP()


// CObjektDlg message handlers

int CObjektDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      if (CDialog::OnCreate(lpCreateStruct) == -1)
            return -1;

      // TODO:  Add your specialized creation code here


      return 0;
}

#pragma once
#include "afxcmn.h"


// CObjektDlg dialog

class CObjektDlg : public CDialog
{
      DECLARE_DYNAMIC(CObjektDlg)

public:
      CObjektDlg(CWnd* pParent = NULL);   // standard constructor
      virtual ~CObjektDlg();
      BOOL OnInitDialog();

// Dialog Data
      enum { IDD = IDD_ObjektDlg };

protected:
      virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
      
      DECLARE_MESSAGE_MAP()
public:
      CTabCtrl od_TabCtrl;
      afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
};


Objekt dialog is called with a DoModal() funktion.
0
 
LVL 10

Author Comment

by:dkloeck
ID: 10959750
on #pragma once begins the header (ObjektDlg.h)
0
 
LVL 10

Author Comment

by:dkloeck
ID: 10959778
btw..
i couldnt find InitDlg in the dlg messages, so i made it by myself..maybe i must put something in messagemap?
0
 
LVL 16

Accepted Solution

by:
nonubik earned 40 total points
ID: 10959803
you must call CDialog::OnInitDialog() before inserting item in tabctrl

BOOL CObjektDlg::OnInitDialog()
{
     CDialog::OnInitDialog();
     od_TabCtrl.InsertItem(0,"test");
     return TRUE;
}
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 10960359
couldnt find InitDlg in the dlg messages, so i made it by myself..maybe i must put something in messagemap?

in class wizard filter on messages for a dialog , it is the WM_INITDIALOG you want.
0
 
LVL 10

Author Comment

by:dkloeck
ID: 10960822
well..there were only WM_INITMENU and WM_INITMENUPOPUP
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

707 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