(this is partly a rant, because it seems to be something really easy to do, but the framework makes it really hard to achieve).
I need to be able to change the background color of a CMFCButton when certain conditions happen in our application.
According to the documentation, I could use the method CMFCButton::SetFaceColor (Sets the background color for the button text); but this will get overridden (sp?) by the visual manager drawing method (CMFCBaseVisualManager::DrawPushButton) and will have not effect.
Our application is under control of a CMFCVisualManager theme; so all controls are drawn to respect the current theme ( we want to have themes in our application).
There is a static method in CMFCButton to disable themes for ALL CMFCButtons; so that is a little bit overkill.
I could set the CMFCButton flag m_bDontUseWinXPTheme to TRUE (which will disable the theme for that particular button (I would need to inherit from CMFCButton) But that will change the look of the button (and if I want to keep some of the look, I would have to draw all of it manually).
Any insights, tips or hints on what would be the best way to change the background color of a CMFCButton without having to re-invent the wheel?
Alas, think your only solution is to derive your own button from the MFC one and change the OnDraw() method (think that's what the draw method is called, going off memory). I had to do this for a set of buttons that reflected status on their color. It's not terribly hard to do once you've done it once.
which, as I explained will lead to problems: you will either get strange results, or a program crash. If you are going to store data in the buffer returned from malloc then you must allocate enough space for the data you are going to copy into it. Anything less will cause your program to overwite other variables.
OK, let us say that you have a path ("C:\Users\Noname\Documents\Test") in argv, and you now want to inspect a subdirectory called "images":
int argvSize = strlen(argv); // the number of characters in the base path// calculate the space needed for the subdirectory as follows:// the length of the base path (argv)// plus the length of the new subdirectory// plus one for the backslash separator in front of the new directory// plus 1 for the trailing null character//int mallocSize = argvSize + strlen(subdir) + 1 + 1;
char* newPath = (char*)malloc(mallocSize);
strcpy(newPath, argv); // copy the root path
strcat(newPath, "\\"); // add a single trailing backslash - note two \\ required here,// as the first one is treated as the escape character
strcat(newPath, subdir); // append the new directory name at the end.// The trailing null is appended automatically by strcat// newPath should now contain:// C:\Users\Noname\Documents\Test\images
Yes because you are using the count from location to do the copy, which is the length of the string, and so will not include the null character. Use the code sample I gave you which makes use of standard library functions that will ensure your copied data is correctly structured.
a random user wrote:
is there any way we could communicate like through skype ?
Sorry, I do this in my own time and at my own speed. I will not be available much longer today.
I did what you told me but the results are still the same
That's because you did not do what I told you. You are still copying your path strings based on strlen rather than strlen+1. And you seem to be creating too many variables, most of which are just duplicates of existing items. This may well be what is causing you confusion.
That is because you keep doing the same thing wrong. You need to stop and think, and reread all my posts that explain how to do it properly. Especially look closely at the sample code I posted yesterday
i did do waht you told me i expended the string by 1
but that 1 byte is messing up my code
even trying using strcat just makes it worse I stopped and read all of ur recent psots but i have nothign that comes in mind that could help me
im sorry for giving you a hard time here but it is hard for me as it is
would you please fix the code to show me what you mean?