Toon posts:

[C++] Help me aub dit leak te vinden

Pagina: 1
Acties:
  • 44 views sinds 30-01-2008

Verwijderd

Topicstarter
Beste mensen, ik heb een best mooie textbox gemaakt. Een class diealles kan wat een textbox moe kunnen. Een probleempje, er zit een memory lea in (zo lijkt het). De code is best lang, maar toch zet ik hem hier neer (ik kan het nergens anders heen uploaden). Meel mij aub als je het lek ziet.

//MADE BY: JEROEN PAUL. COPYRIGHT 2002.

//The textBox Class

class textBox{
private:
//Variables about the x and y position of the object

int top;
int left;
int width;
int height;

//Variables about the style of the object

bool setToSystem;
bool initialised;
bool fadeOnInt;

int tInit;

long borderColor;
long inActiveBorderColor;
long insideColor;

//Text variable, contains the text found in last refresh.

char * text;

//Variables about the place on which things have to be drawn

HWND hwnd;
HWND parent;
HWND nextFocus;

HINSTANCE instance;

RECT *border;
RECT *inside;

//Functions declared to keep intern variables up-to-date

void intern_getText();
void fade2ND ();
void fadeOut ();
public:
//These two functions are the constructor and th destructor. The constructor can be used any time.

textBox (int ileft,int itop, int iwidth, int iheight, bool isetToSystem,bool ifadeOnInt);
~textBox ();

//This is the refresh function. It refreshes the lines around the textbox and acquires its contents.

void refresh();

//These two functions are used to initialise or deinitialise the textbox. The initilise function is only to be used in the main funtion.

void initialise(HINSTANCE instance, HWND parent);
void deinitialise();

//These functions set the contentof the textbox to a value.

void setText(char * text);

//These functions are used to get or set the colours

void setColors(long activeColor, long inActiveColor, long insideColor);
void aquireColor();

//The following functions can be used for the focus settings.

void setNextFocus(HWND nextFocus);
void goToNextFocus ();
void setFocus();

//These functions convert a obect of the class to a certain variable type


operator char *()const;
operator int () const;
operator HWND () const;

//This function aquires the text of the textbox.

char * getText();
};

void textBox::setFocus(){
SetFocus(hwnd);
}

void textBox::goToNextFocus (){
SetFocus(nextFocus);
}


void textBox::setNextFocus(HWND nextFocus){
textBox::nextFocus = nextFocus;
}

textBox::operator HWND () const{
return hwnd;
}

textBox::~textBox (){
delete[] text;

FrameRect (GetDC(parent), border, CreateSolidBrush(insideColor));

delete[] border;
delete[] inside;

DestroyWindow(hwnd);
}

//FrameRect (GetDC(parent), border, CreateSolidBrush(insideColor));

inline void textBox::aquireColor (){
borderColor = GetSysColor(COLOR_HIGHLIGHT);
inActiveBorderColor = GetSysColor(COLOR_INACTIVECAPTION);
insideColor = GetSysColor (COLOR_BTNFACE);
}

void textBox::fade2ND (){
unsigned char r,g,b;

r = insideColor & 255;
g = (insideColor>>8)& 255;
b = (insideColor>>16) & 255;

FrameRect(GetDC(parent),border,CreateSolidBrush(inActiveBorderColor));

for (int a = (r+g+b)/3; a<255; a++){
r = a;
g = a;
b = a;
for (unsigned long D = GetTickCount() + 1; D>GetTickCount(););
FillRect (GetDC(parent), inside, CreateSolidBrush(rgb(r,g,b)));
}
}

void textBox::fadeOut (){
unsigned char r,g,b, xr,xg,xb;

r = insideColor & 255;
g = (insideColor>>8)& 255;
b = (insideColor>>16) & 255;

xr = 255;
xg = 255;
xb = 255;

while (rgb(xr,xg,xb)!=insideColor){
if (xr!=r) xr--;
if (xg!=g) xg--;
if (xb!=b) xb--;

for (unsigned long D = GetTickCount() + 1; D>GetTickCount(););
FillRect (GetDC(parent), inside, CreateSolidBrush(rgb(xr,xg,xb)));
}
}

