Solved

Problem Inserting Items on TabCtrl

Posted on 2004-04-30
11
272 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand LInux Boot partition remotly 3 90
iSeries FTP Exit Program 8 135
Named range not carried over 10 63
VBA "SendKeys" Syntax for Multiple Keystrokes 7 108
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

776 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