|
please go thru MSDN. it has detailed explanation about all the classes mentioned my u.
|
|
|
|
|
i have a combo box which is of type int. i need to retreive the value that is there in the combo box. that is for example i have 2 values in a combo box. 100 and 200. now when i select 100 from the combo box the value has to send than the index. how can i do that?
|
|
|
|
|
With MFC, the simplest a way is binding the combo to an int a CString variable (use the Add Variable Wizard of VS) and then convert the latter to an int (for instance with _tstoi ). You may also use the GetItemData /SetItemData pair to store (and retrieve) directly int values inside combo box items.
If you don't like MFC, the you should retrieve the item text and then convert it to int , i.e.
const INT SIZE=0x100;
TCHAR buffer[SIZE];
INT SelectedInt;
LRESULT sel = SendMessage(hCombo,CB_GETCURSEL,(WPARAM)0, (LPARAM)0);
if ( sel != CB_ERR)
{
INT n = SendMessage(hCombo,CB_GETLBTEXT,(WPARAM)0, (LPARAM) (LPTSTR) buffer);
if ( n != CB_ERR)
{
SelectedInt = _tstoi(buffer);
}
}
Please note, I used a 'quick way' of allocating a relatively large buffer (since your combo contains short strings); you can use CB_GETLBTEXTLEN message to know requested buffer size in advance.
BTW, you have also the option to associate the int values to the Item Data of the combo box and retrieve it, whenever needed, via CB_SETITEMDATA message (it is left as an exercise for the reader... ).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
modified on Monday, December 10, 2007 6:40:52 AM
|
|
|
|
|
i am using MFC. my requirement is simple. whenever i am trying to acess the variable i am getting the value as the index. i need to value from the combo box.
|
|
|
|
|
You're right, mapping the combo to an int variable make the latter containing the selected index value.
Hence you can either:
(1) Map the combo to a CString variable and the performing _tstoi on the variable.
(2) Getting a pointer (say pCombo ) to your combo box class (you can either map a variable or call GetDlgItem ) and then:
int nSel = pCombo->GetCurSel();
int nSelValue;
if (nSel != CB_ERR)
{
CString strValue;
pCombo->GetLBText(pCombo->GetCurSel(), strValue);
nSelValue = _tstoi(strValue);
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
is there any other way to get the value in the combo box. i am declaring the combo box variable as int. and this variable is used in some more files. so cant change the data type. it can be only int.
|
|
|
|
|
Chandrasekharanp wrote: so cant change the data type. it can be only int.
In fact, you can. Sometimes a bit refactoring effort it is worthy to do.
Anyway I don't insist on design policies, hence, supposing you int variable name is iCurSel (and your combo box ID is IDC_COMBO ), you can do:
int iValue;
UpdateData();
if (iCurSel != CB_ERR)
{
CString strValue;
((CComboBox *) GetDlgItem(IDC_COMBO))->GetLBText(iCurSel, strValue);
iValue = _tstoi(strValue);
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
alright.. i have done it. now i have one more thing to do. i need to pass this value to another file. tried using static. but i dont know if i am doing it the right way. it has an error. i tried to declare the variable as
<br />
static int value <br />
in the .h file.
what is the procedure to do that?
|
|
|
|
|
I have problem to send a message to the server application using send() function using winsock.h. Im trying to send my MAC address information to the server. Firstly, i detect the MAC address at the client side using GetAdaptersInfo API. The problem is the MAC address is an unsigned character. The send() function could not send this type of message. The error would produce 'error C2664: 'send' : cannot convert parameter 2 from unsigned char [] to const char. I tried to convert the unsigned char to const char using casting but it is still the same. Maybe i did the casting wrong. How can i solve this? Is there any examples? Thanks
|
|
|
|
|
Muhamad Hazwan Halim wrote: Maybe i did the casting wrong. How can i solve this?
Maybe by posting what you did so that we can see ? Without code it's quite a challenge to tell where you are wrong.
Usually, a casting is sufficient.
|
|
|
|
|
Probably you have something similar to:
SOCKET mySocket;
IP_ADAPTER_INFO myIPAddrInfo;
hence you can do something like:
send( mySocket, (const char* )(myIPAddrInfo.Address), myIPAddrInfo.AddressLength, 0 );
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks Pallini. I think that should solve it. I altered the code and there are no more error. I didnt update the code on the receiver (server) side yet but i think it should not be a problem. If there are problems, i will get back to you guys again. Thanks alot guys.
|
|
|
|
|
I want to read the first byte of a buffer. Tried as follows.
char cRet_Ser_ID = *((char*)&InMsg[0]);
Is this ok, I mean is there any other way to do this.
I appreciate your help all the time...
Eranga
|
|
|
|
|
If InMsg is a char array, then you can simply do:
char cRet_Ser_ID = InMsg[0];
If not, you can simply do this:
char cRet_Ser_ID = *((char*)InMsg);
InMsg is equivalent to &InMsg[0]
|
|
|
|
|
what about this :
char c = static_cast<char>(InMsg[0]);
however, you didn't tell (once again) that InMsg was a BYTE* object...
modified on Monday, December 10, 2007 5:12:42 AM
|
|
|
|
|
toxcct wrote: however, you didn't tell (once again) that InMsg was a BYTE* object...
It is, InMsg is a <byte*> object, as I said in my last question
I appreciate your help all the time...
Eranga
|
|
|
|
|
yeah, i know it is, but the ones reading this question are not necessarily aware of your lately asked question.
so, when you ask something, provide all the infos for us to help, as if it were the first time you ask.
|
|
|
|
|
Ya, it's true and I take care of to do it next time in correct way. Sorry about that.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Thanks for all the replays.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Hello everyone!
I'm making a program that I would like to have a plug-in interface. I thought of using something like Lua, but I would like them to be written in C or C++. I know I can use DLL's, but I want this to be cross-platform.
What's the most common method? I really don't want to use an external library, but I will if I'm too lazy to do it myself.
Thanks in advance!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Lord Kixdemp wrote: I want this to be cross-platform.
Not asking for the moon or anything then . With the current state of technology if you want it to be really cross platform you'll need to ship it as source and that source will need to be dependent on the C++ standard library, (no exotic features) and absolutely nothing else.
Otherwise I would recommend going for a statically linked library built with GCC/g++ under MingW or Cygwin on Windows and from the same source using a similar version of GCC/g++ on your Linux flavour of choice. If you can achieve that with genuinely shared source then a. you're a star b. please let me know the detaisl so I can do it to.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Dear Friends,
Could any one tell me. How to hide the Caption Bar in the dialog box using SetWindowLong() without removing the title bar in the properties of the dialog.
Thanks and Regards.
SANTHOSH V
|
|
|
|
|
Are you interested in changing the WS_CAPTION style dynamically?
If so you can use
ModifyStyle( WS_CAPTION, 0 ); (using MFC)
OR
SetWindowLong( hWnd, GWL_STYLE, GetWindowLong( hWnd, GWL_STYLE ) & ~WS_CAPTION );
|
|
|
|
|
DWORD dwStyle = wnd.GetStyle();
::SetWindowLong(wnd, GWL_STYLE, (dwStyle & ~ WS_CAPTION));
Regards,
Paresh.
|
|
|
|
|
Hi,
I want to enable drag and drop for tree view. I used DragAcceptFile(TRUE) in the tree view and that worked fine for explorer folder.
My other requirement is the drag and drop should also work for email attachments say for outlook or gmail account. To clarify I want to drag an attachement from an email to a node in the treeview. Unfortunately when I am trying to do this it is not enabling and no message is being fired. can anybody help me please?
|
|
|
|