|
A couple of MFC questions
If Microsoft was a half-decent company you''d think they would organize the VC Help system better, in the CButton Overview they should have put information on how to do simple tasks such as disabling a button, but instead they insist on blabbling about CBitmapButton instead, anyway, a few questions:
Q1) How do you disable a button using code (not using the properties window).
Q2) Ive created a Dialog based project and have inserted a toolbar in the resources window, its come up as IDR_TOOLBAR1 in resources\toolbar, but how do I attach it to the dialog (if possible)? With a menu its easy, insert the menu, and select the menus'' reference in the Main Windows'' properties box.
Q3) I have a CListCtrl on the dialog, ive made it a report-type List Control (with multiple colums, 1 item per line) with 4 colums, the 1st column in fine, but random lines of the other three columns have missing information, im not sure exactly how to set up the control because the help isnt very helpful, here''s the code:
Downloads: ZeroOne Realm
For question number 1:
you can use the CCmdUI member function Enable(bool enable).
what you need to do is modify your dialog class'' message map to ''catch'' the update command ui message for your particular button id.
For example, in your dialog class message map (in the section starting with "BEGIN MESSAGE MAP"), you could insert the following:
where IDC_BUTTON1 is the ID of the button, and OnUpdateButton1() is a member function of the class to be called to Enable/Disable the button. your OnUpdateButton1() function might look like this:
I havent done MFC in a while, but I think you can use class wizzard to do that for you.
MFC isnt very popular on gamedev.net, I would suggest posting MFC related questions on other sites'' forums, such as codeguru.com
you can use the CCmdUI member function Enable(bool enable).
what you need to do is modify your dialog class'' message map to ''catch'' the update command ui message for your particular button id.
For example, in your dialog class message map (in the section starting with "BEGIN MESSAGE MAP"), you could insert the following:
|
where IDC_BUTTON1 is the ID of the button, and OnUpdateButton1() is a member function of the class to be called to Enable/Disable the button. your OnUpdateButton1() function might look like this:
|
I havent done MFC in a while, but I think you can use class wizzard to do that for you.
MFC isnt very popular on gamedev.net, I would suggest posting MFC related questions on other sites'' forums, such as codeguru.com
The update cmd ui thing is the best way to grey things. For buttons you can also just call CWnd::EnableWindow and that works fine.
If you create a new appwizard project (sdi or mdi) then the code to create and dock the toolbar is in the mainframe class. you can just copy that code into your dialog and it *might* work (haven''t tried to use toolbars in dialogs before)
The code for the list ctrl looks fine. The problem most likely is because you aren''t setting the other member of the struct to say how long the string is (cchTextMax i think). If all you are doing is setting the strings, you can just call the SetItemText function it''s alot easier.
For MFC not to be popular there sure seems to be alot of questions about it here. I agree that it isn''t appropriate for all gaming problems but it''s not completely useless either. Frigid, I have worked for game companies for a number of years, and MFC is used in alot of cases - more than you would think. And of course for tools it is the best solution, pretty much. But then again if you enjoy re-inventing the wheel and dealing with massive switch statements for windows message handlers, then that''s up to you.
DSutherland
If you create a new appwizard project (sdi or mdi) then the code to create and dock the toolbar is in the mainframe class. you can just copy that code into your dialog and it *might* work (haven''t tried to use toolbars in dialogs before)
The code for the list ctrl looks fine. The problem most likely is because you aren''t setting the other member of the struct to say how long the string is (cchTextMax i think). If all you are doing is setting the strings, you can just call the SetItemText function it''s alot easier.
For MFC not to be popular there sure seems to be alot of questions about it here. I agree that it isn''t appropriate for all gaming problems but it''s not completely useless either. Frigid, I have worked for game companies for a number of years, and MFC is used in alot of cases - more than you would think. And of course for tools it is the best solution, pretty much. But then again if you enjoy re-inventing the wheel and dealing with massive switch statements for windows message handlers, then that''s up to you.
DSutherland
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement