Jump to content
  • Advertisement
Sign in to follow this  
Skute

Adding strings to toolbar buttons from a string table?

This topic is 4972 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, im having trouble trying to set button text on my toolbar from a string table in the resources. im using the following code but the ID of the string thats been added is always -1:
  iStringID[0] = SendMessage(m_hToolBar, TB_ADDSTRING, reinterpret_cast<WPARAM>(m_hInstance), static_cast<WPARAM>(MAKELONG(IDS_NEW, 0)));
  iStringID[1] = SendMessage(m_hToolBar, TB_ADDSTRING, reinterpret_cast<WPARAM>(m_hInstance), static_cast<WPARAM>(MAKELONG(IDS_OPEN, 0)));
  iStringID[2] = SendMessage(m_hToolBar, TB_ADDSTRING, reinterpret_cast<WPARAM>(m_hInstance), static_cast<WPARAM>(MAKELONG(IDS_SAVE, 0)));

	ZeroMemory(tbb, sizeof(tbb));
	tbb[0].iBitmap   = STD_FILENEW;
	tbb[0].fsState   = TBSTATE_ENABLED;
	tbb[0].fsStyle   = TBSTYLE_BUTTON;
	tbb[0].idCommand = ID_FILE_NEW;
  tbb[0].iString   = iStringID[0];

	tbb[1].iBitmap   = STD_FILEOPEN;
	tbb[1].fsState   = TBSTATE_ENABLED;
	tbb[1].fsStyle   = TBSTYLE_BUTTON;
	tbb[1].idCommand = ID_FILE_OPEN;
  tbb[0].iString   = iStringID[1];

	tbb[2].iBitmap   = STD_FILESAVE;
	tbb[2].fsState   = TBSTATE_ENABLED;
	tbb[2].fsStyle   = TBSTYLE_BUTTON;
	tbb[2].idCommand = ID_FILE_SAVEAS;
  tbb[0].iString   = iStringID[2];

I also tried the following, but this didnt work either:
iStringID[0] = SendMessage(m_hToolBar, TB_ADDSTRING, reinterpret_cast<WPARAM>(m_hInstance), reinterpret_cast<WPARAM>(MAKEINTRESOURCE(IDS_NEW)));
  iStringID[1] = SendMessage(m_hToolBar, TB_ADDSTRING, reinterpret_cast<WPARAM>(m_hInstance), reinterpret_cast<WPARAM>(MAKEINTRESOURCE(IDS_OPEN)));
  iStringID[2] = SendMessage(m_hToolBar, TB_ADDSTRING, reinterpret_cast<WPARAM>(m_hInstance), reinterpret_cast<WPARAM>(MAKEINTRESOURCE(IDS_SAVE)));

	ZeroMemory(tbb, sizeof(tbb));
	tbb[0].iBitmap   = STD_FILENEW;
	tbb[0].fsState   = TBSTATE_ENABLED;
	tbb[0].fsStyle   = TBSTYLE_BUTTON;
	tbb[0].idCommand = ID_FILE_NEW;
  tbb[0].iString   = iStringID[0];

	tbb[1].iBitmap   = STD_FILEOPEN;
	tbb[1].fsState   = TBSTATE_ENABLED;
	tbb[1].fsStyle   = TBSTYLE_BUTTON;
	tbb[1].idCommand = ID_FILE_OPEN;
  tbb[0].iString   = iStringID[1];

	tbb[2].iBitmap   = STD_FILESAVE;
	tbb[2].fsState   = TBSTATE_ENABLED;
	tbb[2].fsStyle   = TBSTYLE_BUTTON;
	tbb[2].idCommand = ID_FILE_SAVEAS;
  tbb[0].iString   = iStringID[2];

Any help is much appreciated. PS. How can i compile multiple language tables into 1 exe? ie, i want to have a string table for english, german, french etc, but i dont want to compile and exe separately for each language? Cheers

Share this post


Link to post
Share on other sites
Advertisement
I can't help with the toolbar, but about the string tables:

When you've created one string table in your project you can right click it and choose "add copy". A popup dialog will appear asking for the language id of the copy.

After that point you have two (or more) string tables. If you're using LoadString it will automagically choose the best fit. If you want to change language programmatically you're screwed as there is no such function.

In that case you can load the strings yourself:


std::string CWinUtils::LoadStringEx( DWORD dwResourceId, WORD wLanguage )
{

std::string strTemp( "" );

int nBlock = dwResourceId / 16 + 1;
int nNum = dwResourceId & 0x0f;

HRSRC hRes = FindResourceEx( GetModuleHandle( NULL ), RT_STRING, MAKEINTRESOURCE( nBlock ), wLanguage );

if ( hRes == NULL )
{
return "";
}

HGLOBAL hGlobal = LoadResource( GetModuleHandle( NULL ), hRes );
if ( hGlobal == NULL )
{
return "";
}

WCHAR* pData = (WCHAR*)LockResource( hGlobal );

WORD wStringLength = 0;
if ( pData )
{

for ( int i = 0; i < nNum; ++i )
{
wStringLength = (WORD)*pData;

pData += 1 + wStringLength;
}
wStringLength = (WORD)*pData;
++pData;

char* pTemp = new char[wStringLength + 1];

WideCharToMultiByte( CP_ACP, 0, (WCHAR*)pData, wStringLength, pTemp, wStringLength, 0, 0 );

pTemp[wStringLength] = 0;

strTemp = pTemp;

delete[] pTemp;
}

UnlockResource( hGlobal );
FreeResource( hGlobal );

return strTemp;

}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!