|
Typical sources for stack overflows are declaring large objects on the stack and recursive function calls:
void some_func()
{
int large_array[500000];
CSomeLargeObject Obj;
some_func();
some_other_func();
}
Large objects on the stack should be avoided. Use dynamic memory allocation instead (new or malloc() ).
So check your code for the above conditions. To detect recursive calls, use the debugger and check the functions that are called for recursions.
|
|
|
|
|
So stop using so much stack.
Functions calling themselves endlessly is the usual cause. Dont do it.
|
|
|
|
|
Hi,I recently completed the book Sams Teach yourself C++ and this website was mentioned there for help in further programming process I want some suggestions about getting started with programming in GUI,i am fed up of using console for 3 years learning c and c++
|
|
|
|
|
|
Ok,Thanks
|
|
|
|
|
Farhan_Karim wrote: i am fed up of using console for 3 years learning c and c++
Depending on what "using" means in the context of "3 years" you might want to start learning a different language. Certainly if you have been doing it professionally for 3 years then it is worth consideration. Even an enthusiastic amateur might undertake it.
|
|
|
|
|
The Qt Project[^] offers a great IDE and GUI framework for C++, including examples for the usage of most of the classes.
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
Alright, I've been bugging with this one for quite a while now.
I have a struct which is const and part of a class and therefore I need to initialize it.
What I have done so far:
#ifndef BOUNDARIES_H
#define BOUNDARIES_H
typedef struct{
char upper;
char lower;
} charBoundary;
#endif //BOUNDARIES_H
#ifndef FOO
#define FOO
using namespace std;
#include <iostream> //!< Used for console output
class foo{
private:
const charBoundary versionBoundary = {
1,
-5
};
public:
};
Now I recognized that the initialization
const charBoundary versionBoundary = {
1,
-5
};
is only valid in C++11 - All compilers not supporting C++11 will choke on these lines.
Now I come to the question I want to ask:
Is there any other way to get it compilable to older compilers than making versionBoundary static or non-const or adding a constructor to the charBoundary struct?
I do not like neither of the above mentioned possibilities but if there is no other solution - What would you recommend?
Thanks in Advance
PP
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
Does it have to be const ?
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Yep, thats why I ask - Without the const it would be easy, also if I'd make it static const.
But for the purpose I need it const only would be the best solution.
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
OK, this is not the most elegant solution, but here we go:
charBoundary getInitialBoundary()
{
charBoundary c ={2,-5};
return c;
}
class foo{
public:
foo() : versionBoundary(getInitialBoundary()) {}
private:
const charBoundary versionBoundary;
};
|
|
|
|
|
Dont you have to do the initialisation in the class constructor?
I am not a C++ expert, I have used it enough, but it seems as if it should go there. If not and you only need one instance of the struct shared among all instances of the clas you can make it static. (Again, not an expert here, but I seem to recall from the dregs f my memoery that this is the case, please correct me anyone if it is not so).
|
|
|
|
|
This is actually a bit of research for an article of mine (If you want to peek into it, have a glance here: Don't mess up your #defines[^]).
Erudite_Eric wrote: Dont you have to do the initialisation in the class constructor?
I initially did this, but as stated in the article the problem is that you'd be able to change the struct's value after the object initialization which could lead to an unexpected behavior of your program. On the other side, making it static const leads to the fact that every instance shares the same instance of the struct, which is possible and would not lead to any unexpected behavior.
I am still searching for a solution which would make it only const , just for design reasons.
Thanks for your post anyways, ŷou brought me onto the track of a false thinking of mine - I refused the static const because I thought I'd have to address the struct as foo::struct which is not the case. Gotta update that article...
You know the world is going crazy when the best rapper is a white guy, the best golfer is a black guy, the tallest guy in the NBA is Chinese, the Swiss hold the America's Cup, France is accusing the U.S. of arrogance, Germany doesn't want to go to war, and the three most powerful men in America are named "Bush", "Dick", and "Colon."
|
|
|
|
|
There are many solutions for your problem if you don't insist on trying to initialize a struct.
1. Write a function. Apparently your purpose is to check a value range, so all you really need is a function:
int inVersionRange(char value);
That's all you need in a header. The implementation file then can contain the actual constants:
const char Min_Version = -5;
const char max_version = 1;
int inVersionRange(char value) {
int result = 0;
if (value < Min_Version)
result = -1;
if (value > Max_Version)
result = 1;
return result;
}
If you need more functions that access these boundaries, put the implementation into the same file.
2. static const
struct VersionRange {
static const char VMIN;
static const char VMAX;
};
const char VersionRange::VMIN = -5;
const char VersionRange::VMAX = 1;
3. define the values within a namespace instead of a struct
(same as above, but you don't need the static keyword)
4. create a singleton class to hold the constants and make them write-only
Similar to 2, but you create an instance of your class (or struct) which is made 'static constant' through programming concepts rather than language keywords.
5. use const references and an array intializer
This comes back to your original idea of using an initializer:
class VersionBoundary {
static const char* const boundaries;
public:
static const char& VMIN;
static const char& VMAX;
}
const char* const VersionBoundary::boundaries = { -5, 1 };
const char& VersionBoundary::VMIN = *(boundaries+0); const char& VersionBoundary::VMAX = *(boundaries+1);
|
|
|
|
|
hello, I found out that listview has tooltip (duaaaaaa)
http://blogs.msdn.com/b/alexdan/archive/2006/05/16/adding-tooltips-to-a-list-view-control.aspx[^]
but how in the world it works? my listview is ONWERDRAW and extended styles lVS_EX_INFOTIP | LVS_EX_LABLETIP, I have been told that I will get an LVN_GETINFOTIP notification, which i do not get it at all, my questions are (Did i miss something?) and (How that tooltip works? I mean does it work when i leave the arrow of item or what?) there are some articles but they did not explain that
working with API and C++ nothing else
thank
|
|
|
|
|
A quick look at the documentation shows where the author got this wrong. When you receive the notification you need to set the tooltip text into the buffer as follows:
sprintf_s(pGetInfoTip->pszText, pGetInfoTip->cchTextMax, "Some helpful tooltip");
Note, this is an over-simplification, and you should check the documentation to ensure you are following the rules.
Veni, vidi, abiit domum
|
|
|
|
|
I am trying to get a pointer to my CDocument derived class associated with a particular tab index (provided by the MDI tab control). The MFC framework calls my OnGetTabToolTip function and provides a CMFCTabToolTipInfo pointer which contains in index of the tab requiring the tooltip text... but it seems there is no way to retrieve the doc/view associated with the tab! Must I keep track of the tab index-doc association, keeping in mind users can move tabs around willy nilly, or is there a better way?
I would have thought this had been discussed countless times, but I cannot find helpful advice.
Many thanks.
|
|
|
|
|
See here.
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Thank you for the reply. Unfortunately, your link does not help solve the problem I described. Perhaps some code will clarify the issue. My ToolTip handler looks like this:
LRESULT CMainFrame::OnGetTabToolTip(WPARAM wp, LPARAM lp)
{
CMFCTabToolTipInfo* pInfo = (CMFCTabToolTipInfo*) lp;
ASSERT (pInfo != NULL);
if (pInfo)
{
ASSERT_VALID (pInfo->m_pTabWnd);
if (!pInfo->m_pTabWnd->IsMDITab ())
{
return 0;
}
CWnd *pwnd = pInfo->m_pTabWnd->GetTabWnd(pInfo->m_nTabIndex);
pInfo->m_strText = pDoc->GetTabTipString();
}
return 0;
}
As you can see, a method for getting a pointer to the CDocument derived object CMyDoc from pwnd is needed. From what I have gathered so far, pwnd is a CWnd * to the tab control, and casting it to a (CMyDoc *) does NOT provide a valid pointer (I have tried).
Because the act of clicking on the tab activates the correct doc/view (which is the whole point of having a tabbed MDI), there should be some way of getting a pointer to it.. but I cannot see how this is done.
|
|
|
|
|
Also, I should emphasize that the CMyDoc pointer is not necessarily the active document. It can be any document associated with a tab.
|
|
|
|
|
Could you possibly subclass the tab control and add a member (pointer to doc) that you fill in or retrieve as necessary?
|
|
|
|
|
I am using the CMDIFrameWndEx class which has built-in support for tabbed documents.
So I figured out what the problem was. Turns out, the function CFrameWnd::GetActiveDocument() returns precisely what is needed: the document associated with the tab over which the mouse is hovered. This is not the same as the currently active document, in the usual sense (the open tab). Sank a lot of time into this one
Thanks for the replies!
|
|
|
|
|
Hello all,
I have a SDI application that uses a CFormView class to create a window and this window has 2 buttons and 2 edit boxes.
I can resize this window, like minimize and maximize, but the controls all stay at the same place.
I know that it's possible to move the controls based on window size.
But what i want to do is, as the window is expanded the controls and it's text content to grow proportionally and same when the window is shrinked.
Is that possible to do? i.e., increase/decrease size of controls and texts per window size.
Any sample code will help.
Thanks in advance.
|
|
|
|
|
OnSize() method which respond to the change of windows could do this job
void CMyView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
m_List.MoveWindow (0, 0, cx, cy);
}
1. keep the original size of dialog, suppose Old_width is original width of dialog. We also deal with the height like this
2. use GetWindowRect( LPRECT lpRect ), which Copies the dimensions of the bounding rectangle of the CWnd object to the structure pointed to by lpRect. From it
you get New_Width (it is new width of dialog now)
3. calculate rate = Old_width/ New_Width .
4. use
CWnd* GetDlgItem(
int nID
) const;
to get pointer(suppose ptr) of button or other control,
use ptr->GetWindowRect( BtnRect ) to get boundary rect of button ( or other ..)
calculate new rect of button( suppose new_btn_rect ) through rate and BtnRect (the height also shoud be consided)
5. use ptr->MoveWindows(new_btn_rect ) to move button and change its size
|
|
|
|
|
There are several ways to do the re-positioning of controls. If you just want to experiment a bit for yourself, you can start by following the first answer and familiarize yourself with the functionality. If you want to see how others have done it, here are a couple of CodeProject articles:
MFC/C++ Helper Class for Window Resizing[^]
Control Positioning and Sizing using a C++ Helper Class[^]
Simple and more powerful resizable dialog[^]
EasySize - Dialog resizing in no time![^]
ResizableLib[^]
There are several other articles, just follow the "Related Articles" links in the right hand side bar on the article pages.
My final suggestion is to be prepared to drop the idea of resizing the text. I was involved with a project many years ago where we had to do exactly what you have described and we ended up throwing it away because we were unable to make it look good in all cases. Especially handling text on buttons kept causing problems.
As I said, it was a long time ago, so maybe you can find a solution that works well for you.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|