|
I'm using STL, not MFC. I would like to store the Month names in an enum or something and easily be able to pass in 3 and have returned "March" or pass in 11 and have returned "November"
|
|
|
|
|
inline std::string GetMonthFromInt(int iMonth) {
static std::string sMonths[] = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
if ((iMonth >= 1) && (iMonth <= 12)) {
return sMonths[iMonth - 1];
} else {
throw "Bad month number";
}
}
or if you don't want the overhead of copying strings:
inline const std::string& GetMonthFromInt(int iMonth) {
static std::string sMonths[] = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
if ((iMonth >= 1) && (iMonth <= 12)) {
return sMonths[iMonth - 1];
} else {
throw "Bad month number";
}
}
Michel
It is a lovely language, but it takes a very long time to say anything in it, because we do not say anything in it, unless it is worth taking a very long time to say, and to listen to.
- TreeBeard
|
|
|
|
|
Call GetLocaleInfo() and query for LOCALE_SMONTHNAME1 thru LOCALE_SMONTHNAME12. This way the string gets automagically localized on all languages.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
You are a well full of knowledge when it comes to localization!!!
How many projects have you created with localization, and do you do this for every project that you create?
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
When I worked at Symantec, everything we wrote had to be localizable. Mostly that meant making the code DBCS-enabled, and having all strings that the user might see in the string table. I've only needed GetLocaleInfo() once - I did a scheduling wizard and used it to show the names of the days of the week.
As for my present work, I automatically write DBCS-ready code out of habit.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Michael Dunn wrote:
I automatically write DBCS-ready code out of habit
That is how I write code as well. Although I have never had to use the GetLocaleInfo functions or anything to that effect. It is something that I am interested in learning because not many people I know, know how to use those functions, or even know that they exist. So it would increase my value as a developer for international software.
However, I really find that stuff dull and would rather learn 3D computer graphics or something like that
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Some sample code for Derek who asked in email
TCHAR szMonth[128];
GetLocaleInfo ( LOCALE_USER_DEFAULT, LOCALE_SMONTHNAME1, szMonth, 128 );
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
my app want to modiy clipboard that the other app already open it.
What's could I do ?
How is it ?
Thank you so much
|
|
|
|
|
An application cannot modify the clipboard if another application has it open already.
The clipboard owner must close the clipboard, then another application could open, modify, and close it, then the original owner could open it again with the modifications in place.
|
|
|
|
|
How do most people do their program in Doc/View?
I find it weird that Doc/View have been used in such a way in filezilla, a GPL ftp client and server.
http://sourceforge.net/projects/filezilla/
Such that the view have access to the window itself and encapsulation have been broken.
Is it a common and easier way to do things this way?
From what i have read in books, we should have accessor methods to access the private members in the Document class, and the view class should use these accessor methods.
Perhaps in this example, filezilla does not really have a "document" thus his use of direct access to the window to c
What do you guys think of this progam?
And how should Doc/View be used in programs like this?
Leaning newbie
Give a man a fish and he eats today. Teach a man to fish and he can feed himself for the rest of his life
|
|
|
|
|
Someone recommended that I use the CFileFind class to check the contents of a folder. I tried it and it works great only it check the contents of the folder that my program was in. I can't seem to check the contents of any other folders. How can I accomplish this?
-Raffi
Why do today what can be put of until tommorrow?
|
|
|
|
|
GREETINGS!
virtual BOOL FindFile( LPCTSTR pstrName = NULL, DWORD dwUnused = 0 );
Specify full path in pstrName:
CFileFind hFile;
hFile.FindFile("C:\\Windows\\*.dll",0)
Than use hFile.FindNextFile();
Good luck!
LOVE & PEACE to everyone
|
|
|
|
|
Look for the example in MSDN for FindNextFile .
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
Hi,
I need to be able to show and hide bitmaps in a dialog dynamically. Basically, I want to use the bitmaps to make a card game, but I need to be able to specify their (the cards) locations. I need to be able to do something of the following (yes, I know the following code wont do anything):
ShowBitmapXYZ(0,0);
Or something along those lines.
Thanks,
~ Selevercin
If you have a problem with my spelling, just remember that's not my fault. I [as well as everyone
else who learned to spell after 1976] blame it on
Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
Draw your bitmap in a static control, use SetBitmap(), ShowWindow() and MoveWindow() to control which bitmap where
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
What does SetBitmap() do? Also, how can I display multiple copies of the same bitmap?
Thanks,
~ Selevercin
If you have a problem with my spelling, just remember that's not my fault. I [as well as everyone
else who learned to spell after 1976] blame it on
Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
Selevercin wrote:
What does SetBitmap() do?
From MSDN:
CStatic::SetBitmap
HBITMAP SetBitmap( HBITMAP hBitmap );
Return Value
The handle of the bitmap previously associated with the static control, or NULL if no bitmap was associated with the static control.
Parameters
hBitmap
Handle of the bitmap to be drawn in the static control.
Remarks
Call this member function to associate a new bitmap with the static control.
The bitmap will be automatically drawn in the static control. By default, it will be drawn in the upper-left corner and the static control will be resized to the size of the bitmap.
You can use various window and static control styles, including the following:
SS_BITMAP Use this style always for bitmaps.
SS_CENTERIMAGE Use to center in the static control. If the image is larger than the static control, it will be clipped. If it is smaller than the static control, the empty space around the image will be filled by the color of the pixel in the upper left corner of the bitmap.
Selevercin wrote:
how can I display multiple copies of the same bitmap?
Use multiple static controls
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
Ok, my program is crashing on the code. This is what I have:
<code>
CStatic card;
HBITMAP hBitmap;
hBitmap = ::LoadBitmap(NULL, MAKEINTRESOURCE(IDB_2));
card.SetBitmap(hBitmap);
card.ShowWindow(SW_SHOW);
card.MoveWindow(100, 100, 23, 35, TRUE);
I know it is the SetBitmap() that is causing it, but what did I do wrong?
Thanks,
~ Selevercin
If you have a problem with my spelling, just remember that's not my fault. I [as well as everyone
else who learned to spell after 1976] blame it on
Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
CStatic card;
card.Create(_T(""), SS_BITMAP, CRect (0,0,0,0), this, An_ID_That_Makes_Sense);
...
You have to create the window before you can SetBitmap() etc.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
Within you lies the power for good - Use it!
|
|
|
|
|
Ok, hopefully this is it. For some reason it is not showing it.
<code>
CStatic card;
HBITMAP hBitmap;
card.Create(_T(""), WS_CHILD | WS_VISIBLE | SS_BITMAP, CRect(23,35,100,100), this, 101);
hBitmap = ::LoadBitmap(NULL, MAKEINTRESOURCE(IDB_2));
card.SetBitmap(hBitmap);
card.ShowWindow(SW_SHOW);
card.MoveWindow(100, 100, 23, 35, TRUE);
Thanks,
~ Selevercin
If you have a problem with my spelling, just remember that's not my fault. I [as well as everyone
else who learned to spell after 1976] blame it on
Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
I have just made a function that adds all the files from a folder and it's subfolders to a list, but whenever it gets to a filename with a foreign character in it (æøåöä etc.) it fails and the filename gets set to three random characters and a null. How can i add support for foreign characters?
Tkanks!
|
|
|
|
|
Perhaps if you explained a little bit more in specific how you got the names it would be possible to answer? Maybe also how and exactly where (in what API) you function fails.
I know for sure that the Win32 API function family FindFirstFile & co. works as expected even with Swedish characters, why I obviously question your bad results re. e.g. "å".
|
|
|
|
|
Here's the function:
void AddFilesFromFolder(ITEMIDLIST *pIdl)
{
if (pIdl)
{
IShellFolder *pBrowse = NULL;
LPENUMIDLIST pFolder = NULL;
LPMALLOC pMalloc = NULL;
ITEMIDLIST *pNewId = NULL;
ITEMIDLIST *pFullId;
STRRET strDispName;
STRRET strPrev;
LVITEM lvItem;
char szFolderPath[MAX_PATH+1];
DWORD pActual = 0;
DWORD dwAttrib;
IShellFolder *CurrentFolder;
if (SHGetDesktopFolder(&CurrentFolder) == NOERROR)
{
SHGetMalloc(&pMalloc);
CurrentFolder->BindToObject(pIdl, NULL, IID_IShellFolder, (LPVOID*)&pBrowse);
pBrowse->GetDisplayNameOf(pIdl, SHGDN_INFOLDER, &strDispName);
if (pBrowse->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &pFolder) == NOERROR)
{
SHGetPathFromIDList(pIdl, szFolderPath);
pMalloc->Alloc((unsigned long)pNewId);
lvItem.mask = LVIF_IMAGE | LVIF_TEXT;
while (pFolder->Next(1, &pNewId, &pActual) != S_FALSE)
{
dwAttrib = SFGAO_FOLDER;
pBrowse->GetAttributesOf(1, (LPCITEMIDLIST*)&pNewId, &dwAttrib);
if (!(dwAttrib & SFGAO_FOLDER))
{
memset(strDispName.cStr, 0, MAX_PATH+1);
pBrowse->GetDisplayNameOf(pNewId, SHGDN_INFOLDER, &strDispName);
PathCombine(gszPath, szFolderPath, strDispName.cStr);
if (strDispName.cStr[3] == '\0')
{
showstr(gszPath, &gszMsgBuff[strlen(gszMsgBuff)], 120);
gszMsgBuff[strlen(gszMsgBuff)] = 13;
gszMsgBuff[strlen(gszMsgBuff)] = 10;
}
if (FindHeader() != -1)
{
GetID3();
FillInfo();
ListAddItem();
}
pBrowse->GetDisplayNameOf(pNewId, SHGDN_INFOLDER, &strPrev);
}
if (dwAttrib & SFGAO_FOLDER)
{
UINT cb1 = GetSize(pIdl) - sizeof(pIdl->mkid.cb);
UINT cb2 = GetSize(pNewId);
pFullId = (LPITEMIDLIST)pMalloc->Alloc(cb1 + cb2);
if (pFullId)
{
CopyMemory(pFullId, pIdl, cb1);
CopyMemory(((LPSTR)pFullId) + cb1, pNewId, cb2);
AddFilesFromFolder(pFullId);
}
}
}
pMalloc->Free(pNewId);
pMalloc->Release();
gbFileOpen = true;
pFolder->Release();
}
CurrentFolder->Release();
}
}
}
I got the initial PIDL from the SHBrowseForFolder function.
|
|
|
|
|
Without event looking at or trying to understand this code, why in the [warm place] would anyone ever want to write this amount of code just to iterate a directory tree?! This looks like "MS Malicious" at best.
If you are only handling filesystems, use FindFirstFile & co. It's much cleaner and probably an order of magnitude faster (I could be wrong, but in this case it seems unlikely). Let me know if you want some example code.
|
|
|
|
|
Is it possible to add all the files in a folder + the filess in the folder's subfolders etc. without that much code? in that case i would very much like some sample code.
|
|
|
|
|