problem with trivial MFC app
-
As testing for a real MFC application I made a trivial one, but ran in to problems. To my mind this exemplifies the difficulties faced by the newbie to MFC and doc/view. I wanted a single-window MFC doc/view app with a static control on the window. I used AppWizard to make an MFC EXE. It ran and showed an empty window. I put my static control in the view .h file private: CStatic Statcontrol; Now I made my ..Create() in the view .cpp file RECT rect = {100,100,200,200}; Statcontrol.Create("hello",WS_CHILD | WS_VISIBLE | SS_CENTER,rect,this,ID_STAT); But where do I put this code? In the view constructor it fails. In PreCreateWindow() it fails. All I get is a FALSE return - not much diagnostics. (But I guess 'this' is wrong). In the OnDraw() handler it works! But then it's called multiple times. Help! Why is something so simple so difficult? MFC books never help with things like this. Andrew MisterTransistor - germanium is King
-
As testing for a real MFC application I made a trivial one, but ran in to problems. To my mind this exemplifies the difficulties faced by the newbie to MFC and doc/view. I wanted a single-window MFC doc/view app with a static control on the window. I used AppWizard to make an MFC EXE. It ran and showed an empty window. I put my static control in the view .h file private: CStatic Statcontrol; Now I made my ..Create() in the view .cpp file RECT rect = {100,100,200,200}; Statcontrol.Create("hello",WS_CHILD | WS_VISIBLE | SS_CENTER,rect,this,ID_STAT); But where do I put this code? In the view constructor it fails. In PreCreateWindow() it fails. All I get is a FALSE return - not much diagnostics. (But I guess 'this' is wrong). In the OnDraw() handler it works! But then it's called multiple times. Help! Why is something so simple so difficult? MFC books never help with things like this. Andrew MisterTransistor - germanium is King
Try putting it in your view class OnInitialUpdate function leave CStatic Statcontrol in the header...should work Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks
-
As testing for a real MFC application I made a trivial one, but ran in to problems. To my mind this exemplifies the difficulties faced by the newbie to MFC and doc/view. I wanted a single-window MFC doc/view app with a static control on the window. I used AppWizard to make an MFC EXE. It ran and showed an empty window. I put my static control in the view .h file private: CStatic Statcontrol; Now I made my ..Create() in the view .cpp file RECT rect = {100,100,200,200}; Statcontrol.Create("hello",WS_CHILD | WS_VISIBLE | SS_CENTER,rect,this,ID_STAT); But where do I put this code? In the view constructor it fails. In PreCreateWindow() it fails. All I get is a FALSE return - not much diagnostics. (But I guess 'this' is wrong). In the OnDraw() handler it works! But then it's called multiple times. Help! Why is something so simple so difficult? MFC books never help with things like this. Andrew MisterTransistor - germanium is King
-
Try putting it in your view class OnInitialUpdate function leave CStatic Statcontrol in the header...should work Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks
Gary, thanks - that has indeed fixed it. You don't by chance know a good book/article that explains the principles of MFC programming rather than just showing which menus to click? cheers Andrew
-
Gary, thanks - that has indeed fixed it. You don't by chance know a good book/article that explains the principles of MFC programming rather than just showing which menus to click? cheers Andrew
I am kind of partial to "Inside Visual C++" by Kruglinski. I have found that the best way to learn MFC is by doing. I have never learned much from reproducing book examples. I came from a C, Basic, FORTRAN, assembly language background. I learned the most by taking one of my old programs and making a MFC application out of it. I already knew how the meat of the program worked, so I could just concentrate on the GUI interface. I would use the programming books I bought (I own quite a few) and use the coding examples that applied to the program I was writting. It may not be the best way to learn MFC, but it worked for me. Gary Kirkham A working Program is one that has only unobserved bugs I thought I wanted a career, turns out I just wanted paychecks