Click to See Complete Forum and Search --> : What would be the best way to store


chrishowarth
July 5th, 2007, 11:54 AM
Hello ~

I am trying to store the value returned from an Edit Box using GetDlgItemText. I retrieve the data from the Edit Box and store it to a character array. However, this does not seem to be returning anything! I also think that there must be a more efficient way of doing this, especially as I have to guess the maximum amount of characters the user enters when creatign the array. Here is the code:

char bColour [8]; //Border Colour
int bWidth [5]; //Border Width
char mFont [60]; //Menu Font
char hBgColour [8]; //Header Bg Colour
char hColour [8]; //Header Colour
char onBgColour [8]; //Hover Bg Colour
char offBgColour [8]; //noHover Bg Colour
char onColour [8]; //Hover Colour
char offColour [8]; //noHover Colour
int mPad[8]; //Header Colour
char bgImage [60]; //(Optional) Bg Image
char sepColour [8]; //Separator Colour
int sepSize; //Separator Size
char subImage [8]; //SubImage (little arrow thing)
int subImagePad; //SubImage Padding

...

case IDOK:
{
GetDlgItemText(HDlgStyle, ED_BCLR, bColour, sizeof(bColour));
// TODO (Christopher#5#): Function returns string; but needs to return an integer.
//GetDlgItemText(HDlgStyle, ED_BWDTH, bWidth, sizeof(bWidth));
GetDlgItemText(HDlgStyle, ED_FNT, mFont, sizeof(mFont));
GetDlgItemText(HDlgStyle, ED_HBGCLR, hBgColour, sizeof(hBgColour));
GetDlgItemText(HDlgStyle, ED_HCLR, hColour, sizeof(hColour));
GetDlgItemText(HDlgStyle, ED_ONBGCLR, onBgColour, sizeof(onBgColour));
GetDlgItemText(HDlgStyle, ED_OFFBGCLR, offBgColour, sizeof(offBgColour));
GetDlgItemText(HDlgStyle, ED_ONCLR, onColour, sizeof(onColour));
GetDlgItemText(HDlgStyle, ED_OFFCLR, offColour, sizeof(offColour));
// TODO (Christopher#5#): Function returns string; but needs to return an integer.
//GetDlgItemText(HDlgStyle, ED_PADDING, mPad, sizeof(mPad));
GetDlgItemText(HDlgStyle, ED_BGIMAGE, bgImage, sizeof(bgImage));
GetDlgItemText(HDlgStyle, ED_SEPCLR, sepColour, sizeof(sepColour));
// TODO (Christopher#5#): Function returns string; but needs to return an integer.
//GetDlgItemText(HDlgStyle, ED_SEPSIZE, sepSize, sizeof(sepSize));
GetDlgItemText(HDlgStyle, ED_SUBIMG, subImage, sizeof(subImage));
// TODO (Christopher#5#): Function returns string; but needs to return an integer.
//GetDlgItemText(HDlgStyle, ED_SUBPAD, subImagePad, sizeof(subImagePad));
}
MessageBox(GetActiveWindow(), onBgColour, "onBgColour", MB_OK | MB_ICONINFORMATION);


What is wrong?

Thanks;

Christopher Howarth

VladimirF
July 5th, 2007, 01:42 PM
I am trying to store the value returned from an Edit Box using GetDlgItemText. I retrieve the data from the Edit Box and store it to a character array. However, this does not seem to be returning anything!What do you mean by "does not seem"? Does it or does it not? What does GetDlgItemText() return? 0? Did you check GetLastError()? What was it?

I also think that there must be a more efficient way of doing this, especially as I have to guess the maximum amount of characters the user enters when creatign the array.You don't have to guess! You have options...
1. Limit the number of chars user can enter into edit box (via EM_LIMITTEXT message) and use the same value for the buffer length.
2. Use WM_GETTEXTLENGTH message and allocate buffer dynamically.

Also, look at GetDlgItemInt() that can translate the text into int value for you.

chrishowarth
July 7th, 2007, 12:05 PM
Ah thankyou. Solved - I hadn't assigned IDs to my dialog components! Thanks - I will create my arrays dynamically and limit the possible values.

~ Christopher

VladimirF
July 7th, 2007, 01:25 PM
Ah thankyou. Solved ...You are welcome.
Happy 7/7/7!