i am working with mfc.
in the onpaint in a cdialog, i need to draw some shapes and for each i need to add a button to it. the user can add more of this shapes and also for each new shape there is a button
i was able to create the button in onpaint but clicking it causes the app to freeze
is there any solution for this, or any other approach for adding the button
Waw, this is... bad ! You know that OnPaint will be called each time the app needs to be refreshed ? So for example, a windows comes before your app and then disapear, then OnPaint will be called again. Thus you will create new buttons over and over again... This is crazy.
You should create the buttons once only, at the creation of the window.
I know that creating controls in wm_paint is bad and crazy and waw.
Each shape on the dialog has a button (drawn inside the shape) to do some action on the shape.
but lets suppose that i have one shape now, and i created its button outside the wm_paint.
now in run_time the user will add new shape,
but how i ll create a new button to associate with the new shape?
I think you need to re-think your design; you simply cannot create controls in the OnPaint.
in your main view, you will draw an OBJECT.
that OBJECT will be a class ( CWnd derived ) that will take care of creating/owning its Button and drawing the shape.
for example, a rough implementation :
/// in that class you will create a button, and use the OnPaint to draw the shape.
class CButtonShape : public CWnd
afx_msg void OnPaint();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
and use the view to create and display that class ( or many as you wish ).
To specify an array with dynamic size, you should allocate it dynamically.
char* buffer1 = new char[nfilelength];
// read the file.
// do other thing that you need.
delete  buffer1;
But I think there is a logical mistake in your code. You read only one char from the file using fread. If you intended to do so then you don't have to give any array.
If not you should specify the size as nfilelenght or sizeof(char)*nfilelength instead of sizeof(char).