I used onctlcolor() method to set the background color for the controls & Dialog.
i run my application, working good but after 15 mins the below error occured,
Application Error:
The Required Resource Was --------> Shown message box
Program Error:
First-chance exception at 0x7c81eb33 in XRay.exe: Microsoft C++ exception: CResourceException @ 0x001274f8.
First-chance exception at 0x7c81eb33 in XRay.exe: Microsoft C++ exception: CResourceException @ 0x001259d0.
First-chance exception at 0x7c81eb33 in XRay.exe: Microsoft C++ exception: CResourceException @ 0x00123ea8.
First-chance exception at 0x7c81eb33 in XRay.exe: Microsoft C++ exception: CResourceException @ 0x00122380.
First-chance exception at 0x7c81eb33 in XRay.exe: Microsoft C++ exception: CResourceException @ 0x00120858.
Warning: Uncaught exception in WindowProc (returning 0).
But i never used any sound files in my project. For your reference code in onctlcolor() method,
What does GDI resources have to do with creating sound files?
Second, where is the call to DeleteObject for those brushes you created? Please read the documentation on CreateSolidBrush. Without the call to DeleteObject, you're creating these brushes and not deleting them:
As to your code, why are you repeatedly calling GetDlgCtrlID()? Just call it once, save the return value into an int variable, and just use that variable to compare.
Also, you could have just placed the ID's you care about in an array, and then search the array to see if any of them match the return value of GetDlgCtrlID(). This will make the code much easier to maintain instead of having so many comparisons.
Code:
//...
const int MyID[] = {IDC_STATIC1, IDC_STATIC2, IDC_STATIC3 /* etc */ };
const int numIDS = sizeof(MyID) / sizeof(MyID[0]);
//...
int idToFind = pWnd->GetDlgCtrlID();
bool bFoundID = false;
int foundID = -1;
for (int i = 0; i < numIDS && !bFoundID; ++i)
{
if ( idToFind == MyID[i] )
{
bFoundID = true;
foundID = MyID[i];
}
}
if ( bFoundID )
{
// do something with the found ID
}
With the code above, all you need to do is to add the new ID to the array at the top. There is no need for more and more comparisons.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; January 7th, 2013 at 02:03 AM.
2. This is my first project in MFC, I'm learning from google, codegure, msdn & code project web site only.
Just i search my project requirement from net & i used the code to my project. so i never known about DeleteObject? Sure I will read the
MSDN page & will use the DeleteObject method in my project. here after I will use code tags when posting code.
3. I taken the code from google how to set background color for dialog, so i used that code for all my dialog controls(GetDlgCtrlID()).
I don't know this array method.I will use the control ID array method in my onctlcolor method.
4. For using Control ID Array & DeleteObject method, shall i recover my project from resource Exception problem sir?
I will try the above 2 methods and come back with you sir.
Just an aside remark and advice.
No offense, your CXRayFIDlg::OnCtlColor looks like a mess, then it's no wonder that you can easily make mistakes in it. Too much code, too many conditions, too many hardcoded color values. What about if you have tens of dialogs with tens of colored controls? And what about if in other places you need different colors and/or you have to change colors at run-time? Normally, will result a triple mess...
First to note: MFC "reflects" WM_CTLCOLOR notification messages to the child controls. That allows handling them in a more object-oriented manner.
So, much more reliable, flexible and easy to maintain is to derive your own control class (ex. CColoredStatic derived from CStatic) an handle reflected WM_CTLCOLOR messages.
Here is an example of "colored" static control class:
All you have now to do in the parent dialog class is to include "ColoredStatic.h" and replace CStatic with CColoredStatic then call the methods for setting the color atributes whenever is necessary.
Example:
In the same way you can proceed for other control types (edit and so on).
It takes no much time to implement and test such class, once and forever, then easily use it anywhere is needed.
Last edited by ovidiucucu; January 10th, 2013 at 04:39 AM.
Bookmarks