?
Solved

Problem Inserting Items on TabCtrl

Posted on 2004-04-30
11
Medium Priority
?
276 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
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 160 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

765 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