void textBox::setColors(long activeColor, long inActiveColor, long middleColor){
borderColor= activeColor;
inActiveBorderColor = inActiveColor;
insideColor = middleColor;
}

textBox::operator char *() const{
return text;
}

textBox::operator int () const{
return charToInt(text);
}

void textBox::deinitialise(){
if (initialised){
initialised = !DestroyWindow(hwnd);
fadeOut();
}
}

void textBox::setText(char * text){
if (!strComp(text, textBox::text)) SetWindowText(hwnd,text);
}

char * textBox::getText(){
return text;
}

void textBox::intern_getText(){

GetWindowText(hwnd, text,255);
resize(text);
}

void textBox::refresh(){
if (initialised) {
if (GetPixel(GetDC(parent), left+width, top+height)!=borderColor ||GetPixel(GetDC(parent), left, top)!=rgb(61,149,255) || GetPixel(GetDC(parent), left+width, top)!=rgb(61,149,255)||GetPixel(GetDC(parent), left, top+height)!=rgb(61,149,255)) {
FrameRect(GetDC(parent),border,CreateSolidBrush(borderColor));
}


if ((GetFocus()==hwnd) && GetAsyncKeyState(9)) {
while (GetAsyncKeyState(9));
goToNextFocus();
}

intern_getText();
}else{
if (GetPixel(GetDC(parent), left+width, top+height)!=inActiveBorderColor ||GetPixel(GetDC(parent), left, top)!=rgb(61,149,255) || GetPixel(GetDC(parent), left+width, top)!=rgb(61,149,255)||GetPixel(GetDC(parent), left, top+height)!=rgb(61,149,255)) {
FrameRect(GetDC(parent),border,CreateSolidBrush(inActiveBorderColor));
}
}
}

void textBox::initialise(HINSTANCE instance, HWND parent)
{
if (!initialised){
if (tInit>0 && fadeOnInt){
fade2ND();
}


textBox::parent = parent;
textBox::instance = instance ;
textBox::hwnd = CreateWindow(TEXT("edit")
,NULL
,WS_CHILD | WS_VISIBLE | SS_LEFT | WS_CLIPCHILDREN | ES_AUTOHSCROLL
,left+1
,top+1
,width-2
,height-2
,parent
,NULL
,instance
,NULL
);

border= new RECT;

border->left = left;
border->top = top ;
border->right = left+width;
border->bottom = top+height;

inside = new RECT;
inside->left = left+1;
inside->top = top+1 ;
inside->right = left+width-2;
inside->bottom = top+height-2 ;

initialised ++;
tInit++;


}
}
textBox::textBox (int ileft,int itop, int iwidth, int iheight, bool isetToSystem, bool ifadeOnInt):
top (itop),
left (ileft),
width (iwidth),
height (iheight),
setToSystem (isetToSystem),
initialised (false),
fadeOnInt(ifadeOnInt),
tInit (0)
{
if (setToSystem) aquireColor();

text = new char [255];
}

Verwijderd

[ code ] for(i=0;i<4;i++) { .. } [ / code] behoud opmaak van tekst (preformatted), [code=...] herkent "c, c++, perl, python, asp, vb, java, js, fortran, cobol, pascal, delphi, html", hiervoor komen later zo mogelijk highlighters voor.

Zo nu eerst ff doorlezen...

  • .oisyn
  • Registratie: September 2000
  • Laatst online: 03:21

.oisyn

Moderator Devschuur®

Demotivational Speaker

zo werkt het hier niet

ten eerste is je code totaal niet gecomment, ten tweede moet je niet van ons verwachten dat wij wel even jouw problemen oplossen. Tip: veel debuggers kunnen lekken detecteren (en waar en wanneer ze gealloceerd zijn)

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


Dit topic is gesloten.