1

here is my problem : In my Solution, I have 2 projects, one is a lib in which I created a ressource file (mylib.rc) and a dialog template in it. Then I made a class which inherits CDialog and uses this template. But when I instantiate it and call DoModal(), nothing appends...

here the code of my class, is something wrong with it ?

MyDialog.h

/*MyDialog.h*/
#pragma once
#include "../../../resource.h"

class MyDialog : public CDialog
{
    enum {IDD=IDD_DLGTEMPLATE};
public:
    MyDialog(CWnd* pParent = NULL);  
    virtual ~MyDialog();

protected:
    virtual BOOL OnInitDialog();

    DECLARE_MESSAGE_MAP()
private:
    afx_msg void OnBnClickedOk();
    afx_msg void OnBnClickedCancel();
};

MyDialog.cpp

/*MyDialog.cpp*/
#include "stdafx.h"
#include "MyDialog.h"

MyDialog::MyDialog(CWnd* pParent /*=NULL*/) : CDialog(IDD_DLGTEMPLATE, pParent) {}
MyDialog::~MyDialog() {}

BOOL MyDialog::OnInitDialog() { return TRUE; }

BEGIN_MESSAGE_MAP(MyDialog, CDialog)
    ON_BN_CLICKED(IDOK, &MyDialog::OnBnClickedOk)
    ON_BN_CLICKED(IDCANCEL, &MyDialog::OnBnClickedCancel)
END_MESSAGE_MAP()

void MyDialog::OnBnClickedOk() { OnOK(); }
void MyDialog::OnBnClickedCancel() { OnCancel(); }
Jesus_21
  • 180
  • 1
  • 7

3 Answers3

2

Are you linking with library statically?

If yes one of the reasons could be that you are using rich edit control but you do not initialize RICHED20.DLL ot RICHEDIT.DLL.3You have to call AfxInitRichEdit2 or AfxInitRichEdit. If resource of your dialog is in the DLL, you have to set resource handle to the handlle of the DLL module before invoking dialog.

Call AfxGetResourceHandle to store current handle and call AfxSetResourceHandle to set the handle to a DLL.

After you are dodne with a dialog, use AfxSetResourceHandle to set handle using saved one.

JohnCz
  • 1,613
  • 1
  • 9
  • 9
1

Try placing the following just before the call to DoModal():

AFX_MANAGE_STATE(AfxGetStaticModuleState());
reuben
  • 3,360
  • 23
  • 28
acraig5075
  • 10,588
  • 3
  • 31
  • 50
0

I finally found it, I was using a second ressource file (*.rc), I just had to include the second into the first through the "Set Includes" dialog box in the "Ressource View" as a "Compile-Time Directive"

Thanks anyway guys !

Jesus_21
  • 180
  • 1
  • 7