Solved

Problem Inserting Items on TabCtrl

Posted on 2004-04-30
11
269 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
11 Comments
 
LVL 4

Expert Comment

by:r2far
Comment Utility
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
Comment Utility
Move this code to OnInitDialog function.
0
 
LVL 16

Expert Comment

by:nonubik
Comment Utility
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
 
LVL 10

Author Comment

by:dkloeck
Comment Utility
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
Comment Utility
What error do you get? How is od_TabCtrl defined?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 10

Author Comment

by:dkloeck
Comment Utility
// 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
Comment Utility
on #pragma once begins the header (ObjektDlg.h)
0
 
LVL 10

Author Comment

by:dkloeck
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
well..there were only WM_INITMENU and WM_INITMENUPOPUP
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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: 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…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now