OnInitDialog - Programmer

This is a discussion on OnInitDialog - Programmer ; Hi NG Sorry to start a new question about a topic discussed in an earlier mail, but I "closed" the earlier one. My question is about OnInitDialog, which I understand initialize controls before other function inclucive OnPaint are called. Scott ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: OnInitDialog

  1. OnInitDialog

    Hi NG

    Sorry to start a new question about a topic discussed in an earlier mail,
    but I "closed" the earlier one.

    My question is about OnInitDialog, which I understand initialize controls
    before other function inclucive OnPaint are called. Scott McPhillips wrote
    to me that I should place my controls in OnInitDialog instead of my
    constructor, but how do I do that? The structure of my code is showed below.
    Can you please show me how to make the code for OnInitDialog?

    If i write "BIOWindow::" I get a list, where I can chose OnInitMenu but not
    OnInitDialog.

    I do not use menus and dialogs, but dont know if that is a problem.

    //**** My code "structure"****

    BEGIN_MESSAGE_MAP(BIOWindow, CFrameWnd)
    ON_WM_PAINT()
    ON_BN_CLICKED(IDC_BTN_INSERT,OnBtnClick)
    ON_BN_CLICKED(IDC_BTN_CLEAR,OnBtnClear)
    ON_LBN_DBLCLK(IDC_LSB_LON, OnDblClickLon)
    ON_WM_LBUTTONDOWN()
    END_MESSAGE_MAP()

    BIOWindow::BIOWindow()
    {
    Create(NULL, "BIO Løn", WS_OVERLAPPEDWINDOW, CRect(20,20,480,345));
    }

    void BIOWindow::OnBtnClick(){ }

    void BIOWindow::OnBtnClear(){}

    void BIOWindow::OnLButtonDown(UINT nFlags, CPoint pt){}

    void BIOWindow::OnDblClickLon(){}

    void BIOWindow::OnPaint(){}

    //**** End code ****

    Thanks
    AHR



  2. Re: OnInitDialog

    "AHR" wrote in message news:<41066cb5$0$264$edfadb0f@dread14.news.tele.dk>...
    > Hi NG
    >
    > Sorry to start a new question about a topic discussed in an earlier mail,
    > but I "closed" the earlier one.
    >
    > My question is about OnInitDialog, which I understand initialize controls
    > before other function inclucive OnPaint are called. Scott McPhillips wrote
    > to me that I should place my controls in OnInitDialog instead of my
    > constructor, but how do I do that? The structure of my code is showed below.
    > Can you please show me how to make the code for OnInitDialog?
    >


    The easiest way is to use ClassWizard. Select your dialog class,
    select the message WM_INITDIALOG, click "Add Function". Then edit the
    code.

    HTH

    Paul.

  3. Re: OnInitDialog

    You generally do not need to add controls in the OnInitialize. It's
    much better to use classwizard for this, as otherwise your code grows
    quite messy. I notice that you appear to have some 'Create' type code
    in your constructor - this will generally not work and cause an
    exception because no window exists on which to place the controls at
    the time that the contructor executes (i.e. m_hWnd == NULL).

    Simon Hayden
    http://www.AutoUpdatePlus.com
    Get software updates to your clients the Quick and Easy way!

  4. Re: OnInitDialog

    "AHR" wrote in message news:<41066cb5$0$264$edfadb0f@dread14.news.tele.dk>...
    > Hi NG
    >
    > Sorry to start a new question about a topic discussed in an earlier mail,
    > but I "closed" the earlier one.
    >
    > My question is about OnInitDialog, which I understand initialize controls
    > before other function inclucive OnPaint are called. Scott McPhillips wrote
    > to me that I should place my controls in OnInitDialog instead of my
    > constructor, but how do I do that? The structure of my code is showed below.
    > Can you please show me how to make the code for OnInitDialog?


    Since MFC encapsulates all the creation and destruction of the
    controls, the only thing you have to worry about is when do you get to
    start using them. OnInitDialog is the first method it is safe to
    access your dialog controls and manipulate them like populate a combo
    box from a file, etc. The class wizard lets you set a bunch of
    defaults on the controls while your still desiging, but you will find
    yourself needing to initialize some things that you can only do at
    runtime. That's were OnInitDialog comes in.

+ Reply to Thread