Instead of adding code and hoping it works, did you debug your code? Did you set a breakpoint in the dialog procedure to see what is happening?
You're supposed to first diagnose the problem, see where it breaks down, read the documentation, and then add code to correct the problem. When it comes to Windows programming, you don't just add code just to see if it fixes something -- you need to know the exact reason why something fails first.
A Win32 program requires all these moving parts to be correct, resource file, window procedure, resource constants, etc. Just showing us the dialog procedure doesn't prove whether you have all the pieces working correctly.
That's why I mentioned to you in another thread that you take a full, working example of a simple Win32 dialog, where you don't need to change any code, compile it, run it. Once you do that, then and only then can you go any further. Did you do that, or are you trying to write the program from scratch? There are thousands of simple, working, full source samples of a Win32 dialog, and that is where you should be starting from.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; February 3rd, 2013 at 09:55 AM.
switch statement is executed and WM_COMMAND is never reached (verified by removing first breakpoint and ">continue")
so i tried that case statement.
I see no problem with windowsproc as except for the dialog box button everything is working fine, include other menu items, There is no problem with displaying dialogue box also,
BEGIN
DEFPUSHBUTTON "That is Good",IDOK,30,35,66,25
END
That was the part of the code associated with the button in resource file, so i showed the complete code generated for dialogue box;
I did run a program from msdn with no problem, i did not face this problem when adding dialogue box to template generated vs, But i am facing this problem when i try to write complete program starting from a empty project, But now if compare with other 2 programs i see no difference, Now i cant even guess were i might be going wrong.
So, trying so many things, now somehow i want to know the problem, so i am looking for help.
I did run a program from msdn with no problem, i did not face this problem when adding dialogue box to template generated vs, But i am facing this problem when i try to write complete program starting from a empty project...
Why did you start from a empty project? Why not from a Win32 one?
Besides, your problem is more related to the C++ and WinAPI Forum (which "Discuss Windows API related issues using C++ (and Visual C++). This is a non-MFC forum") rather than Visual C++ Programming one ("Ask questions about Windows programming with Visual C++ and help others by answering their questions.")
i'm not using mfc, i have not touched mfc yet, i am a beginner, i don't know why, if i do the same things with win32 template everything works smoothly, for now i badly want to know what is really wrong.
Programmers don't guess!! They make insiteful observations based upon the information available. You need to understand and debug your code.
As Paul said
You're supposed to first diagnose the problem, see where it breaks down, read the documentation, and then add code to correct the problem. When it comes to Windows programming, you don't just add code just to see if it fixes something -- you need to know the exact reason why something fails first.
You've only posted a part of the code with which you are having problems. But as all parts of a WIN32 program work together with the OS calling your routines and your routines calling Windows routines, the problem could be anywhere.
You need to start with a known working example of a WIN32 program that uses a dialog box. Compile that and make sure it works as expected. Then add/change as required and after each step make sure the program still works. If it doesn't you then know that the problem lies with the last change.
You must understand how a WIN32 program is expected to work. This has to be learnt - it can't just be found by trying some ad-hoc code and hoping for the best.
When a dialog is created only dialog window is active so only all msgs now received by dialog proc,
1. soon a dialog window is created case "WM_INITDIALOG" is entered.
2. even if i click the only button in the dialog window now, n "WM_COMMAND" is generated but it is expected.
3. I checked the ID associated with the button, it is ok.
4. checking properties in for the button i confirm the button is not disabled.
5. But if i do the same starting from win32 template, everything works fine
6. Comparing code generated with that of working porgram, i see no difference.
I tried to tackle the problem with strategic manner but i failed. after doing everything above i did not know what to do next. So i came here searching for help.
and now i will attach all the files in the project. But i do not really think any code outside what i have posted in the original problem will have much relevance to the problem.
To simplify the question : any guess why a button in dialog box may not create "WM_COMMAND" message upon clicking it?
There is no problem with your dialog template, and your dialog procedure contains one problem that has nothing to do with your current issue. But for sure there is a problem with your message pump. As I can see it, the most probable reason is that your code pumps messages for your frame window only, and other windows' messages remain not dispatched. This never happens when you let wizard generate the message pump (this or that way, specific to the framework in use)
Though i could not solve the problem, i can move on now because that reason is convincing but i am still a little sad that i failed to write such simple application from an empty file.
I hope one day in future i can look back to fix it
For now i am feeling a little comfortable to move on atleast, thank you again
I hope one day in future i can look back to fix it
Why not now? Do you know what the message pump is? What it looks like? And where to look it for? If all the answers are 'yes', why don't you go and slay the dragon right now?
As for the problem in dialog procedure I mentioned. You never destroy dialog with EndDialog() in case the dialog is not modal, i.e. created with CreateDialog(). And you use DestroyWindow() in such case.
Last edited by Igor Vartanov; February 4th, 2013 at 12:07 PM.
Though i could not solve the problem, i can move on now because that reason is convincing but i am still a little sad that i failed to write such simple application from an empty file.
No. You never should be writing Win32 event driven applications from scratch! The reason why is that Win32 programming is not simple. That's why I stated you take a working example and change it until you break something. You never should learn Windows programming by writing a program out of thin air. Even professional programmers don't do this.
In that example, do you see the erroneous message pump that you wrote? No. You see the second parameter being NULL to GetMessage(), just as Igor pointed out. I can show you another thousand examples of dialog box code from different web sites and authors with the same correct message loop. So why is it your code has that bogus message loop? The only reason is that you didn't take the advice of getting working code and learning from it.
I had working code with me, one from msdn and as saidfrom i had no problem when a start from win32 template. I wasn't looking at msg pump as dialogue box was receiving "WM_INITDIALOG". I never really ignored your advice, Thank you for your support.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.