| NeckDeepInSyntaxErrors (49) | |||
|
I've written a sort of initialization program for another program. This "initialization" program becomes unresponsive immediately after being run. I've looked through many times, but can't quite seem to figure it out. I'll start off with WinMain and the WM_CREATE sections (though I don't think there are any problems there), and if you need to see more, let me know.
The call to ShowWindow in WM_CREATE was added after the program was initially created, because without it the window wouldn't show at all (I believe this may have something to do with the problem). The commented out call to the CreateWindowEx function within WM_CREATE was added afterwards, thinking that maybe SendMessage would cause the the program to hang if the handle in the lParam was not yet a valid handle. However, that did not fix the "unresponsive" problem. | |||
|
|
|||
| modoran (1245) | |
|
Your WinMain seems weird to me, why don't you use a default generated one ? Most IDE have WinMain templates, like Code::Blocks, which is guaranteed to work. Then start adding your code and see what happens. | |
|
|
|
| NeckDeepInSyntaxErrors (49) | |
|
Actually, I am using Code::Blocks. The WinMain in the post above is (for the most part) the one from the "Frame Based" option in the "Win 32 GUI" option from File -> New -> Project... I changed the variable names, removed all of the comments/blank lines/unnecessary white spaces, and added in a little bit, but then saved as a custom template. This is the (for the most part) the WinMain used in all of my programs, and I have another working program using the exact same WinMain (only difference between them: using hMain instead of hOpen). Though, to be fair, you have said that it seems weird to you. I guess it's generally user dependent (different people use different things, and since it's the one I'm used to using, it doesn't seem weird to me). My point though, I have this same WinMain function in another program that does run, and does not automatically become unresponsive. Therefore, I assume the problem is not there. EDIT: I have used Search -> Replace from the Code::Block's menu to rename all instances of hOpen with hMain. The WinMain function is now exactly the same as my working program's however this particular one still becomes unresponsive when run. | |
|
Last edited on
|
|
| NeckDeepInSyntaxErrors (49) | |||||
Okay, using multiple calls to MessageBox() I think I found the part that freezes it. I'll start off by posting a little more code (revised edition, with message boxes):
The program displayed the "Starting Loop Now" message box, then became unresponsive. This loop is meant to initialize the HWND elements of the vhWin array to NULL. The separate HWND elements that have been commented out were the original ones used while originally writing the program. I decided to switch to the array for:
Which is used at several points throughout the program to (theoretically) destroy all controls that are currently displayed, without knowing at every point which ones are displayed. Note: I don't know if this is wrong/bad. If the program is becoming unresponsive due to problems with the array, would there be another way to do this? The only other ones I can think of would be to use an external function with a very long if...else if... statement, or a lot of IsWindow() calls. :\ | |||||
|
Last edited on
|
|||||
| modoran (1245) | |
On my system, sizeof (vhWin) return 76, so you know what that means, don't you ?Your program attempts to write outside of bounds of vxWin array and crashes. Use something like sizeof (vhWin ) / sizeof (vhWin[0]) or _countof() macro if it is available instead.
| |
|
|
|
| NeckDeepInSyntaxErrors (49) | ||||||
|
Thank you very much modoran, I hadn't realized that was happening. (It honestly never occurred to me to check that, and I didn't realize it was using the array's size rather than the number of units...oddly enough considering it says sizeof) XD I changed sizeof(vhWin) to sizeof(vhWin)/sizeof(vhWin[0]) as you suggested, because I added <stdlib.h> (as suggested on the msdn page for the _countof() macro. However, when compiling it gave me this error:
It passed through the WM_CREATE section of the code now, but it got stuck and became unresponsive on the first call to the theoretical window destroying loop from my previous post. Though I changed those as well, so it now looks like this:
I also tried changing that to:
However both cause the same unresponsive problem. | ||||||
|
|
||||||
| TTT (52) | |
| Can you post your whole code? I'll try to help | |
|
|
|
| NeckDeepInSyntaxErrors (49) | ||||
TTT wrote:
Oh boy...I have a feeling that this is going to be a bit embarrassing...but, here goes...
| ||||
|
|
||||
| NeckDeepInSyntaxErrors (49) | |||
| |||
|
|
|||
| NeckDeepInSyntaxErrors (49) | |||
| |||
|
Last edited on
|
|||
| NeckDeepInSyntaxErrors (49) | |
|
In the actual code written into the editor in the IDE, the GetWhateverText() functions at the bottom are all single quoted strings. I split them into separate lines because it ran very far off the side of the screen in the forum's code tags. There may be (most likely is) many more bugs/problems within the program. However, it compiles without errors, so right now I'm trying to debug through running it, but it keeps getting stuck (now that modoran helped me fix the original array problem) in the IDB_NEXT case of WM_COMMAND when it gets to the theoretical window destroying loop. And, whether you (can) help or not, thank you modoran and TTT for your time. It's greatly appreciated. | |
|
|
|
| TTT (52) | |||||
I think there is infinite loop in your program )))
your iCount remains 0 so statmenet in while is always right. So rewrite it like this then try again
This was in case IDB_NEXT | |||||
|
Last edited on
|
|||||
| modoran (1245) | |||
Please make your variables inside your window procedure either static or use global variables (not recommended) as will go out of scope each time the window procedure is called.
| |||
|
|
|||
| NeckDeepInSyntaxErrors (49) | |
|
Thank you again TTT. I didn't realize I had put the increment inside of the if statement... Note on why I may be missing obvious errors: This whole thing consists of three separate programs, which altogether was supposed to be a Christmas present for someone...obviously, I've missed that deadline. So, I've been driving myself crazy trying to finish it as soon as possible...maybe I just need to take a break XD Also, because this was created for one person in particular, the terms of service part is kind of an inside joke between us (^_^) And...it now passes through there, and creates the controls. The static control is displayed as an empty frame with no text, but I can most likely fix that. I'm going to take a short break, and look back through. Note: the size of the "Okay" button was not at all how I seen it in my head, so some of the dimensions on the windows will be changed. @modoran: Will do, thank you. It was my (obviously wrong) assumption that in win32 programming that once the message loop started the window procedure remained active until it returned 0 to end the loop. I didn't think they would go out of scope like that. | |
|
Last edited on
|
|
| NeckDeepInSyntaxErrors (49) | |
|
Okay, I'm back now, and after changing the sizes of the controls to look a little better (I haven't finished the missing text problem yet), I clicked through and found a few other small problems. I'll go through and fix everything I can, and re-post the new code when I'm done. Thank you both very very much. | |
|
|
|
| NeckDeepInSyntaxErrors (49) | |||
| |||
|
|
|||
| NeckDeepInSyntaxErrors (49) | |||
| |||
|
|
|||
| NeckDeepInSyntaxErrors (49) | |||
| |||
|
|
|||
| NeckDeepInSyntaxErrors (49) | |||
Right now, this is the unedited code I have. I've tried using WM_SETTEXT and SetWindowText as opposed to using c_str() in the CreateWindowEx() calls. However, nothing has worked and the static controls remain textless. I have used std::fstream to open a file and write the string to it just before calling CreateWindowEx(). The string contains the text from the function, however it won't display. Edit: I figured out the missing text problem. The text doesn't display when the SS_BLACKFRAME style is defined. I've updated the sizes of the static controls, and the buttons. I've added in actual "Back" buttons, rather than simulating the "Next" button from 2 sections back like before. It was easier to do it this way to keep track of clearing specific variables, etc when going backwards rather than forwards. | |||
|
Last edited on
|
|||
| NeckDeepInSyntaxErrors (49) | |
| I've got everything done now, thank you, thank you, thank you (^_^) | |
|
|
|