|
Have a dialog(Dialog1) with a combobox control(ID:IDC_COMBO and variables:m_combo) initilaise with some values.
Have a CFormView with a edit control(IDC_EDIT1).
How do you passed the value in the combobox to the edit?
Thanks
S1189216G
|
|
|
|
|
you told that the combobox variable is m_combo.... but what type is it? is it a CComboBox? an int?
Remember that classwizard let you add the DDX variable mapping to be a control or a value.
If it's a value or a control, you will need to get the string of the combobox using
GetDlgItem(IDC_COMBO)->GetWindowText(sValue);
Also if it is a value:
UpdateData(TRUE);
((CComboBox *)GetDlgItem(IDC_COMBO))->GetLBText(m_combo, sValue);
Cheers
Jaime
|
|
|
|
|
hello everyone..
currently i'm doing a mini assignment using vc. it's very simple. the input will be a string, then i have to convert it into hex and then show the hex version with a click of a button. so roughly i will have 2 edit boxes and a button. i have this code in a non MFC environment:
int main(void)
{
char input[n];
int result, i=0;
cout<<"pls key in your name"<
|
|
|
|
|
CString GetBuffer(int stringLen) is what you want
(By the by, you can use int len = str.GetLength()
to get the length of the string for getting
the buffer.)
Straight from MSDN CD:
// example for CString::GetBuffer
CString s( "abcd" );
#ifdef _DEBUG
afxDump << "CString s " << s << "\n";
#endif
LPTSTR p = s.GetBuffer( 10 );
strcpy( p, "Hello" ); // directly access CString buffer
s.ReleaseBuffer( );
#ifdef _DEBUG
afxDump << "CString s " << s << "\n";
#endif
Once you have a pointer to the buffer you can
parce it; but I would advise against changing it.
You can't print your output using cout in MFC.
Again use a CString (the member format)
Something like :
CString str
str.Format("The hex value is: %x\n", char);
Then use AFxMessageBox(str)
There are a million ways...
Hope the above helps
WedgeSoft
|
|
|
|
|
alrite.. i'll give it a try.. thanx..
~wilD cat~
|
|
|
|
|
hi,
i need to do search and remove content in a CMapStringtoPtr.
currently, i used a loop to iternate thro' the CMap, do search and RemoveKey(). however, my app. crash in the loop due to the RemoveKey() may change Map structure.
below is my code. anyone method to solve my problem? i can figure out do search in a loop, store the key and remove in another loop. but, i want to know any method to all of them in a loop?
thanks,
jim
POSITION pos, pos2;
pos = m_ActiveReleaseMap.GetStartPosition();
int listlen = m_ActiveReleaseMap.GetCount();
if (listlen == 0) {return;}
do
{
pos2 = pos;
m_ActiveReleaseMap.GetNextAssoc(pos, OrderNo, (void *&) ptr);
// do checking. if match, remove.
m_ActiveReleaseMap.RemoveKey();
}
while( pos != NULL) ;
|
|
|
|
|
I wrote a response, then re-read your question.
In the second half of your question you say
you have had success by storing and deleting
in a second loop -- that way my solution. my
response was a waste of your time. Sorry. I
have had the same problem and am of the belief
you can not remove an item within the loop. You
must do it in a second loop. But (more waste of
your time) I can't say way. I'll watch for other
answers to your question. perhaps someone will
post a definative reason.
WedgeSoft
|
|
|
|
|
In the loop, try putting a
pos = m_ActiveReleaseMap.GetStartPosition();
before this:
m_ActiveReleaseMap.GetNextAssoc(pos, OrderNo, (void *&) ptr);
Bikram Singh
|
|
|
|
|
actually, i did this b4 but seems still not ok!
for( pos = m_ActiveReleaseMap.GetStartPosition(); pos != NULL; )
m_ActiveReleaseMap.GetNextAssoc(pos, OrderNo, (void *&) ptr);
// search and removal
}
|
|
|
|
|
Hi !
I use multi-thread in my software. I must declare the ThreadProcedure static if I don't want the following error message:
error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
The problem is that I call many functions and variables which are not static. Do I need to declare everything static or I don't understand the goal of the STATIC keyword in my declaration of my ThreadProcedure ?
Thank you to help me
Note: I use VC++ 6.0
|
|
|
|
|
Danny Gilbert wrote:
I don't understand the goal of the STATIC keyword in my declaration of my ThreadProcedure
I assume "ThreadProcedure" is a class member?
If you declare "ThreadProcedure" static, the function essentially "does not belong" to any single instance of the class. So, to use this method, you need to pass the instance's pointer (eg. via ThreadProcedure(this);), for the ThreadProcedure to be useful at all.
Other than the passed-in pointer, anything that ThreadProcedure uses from the class it is declared in, must also be defined as static.
Bikram Singh
|
|
|
|
|
does anyone have code for a simple Non-MFC ftp server, I am doing a project and I would like help. Thanks for reading this.
-Ryan M.
|
|
|
|
|
How do I load a variable inside an edit box?
I have an edit box stated below, its called "OnCash", It's ID is "IDC_CASH".
Source:
----------------------------------------------
void CTycoonDlg::OnCash()
{
//$cash(variable)
}
----------------------------------------------
I want it to say in the editbox that is read only, $(cashvariable)
so it would look like this inside the editbox:
$100000 (default value for the cash, unsigned long)
Can anyone help me?
|
|
|
|
|
You need to create a variable for the value of the edit box
do this by going to the resource viewer right click on the dialog select "Class Wizard"
click on the Member Bariables tab
select IDC_CASH and click Add Variable
name it something like m_Cash
then to set the text in it do this
m_Cash = "$1000000";
UpdateData( TRUE ); // sets the edit boxes text to m_Cash's value
to get the edit boxes text and store it in m_Cash call UpdateData( FALSE );
|
|
|
|
|
Problem is:
I already made a value, and It's being read all across the program, im just trying to sorta make an active display in the MFC application on how much money I have... It's an edit box, displaying how much cash you have.
This is part of the source:
#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
unsigned long cash = 100000;
But Class Wizard makes a new variable, and I want to use my old variable.
|
|
|
|
|
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 ()
|
|
|
|