|
When working in MFC applications and your not sure whether you will need UNICODE or not, you just need to be carful in your string handling. Declare characters etc using the TCHAT type. This will resolve to either char or wchar depending on whether you have UNICODE defined. This will make all your types switch automatically.
After that, your big concern will be string manipulation functions. strlen() etc. They all have an equivalent beginning with _tcs which resolves to either the ANSI or UNICODE versions of the functions depending on the UNICODE define.
The MFC CString class is automatically UNICODE complaint if your build for UNICODE.
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
Is the UNICODE only when dealing with strings and char? What kind of concerns will I have when I am manipulating strings? Is there functions like strlen() designed for UNICODE? Is this a good practice to get into when coding in MFC and is there a library I have to use?
Thanks for your all of your help!!
|
|
|
|
|
For the manipulation you use the equivalent _tcs... version of the function.
If your have MSDN, just type _tcs... into the index option and it will give you a list of all the vaailable functions. There should be an equivalent for all the standard C runtime string functions.
e.g. strlen -> _tcslen
strcpy -> _tcscpy
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
The string functions are the only ones I am going to have to worry about correct?? If I am going to start to write a piece of software would you advise to use the UNICODE instead of regular char? That is all I have to worry about correct, just strings??!
Again did you mention anything about a include file for UNICODE?
I caught that type and just figured it was TCHAR.
Thanks Roger, you have been a great help!!!!!!!! Just as everyone else at this site!!
|
|
|
|
|
BrockVnm wrote:
If I am going to start to write a piece of software would you advise to use the UNICODE instead of regular char?
If you are positive that your application is not going to be used in an environment that uses double-byte characters, then using char types and the related strxxx() functions is fine. However, using TCHAR types, and the related _tcsxxx() functions does not cost any extra as the preprocessor resolves them accordingly.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
|
I spotted it just as I hit submit
Buts whats more annoying is that I had gone and tried to fix it once already and typed in the same mistake again!
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
If there's one thing I hate more than making typos in replies is having some moron pointing out the bleedin' obvious.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
In addition to Roger's good summary, you should also wrap any string constants with the _T() macro.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
would you type the _T with any function that you are using that UNICODE variable with. What kind of enviornments would I need UNICODE for....i.e. windows xp, etc. Or is this something that I would use if I was gonna try and use the software on linux, unix, windows, etc???
|
|
|
|
|
BrockVnm wrote:
would you type the _T with any function that you are using that UNICODE variable with.
The _T() macro is for string constants and is only used when _UNICODE is defined. Otherwise it is removed by the preprocessor.
BrockVnm wrote:
What kind of enviornments would I need UNICODE for...
Japanese Kanji or Korean Hangul are two examples.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Ok, they are used if you want to use other languages!!! So if I am not going to support other languages I will be ok. Thanks David!
|
|
|
|
|
BrockVnm wrote:
Ok, they are used if you want to use other languages!!! So if I am not going to support other languages I will be ok.
Of course.
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Is this discussions and tips holds true for Win32 Applications?
|
|
|
|
|
Dear MFC Gurus!
I'm writting SDI-based application that has DialogBar with combobox control. This DialogBar is initialized as the follows:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
if (!m_Bar.Create(this,IDD_BARDLG,CBRS_TOP,ID_MYBARDLG)) {
AfxMessageBox(_T("Failed to create dialog bar!"),MB_ICONSTOP);
return -1;
};
};
where m_Bar is CDialogBar. IDD_BARDLG doesn't have its class derived from CDialog!
How to capture ON_CBN_SELCHANGE message in CMainFrame class from combobox control belonging m_Bar? In other words, I need to track changing the selection of combobox. What should I do?
Yours sincerely,
Alex Bash
|
|
|
|
|
Trap it in your dialog bar. Then, post a command (eg: CMD_CHECK_COMBO ) to the mainframe that causes it (the mainframe) to check the selection of the combo.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
What is "trap"? I'm not sure about terminology...
Yours sincerely,
Alex Bash
|
|
|
|
|
What I meant was write a handler for the CBN_SELCHANGE notification.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I've got a custom control that I am implementing that behaves much like a combo box. When the user clicks the down arrow button, an new window is displayed that presents a Color Selector much like the one in MS Office. I've based the code loosely on articles found here on CodeGuru, with modifications for my specific requirements. Now I've got everything working fine but one that that is causing me trouble is that when the Color selection drop down is shown the control gets a killfocus message. I don't really want a
kill focus message to go out since my control hasn't really lost focus, its just given it to is dropdown window.
Looking at SPY I see that the normal combo box doesn't send out a kill focus when the dropdown is opened so there must be a way to trap the message.
Does anyone know how I can keep my Control from sending a kill focus when the Dropdown window is shown?
My class is derived from CButton.
Thanks
Timothy Bish
tabish[at]twcny.rr.com
timothy.a.bish[at]lmco.com
|
|
|
|
|
tabish121 wrote:
Does anyone know how I can keep my Control from sending a kill focus when the Dropdown window is shown?
I don't think you can prevent this. But your control could just ignore the WM_KILLFOCUS (or at least handle it differently) if the color selector window is being displayed.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
The problem is that the control is being used as an in-place control in a List Ctrl, and when the control looses focus it is destroyed by the list control. I've thought up some hacks to work around this but I just figure that there must be a way to make this behave more like CComboBox, which doesn't send a Kill Focus when the list is opened.
Thanks
Timothy Bish
tabish[at]twcny.rr.com
timothy.a.bish[at]lmco.com
|
|
|
|
|
Is window that is being popped up a child of the CButtonCombo class? If not making it a child may solve your problems.
If it is the child, the CListCtrl OnKillFocus() handler needs to check that the window receiving the focus is not a child window of the combo box. If it is, then is does not destroy the control.
Roger Allen - Sonork 100.10016
Roger Wright: Remember to buckle up, please, and encourage your friends to do the same. It's not just about saving your life, but saving the quality of life for those you may leave behind...
|
|
|
|
|
Yes, the popup window is a child of the Buttom Combo class, which was what I thought would help to avoid the Kill Focus event being sent, but apparently not. I think I've come up with a solution that should work, its not the most elegant, but at least it should solve the problem.
Thanks for the input.
|
|
|
|
|
can any 1 show me how i can read n send chunks of a bufffer at a time?
size = file.tellg();
file.seekg (0, std::ios::beg);
long filesize;
filesize = size;
char sizebuf[50];
ltoa(size,sizebuf,10);
send(newsock,sizebuf,strlen(sizebuf),0);
long sent = 0;
long sizee = filesize/10;
long marker = 0;
long final;
do{
//file.seekg (marker, std::ios::beg);
file.read(buffer + marker,sizee);
//file.get(buffer + marker,sizee);
sent = send(newsock,buffer,sizee,0);
marker = marker + sent;
// }while(final <= filesize);
}while(!strcmp(buffer,"eof"));
thanx
|
|
|
|
|
First, tellg gets the current position, you should move the pointer to the end of the file and then use this to get the file size. Then move the pointer back to the top (which you have done.)
Then determine the size that you want to read (chunk). Then call the read method with the buffer and the number of bytes you want to read.
file.read( buffer + marker, size );
Then mover the marker:
marker += chunk;
Continue doing this until you have read in all the bytes or until the file.eof() is true.
You may also want to surrond this in a try-catch incase there are any problems reading.
Larry J. Siddens
|
|
|
|