|
just delete the wizard-made variable and use your own. You will need to rename the variable in DDX macros section too.
Jaime
|
|
|
|
|
I did that and this is how it shows up, 100000, I added a command which increases the value by 1, ak,; cash++. I hit the button, and it shows up as it has been changed in the list box, but not the edit box.
The List Box's purpose is to show changes, like if you buy a car, it will say you lost $10,000, and the edit box display's how much money you currently have, and updates accordingly...
If I delete the preset in the DDX section it turns into -858993460, and so i deleted it being set in the begining of the file where it says unsigned long cash = 100000; to long cash. (I changed the unsigned part also)
The two problems are that
1. The edit box doesn't update.
2. The edit box doesnt have a $ before the number, how do i do that?
Thanks alot for your help.
Here is how the source beginning is:
-------------------------------------------------------------------------
#include "stdafx.h"
#include "Tycoon.h"
#include "TycoonDlg.h"
#include "BUY.h"
#include "SELL.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
long cash;
unsigned int day = 01;
unsigned int month = 01;
unsigned int year = 04;
unsigned int chp;
unsigned int mhp;
/////////////////////////////////////////////////////////////////////////////
// CTycoonDlg dialog
CTycoonDlg::CTycoonDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTycoonDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTycoonDlg)
cash = 100000;
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTycoonDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTycoonDlg)
DDX_Text(pDX, IDC_CASH, cash);
//}}AFX_DATA_MAP
}
-------------------------------------------------------------------------
|
|
|
|
|
Is there a RegisterWindowMessage equivalent for notify id's? If i assign an arbitrary number it might already exist.
|
|
|
|
|
use
WM_USER + a value
mind is everything.
|
|
|
|
|
How can I convert CString to const char*.
I have UNICODE set up in my project setting.
I tried
<br />
const char* k = (const char*)reinterpret_cast<LPCTSTR>(astring.AllocSysString())
but it only convert the very first character.
If I do just like before
const char* k = (const char*)astring;
I got following error message
<br />
c:\myDlg.cpp(490): error C2440: 'type cast' : cannot convert from 'CString' to 'const char *'<br />
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called<br />
can you help me how to convert CString to const char* so I can use atol(), atoi() function.
|
|
|
|
|
First of all, AllocSysString() returns a BSTR , which is a string type used by COM (among other things). You probably don't want this, if you're just converting string types.
If you are using MFC 7.0 or 7.1 (corresponding to VS .NET 2002 or 2003), you can do the following:
CString astring;
CStringA astring_A(astring);
const char *k = astring_A.GetBuffer(); CStringA is the char form of CString , and includes a constructor that automatically converts from the _TCHAR form (CString ) if necessary. I believe that, by default, the conversion uses the CP_ACP code page.
If you are using VC6, it's a little harder:
CString astring;
int astring_A_size = (astring.GetLength() * sizeof(_TCHAR)) + 1;
char *astring_A = new char[astring_A_size];
::WideCharToMultiByte(CP_ACP,0,(LPCWSTR)astring,-1,astring_A,astring_A_size,NULL,NULL);
const char *k = astring_A; WideCharToMultiByte is an API function that converts a wide character string to a multibyte character string according to a specified code page.
Please note that my code here is an example only. If you are using other code pages, you'll need to be more careful. Also, my allocation for astring_A in the second example is only an approximation. WideCharToMultiByte can also be used to calculate the size of the MBCS string, so that you can allocate exactly the right amount of buffer.
Software Zen: delete this;
|
|
|
|
|
|
instead of converting the CString to a const char * in order to use atoi or atol, use the wchar versions of the functions ( _wtoi or _wtol ). Or better yet, use the TCHAR macros, _ttoi or _ttol, in your code.
CString str = _T("123");
int num = _ttoi(str);
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Hi, people. Can sommebody explain me the difference
between
1. char str[256]
2. char *str = new char(256)
I thought it's equevalent, but my program works good with 1st and fails sometimes when I use the second variant. Unfortunately I can't watch when it happens.
Help me
|
|
|
|
|
I think what you want is:
char *str = new char [256];
[] instead of ()
|
|
|
|
|
Kosk has the correct answer, but here's a little explanation:
The first form is an array of 256 char 's.
The second form returns a pointer to a single char , initialized to the value 256 (which actually initializes the value to zero, which is the lower 8 bits that fit into a single char ).
What you actually want is char *str = new char[256]; , which sets str to a pointer that is an array of 256 char 's. Note that, with this form, when you no longer need the array, you should use delete []str .
Software Zen: delete this;
|
|
|
|
|
char str[256];
is an array of characters (actually unsigned integers)
char *str = new char[256];
is a pointer to an array of characters stored in memory
this is mostly used in functions that take an output parameter.
|
|
|
|
|
In all the examples i have come across they use SystemParameterInfo() to set the wallpaper
but apparently that just doesnt work on my OS (Win M.E.)
i know how to set it in the registry but i just need a way to update it. anyone one know how?
|
|
|
|
|
Did you try setting the "fWinIni" parameter of SystemParametersInfo() to SPIF_SENDCHANGE ?
Bikram Singh
|
|
|
|
|
I wist to initialise some items in a structure, but the only way I can see to do it is as follows:-
typedef struct <br />
{<br />
char fieldDesc [100];<br />
char detailsDesc [20];<br />
char unitsStr [10];<br />
}GENERAL_DATA;<br />
<br />
typedef struct <br />
{<br />
unsigned short data;
GENERAL_DATA details;
}ITEM_DATA;<br />
<br />
ITEM_DATA thisItem;<br />
<br />
strcpy(thisItem.details.fieldDesc,"The field description");<br />
strcpy(thisItem.details.detailsDesc,"This is the details..");<br />
etc
Are they any way I can set the char data up in ITEM_DATA, or could I set the constant data up in a new structure:-
typedef struct <br />
{<br />
unsigned short data; <br />
char fieldDesc [100] = "This is a description";<br />
char detailsDesc [20] = "The details....";<br />
char unitsStr [10] = "$";<br />
}ITEM_DATA_01;
etc
The above does not work, but thats what I am after!
I know what data should go into the char fields in advance, but the only way I can see to load this constant data in is via a statement like
strcpy(thisItem.details.fieldDesc,"The field description");
Are they any other ways to load this constant data?
Graham.
grahamfff
|
|
|
|
|
Well you can always do
<br />
typedef struct yadda<br />
{<br />
yadda()<br />
{<br />
strcpy(fieldDesc,"This is a description");<br />
strcpy(detailsDesc ,"This is a description");<br />
strcpy(unitsStr ,"This is a description");<br />
<br />
}<br />
char fieldDesc [100];<br />
char detailsDesc [20];<br />
char unitsStr [10];<br />
}GENERAL_DATA;<br />
Then every new GENERAL_DATA variable will be initialized.
|
|
|
|
|
Thanks for the info, that solves the first problem.
But can you advise on how to use a union or other overlay method.
I just want to deal with a buffer when sending out the data, but deal with the structure itmes in the program; i.e. two names for the same item of data; see listing below
typedef struct yadda<br />
{<br />
yadda()<br />
{<br />
strcpy(fieldDesc,"This is a description");<br />
strcpy(detailsDesc ,"This is a description");<br />
strcpy(unitsStr ,"This is a description");<br />
<br />
}<br />
char fieldDesc [100];<br />
char detailsDesc [20];<br />
char unitsStr [10];<br />
}GENERAL_DATA;<br />
<br />
typedef struct <br />
{<br />
unsigned short data; <br />
GENERAL_DATA details;<br />
}ITEM_DATA;<br />
<br />
union DATA01<br />
{<br />
ITEM_DATA thisSignal;<br />
unsigned int buffer[512];<br />
}data01;
I get the error c:\Overlays\OverlaysDlg.cpp(48): error C2620: member 'SIGNAL1::thisSignal' of union 'SIGNAL1' has user-defined constructor or non-trivial default constructor.
Are they another method of overlaying the data.
grahamfff
|
|
|
|
|
If this is C++, you should add constructors to both struct 's to handle the initialization. If this is 'plain old' C (which I guessed might be the case, from your use of typedef ), you can try the following:
typedef struct
{
char fieldDesc [100];
char detailsDesc [20];
char unitsStr [10];
} GENERAL_DATA;
typedef struct
{
unsigned short data;
GENERAL_DATA details;
}ITEM_DATA;
static ITEM_DATA InitialItemData = {
1234,
{
"field description",
"detail",
"units"
}
}; Anywhere you need to initialize an ITEM_DATA , just assign it:
ITEM_DATA current_item;
current_item = InitialItemData;
Software Zen: delete this;
|
|
|
|
|
Thanks for the info and yes was for C code. Just two points, how would you do it for C++ and can you overlay the structure via union;
union DATA01<br />
{<br />
ITEM_DATA thisSignal;<br />
unsigned int buffer[512];<br />
}data01;
i.e. same data by two different names.
grahamfff
|
|
|
|
|
For C++, I would add a constructor. In C++, class and struct are the same except for one point. With struct , members have public access by default, while with class , the access is private by default. This means that a struct can have a constructor, and that's the place you should initialize the values.
You can initialize the union as follows:
data01.thisSignal = ItemDataInitial; where ItemDataInitial is an initialized ITEM_DATA as I described in the previous post. If you use a constant initializer for the union , it must correspond to the first field in it.
Software Zen: delete this;
|
|
|
|
|
Thanks for the info. I have started to use your scheme, or a varient of it.
Will use the union as follows:-
typedef struct
{
unsigned short data1;
}DATA1;
typedef struct
{
unsigned : 4 data2;
}DATA2;
etc
union ALL_DATA_UNION
{
DATA1 data1;
DATA2 data2;
etc
unsigned short buffer[50];
}ALL_DATA;
I need to transmit the buffer, but want all the data items 'overlayed' with the buffer. Dont need to initialise the union as can use memcpy to zero the buffer.
I will have another structure with the details of each item of data and initialise it as per your scheme.
Thanks again, but please point out if this scheme is fault.
Regards,
Graham
grahamfff
|
|
|
|
|
You can use constructor in your structure like this:
struct MyStructure<br />
{<br />
char blablabla[200];<br />
MyStructure()<br />
{<br />
strcpy(this->blablabla,"Testing");<br />
}<br />
}
|
|
|
|
|
Hai,
I'm doing an application in Win32 where I am creating a window dynamically.I want to know how to disable the minimize maximize and close buttons in the title bar of the window dynamically.Can anyone suggest?
Thanks a lot.
|
|
|
|
|
One solution is EnableMenuItem();
GetSystemMenu(FALSE)->EnableMenuItem(SC_SIZE, MF_ENABLED/MF_DISABLED);
Kuphryn
|
|
|
|
|
How can i get the notification in to my application, when the IP address changes..?
mind is everything.
|
|
|
|