|
Hello All,
I am adding values 0,1,2 to a combo box in Initdialog
switch(Message)<br />
{<br />
case WM_INITDIALOG:<br />
{<br />
HWND hwndCombo = GetDlgItem(hwnd, IDC_CB);<br />
SendMessage(hwndCombo , CB_ADDSTRING,0, (LPARAM) "0");<br />
SendMessage(hwndCombo , CB_ADDSTRING,0, (LPARAM) "1");<br />
SendMessage(hwndCombo , CB_ADDSTRING,0, (LPARAM) "2");<br />
}
in other function I want to use the value of the combo box, (user selected item) for that I am using below code
int F;<br />
HWND HCBF = GetDlgItem(hwnd, IDC_CB);<br />
SendMessage(HCBF , CB_GETITEMDATA,(WPARAM)F, 0);
This code has no error but I am getting some junk value and i am not geting the values 0,1,2
Can u please tell me what is the error in the above code ???
Thanking you,
Suresh HC.
|
|
|
|
|
Suresh H wrote: int F;
HWND HCBF = GetDlgItem(hwnd, IDC_CB);
SendMessage(HCBF , CB_GETITEMDATA,(WPARAM)F, 0);
Here , you have not initialized F .
Passing junk values as index. Pass index you want there.
CB_GETITEMDATA is not right message to send in this case, too.
You need to use CB_GETLBTEXT .
|
|
|
|
|
Hi Prasad,
Thanks for the response.
Actually I want to extract the value of the Combo Box (user selected value)
In combo box we have values from 0,1,2,3 ---- so on when user selects some value fro list any number , I want to extract that number and I want to use that number in the program.
Can u please tell me what I have to do ??
|
|
|
|
|
You must use of CB_GETCURSEL for get index to currently selected item instead use of 0
|
|
|
|
|
This code should suffice,
int nIndx =::SendMessage(hCombo,CB_GETCURSEL,0,0);
TCHAR buff[100];
::SendMessage(h,CB_GETLBTEXT,(WPARAM)nIndx,(LPARAM)buff);
|
|
|
|
|
And he needs to a convert atoi
|
|
|
|
|
WhiteSky wrote: And he needs to a convert atoi
Why ?
|
|
|
|
|
If he wants to use of numeric values
|
|
|
|
|
Thanks WhiteSky for the Response, yr info is also very use full for me. I will keep a note of that.
|
|
|
|
|
Thank you
|
|
|
|
|
Ok, you was refering to extracting numbers.
|
|
|
|
|
And also one other thing if he wants to use CB_GETCURSEL(return values) for works on his programs(not for combobox)its not good idea because it returns -1,0,1,...but if he has values like 100,200,300 on his combobox... return values of CB_GETCURSEL not helpfuls
|
|
|
|
|
WhiteSky wrote: CB_GETCURSEL(return values) for works on his programs(not for combobox)
WhiteSky wrote: its not good idea because it returns -1,0,1,...but if he has values like 100,200,300 on his combobox... return values of CB_GETCURSEL not helpfuls
I'm really not getting , what you are trying to say?
|
|
|
|
|
I said its better he uses of value on combobox
|
|
|
|
|
Haven't you seen this[^]?
|
|
|
|
|
Thanks Prasad Code is working.
Thanks for taking some time for me and helping me.
In yr code 1st line was enough for me
int nIndx =::SendMessage(hCombo,CB_GETCURSEL,0,0);
since in the combo box I have values from 0,1,2,3,4,5 and so on …
so as I get the Index number value will be the same as the CB content.
I did not know about the CB index. Thank you very much.
|
|
|
|
|
Suresh H wrote: since in the combo box I have values from 0,1,2,3,4,5 and so on …
so as I get the Index number value will be the same as the CB content.
Seems very strange logic.
But, use CB_GETLBTEXT message, as it will not be the case always.
|
|
|
|
|
Yes Prasad I will make use of it.
|
|
|
|
|
For CB_GETLBTEXT, MSDn says:
lParam
Pointer to the buffer that receives the string. The buffer must have sufficient space for the string and a terminating null character.
With your 100 TCHARS you might or might not be ok.
MSDN gives the solution in the next sentence:
You can send a CB_GETLBTEXTLEN message prior to the CB_GETLBTEXT message to retrieve the length, in TCHARs, of the string.
So, the code-snippet would better be:
int nIndx =::SendMessage(hCombo,CB_GETCURSEL,0,0);
const LRESULT nSize = ::SendMessage(hCombo, CB_GETLBTEXTLEN, (WPARAM)nIndx, 0);
TCHAR buff[nSize+1];
::SendMessage(h,CB_GETLBTEXT,(WPARAM)nIndx,(LPARAM)buff);
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
jhwurmbach wrote: lParam
Pointer to the buffer that receives the string. The buffer must have sufficient space for the string and a terminating null character.
With your 100 TCHARS you might or might not be ok.
True, It is just a quick fix.
jhwurmbach wrote: TCHAR buff[nSize+1];::SendMessage(h,CB_GETLBTEXT,(WPARAM)nIndx,(LPARAM)buff);//buff will contain text returned
Again, small correction here, need to allocate memory on heap.
TCHAR *buff = new TCHAR[nIndx+1];
::SendMessage(hCombo,CB_GETLBTEXT,(WPARAM)0,(LPARAM)buff);
|
|
|
|
|
prasad_som wrote: Again, small correction here,
In the end it doesn't pay to cut short on testing...
Thanks!
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
Hi
All
I am doing multilingual applicaton in VC++, in this application i want marathi menu in my applicatin. I don't want to change menu font from control panel because by setting this all menu in win XP will be in marathi. so Can i set menu font to marahti by any code. please send me solution if anybody have.
Thanks
Atul Mahajan
Atul
|
|
|
|
|
Use a string table if you are using VS2003 or above. Load Unicode strings during runtime if you are using VS6. What have you tried? Where exactly are you stuck? Are you hard-coding menu captions currently?
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|
I am using VC++ 6.0 for this apllication. I tried by using following steps
I open .rc file in MSWord
then change font strings to marathi
save this file
rebuild application and run it.
but font of menu not change, i read this steps on some site on internet so i follow this step , but not get desired result.so please guide me
Thanks in Advance
Atul
Atul
|
|
|
|
|
M. Atul wrote: I open .rc file in MSWord
then change font strings to marathi
save this file
rebuild application and run it.
VS6 is does not understand unicode. How did you even compile it with unicode characters? VS Editor must have given you an error that the resource file is corrupted and so can't be loaded. If not, then you did not save it with unicode characters which essentially means you did not make a change. All you have to do is, store your strings in an external file and load it dynamically. Ever heard of resource dlls? I suggest you read more on localization.
Nobody can give you wiser advice than yourself. - Cicero
ப்ரம்மா
|
|
|
|
|