|
If you are using Visual Studio, you can use its integrated debugger. Here is a guide to get started with it - it's really easy: Get started with Visual Studio 2017 - Debugging[^]
If you are not using Visual Studio, you should tell us what you use, so someone can suggest a suitable debugger to use for that, and/or a quick guide to learn how to use it.
The important things to know about debugging:
1. if you don't want to, you do not need to add any specialized code to your program to enable debugging.
2. You can tell your debugger that you want your program to stop if something specific happens. What you told us is quite easy to specify with Visual Studio: you can make the program run up to exactly the point where your iVal changes (see Data Breakpoints – Visual Studio 2017 15.8 Update | Visual C++ Team Blog[^] )
3. When using a debugger, you can not only make your program run up to a point, you can also inspect all variables, the call stack, and other aspects of the current state of your program.
There are many more things that a debugger can help you with, e. g. change a variable at runtime, make the computer skip or repeat some code, etc.. All without changing the program code. But you have to learn the basics.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
How to change the background color of checkbox in CListCtrl?
The checkbox appears before the 1st column. if I change the background using m_cLstCtrl.SetBkColor(RGB(0,0,0)); the background of the entire control is changed.
If I change it inside OnCustomDraw as below:
void CSysWindow::OnCustomDrawAlarmLine ( NMHDR* pNMHDR, LRESULT* pResult )
{
NMLVCUSTOMDRAW *pCD = (NMLVCUSTOMDRAW*)pNMHDR;
// By default set the return value to do the default behavior.
*pResult = CDRF_DODEFAULT ;
//obtain row and column of item
int iRow = pCD->nmcd.dwItemSpec;
int iCol = pCD->iSubItem;
//Remove standard highlighting of selected (sub)item.
pCD->nmcd.uItemState = CDIS_DEFAULT;
switch( pCD->nmcd.dwDrawStage )
{
case CDDS_PREPAINT: // First stage (for the whole control)
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
break;
case CDDS_ITEMPREPAINT:
{
*pResult = CDRF_NOTIFYSUBITEMDRAW;
}
break;
case CDDS_ITEMPREPAINT | CDDS_SUBITEM : // Stage three
{
if ((iCol != 0) || (iCol != 1))
{
pCD->clrText = RGB(255,0,0);
pCD->clrTextBk = RGB(0,0,0);
}
if ((iCol == 0) || (iCol == 1))
{
pCD->clrText = RGB(255,0,0);
pCD->clrTextBk = RGB(0,255,0);
}
//if (sub)item is of interest, set custom text/background color
//if( 1 == iRow && 3 == iCol )
//{
// pCD->clrText = RGB(255,0,0);
// pCD->clrTextBk = RGB(210,245,245);
//}
//else
//{
// pCD->clrText = RGB(0,0,0);
// pCD->clrTextBk = RGB(255,255,255);
//}
*pResult = CDRF_NOTIFYPOSTPAINT;
}
break;
case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM: // Stage four (called for each subitem of the focused item)
{
}
break;
default:// it wasn't a notification that was interesting to us.
{
*pResult = CDRF_DODEFAULT;
}
break;
}
}
The background of the other column gets changed. but not the Checkbox.
So...How to change the background of the checkbox column alone?
|
|
|
|
|
Your code seems to be changing different columns. Try modifying the code so it only affects column 0 (where the checkbox is) and see what happens.
|
|
|
|
|
The complete background is not changing
|
|
|
|
|
Hi
1) I have huge C++ code, that I need to refactor. I am using RAD Studio- code gear
Please advise free Tool to refactor C++ code. Thanks you
2)The code is very bad. it has around 3000 compiler warning. I know it is bad to automate fixing the warnings but Is there any tool, or automated process to fix the warnings
Thanks you!!
|
|
|
|
|
It is most unlikely that any tool could do this. You will need to get your "code analysis head" on and knuckle down to a few days (or weeks) of hard work.
|
|
|
|
|
The best tool is Elbow Grease and Visual Studio Level 4 warning level and "Stop on Warning" .
I'd rather be phishing!
|
|
|
|
|
A warning typically means that while the code is legitmate with respect to the C++ syntax, the compiler suspects that it might be doing something else than what the programmer intended. Since the computer can't guess what's in the head of the programmer, there's no safe way for it to automatically fix it.
If you have so many warnings, it's probably best to watch out for very common types of warnings, pick one of these, and focus on fixing that warning everywhere in the code, ignoring other warnings. Most of the time you'll quickly be able to spot certain patterns, and fixing these errors should therefore be possible almost without thinking after a while. It will still take time, but that way it's probably a lot faster than working on all warnings by order of occurrence.
P.S.: if your goal is refactoring the entire code, then eliminating warnings is the last of your concerns! First you need tests, to ensure that the refactored code really produces the same results. Then you need to start with the lowest level functions, and then work your way up. Chances are, that changes in your low level functions require adjustments higher up, and that could very well affect code that currently issues warnings. It would be pointless to fix warnings first and then change that same code again due to low-level refactoring, so you better don't do that so early!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
modified 25-Jan-19 10:04am.
|
|
|
|
|
I'm going to embedd the Python in my MFC/C++ application(interactive Python console) and extend the Python with the application's API.
Since any script can be malformed, what are the risks in this particular case?
Is there any technics to protect the main C++ application?
Would appreciate the feedback from programmers who was experienced this kind of scenario, and also the security experts.
Thanks.
|
|
|
|
|
Immense, but not because of Python, but that you are adding scripting to your app, opening up a lot of vectors for software with bad intent and plain bad software.
|
|
|
|
|
Hello! What extensions, plug-ins, additional programs for working with Visual Studio do you use? I'm interested in memory usage reports, code optimization. What can you to advise. What can be useful for beginner? For Windows
|
|
|
|
|
|
Thank you, I think I watched that post. I also watched many articles such as "5, 10, 20... best extensions" for Visual Studio. It seemed to me most of the items from the list are rarely used.
modified 23-Jan-19 10:21am.
|
|
|
|
|
Somewhat helpful:
Hide Suggestions And Outlining Margins: removes whitespace at the beginning of lines, near the line numbers.
Editor Guidelines: adds a vertical line at a given column, I have it at 80. This allows me to comfortably have the project explorer on the left, two editor panes and the test explorer on the right.
Also, Macros for Visual Studio (it lets you to record and replay keyboard macros). Really handy tool for me
|
|
|
|
|
Be sure I'll try this plugins. Macro seems to be very useful.
|
|
|
|
|
You can use IntelliCode, it's good plugin for novice programmers. Also, I use VLD, Deleaker or standard debugger.
|
|
|
|
|
Thanks for participating. I researched your recommendations. I will use not all the plugins, but some of them I added in VS
|
|
|
|
|
Im using MFC GridControl 2.7 taken from code proejct in my application.In my grid control, im making second column as check box column. The default state of check box should be true. Later, user can uncheck the checkbox and depends on the state, furthur functinoality wil go. Here i dont know how to set checkbox as checked in default.
m_ctLstCtrl.Create(listRect, this, IDC_TRENDLISTCTRL);
m_ctLstCtrl.SetEditable(TRUE);
try {
m_ctLstCtrl.SetRowCount(9);
m_ctLstCtrl.SetColumnCount(15);
m_ctLstCtrl.SetFixedRowCount(1);
m_ctLstCtrl.SetFixedColumnCount(1);
}
catch (CMemoryException* e)
{
e->ReportError();
e->Delete();
return -1;
}
for (int row = 0; row < m_ctLstCtrl.GetRowCount()-1; row++)
{
m_ctLstCtrl.SetCellType(row+1,1,RUNTIME_CLASS(CGridCellCheck));
}
Anu
|
|
|
|
|
You should post your question in the forum at the end of the article. I know for a fact that the author spends much of his time on CodeProject.
|
|
|
|
|
|
Okay.
Thank you.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
Amazing implementation; so much functionality in so little code.
|
|
|
|
|
This forum is for asking questions about problems with code you wrote, not asking for code.
Hint: if the problem you have is a very common one, a simple search in your favorite search engine is much more likely to turn up results.
But if this is homework, you really should at least try to solve it. Homework is rarely about finding the solution, it is about trying to find the right way towards the solution. Asking for code is the opposite direction - sorry, no points.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
I started programming in high school in C about 15 years ago as a hobby and did not follow programming as my career path but it has served as a useful tool periodically since then.
I was more or less told that C would be a good entry language, that it would be a good foundation if I decided to learn others. That Java is bloated and grossly resource inefficient, as well as sacrificing quite a lot to be fully cross platform. That C++'s OOP leads to less resource efficient programming and that classes were a crutch to help structure code in lieu of skillfully choosing one's own good designs. But that they would make it easier to work with others by giving greater standardization to interfaces.
Today I observe as follows:
C was designed for specific purposes and to specific ideals, and I mostly align with them. It's small, clean, and efficient. You're free to shoot yourself in the foot, all 12 toes. Proper design practices are your responsibility (or willful irresponsibility). If you want something you can build it or borrow/get it from someone else. It's not large.
On the other hand, pure speed and efficiency is not critical in all applications. If you are doing desktop development with a moderate amount of data, and let's say not computationally intensive graphics, the efficiency may be unnecessary. Rapid development is more critical to me now.
The very minimal provisioning of the standard library slows development time, like a mostly empty toolbox. Not only mostly empty, but the tools of the standard library are very traditional and sometimes crude for what you might need. Other languages provide a much greater toolset of readily usable and easily importable features.
C is not entirely outmoded but its popularity is marginal, and with that marginalization a lot of the contributions made to programming as a whole are largely unavailable. Its use is declining further with the rise of C#.
Projects | The State of the Octoverse[^]
I think the logical choice would be to learn C++ next.
|
|
|
|
|