Solved

Problem Inserting Items on TabCtrl

Posted on 2004-04-30
11
273 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
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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