After trying and error for many times, I decided to ask here. My objective is I wanted to change the feature of my IE toolbar button. The button is firstly setup by IE at IE startup using the function CRebarHandler::onSetRedraw
and CRebarHandler::setButtonMenu2()
.
And then, I create a call from another cpp file, to call CRebarHandler::setButtonMenu2()
. I intent to change just the button's image. I assigned the ID of the image correctly. But somehow it does not work. When I put other code inside this function,like a code for writing to file, it is proven work. Means, it is properly being called from the other file.
But the thing is, the code for the button inside CRebarHandler::setButtonMenu2()
seems does not work. Need help.
Here is the code I am working on (I modify John Lister's button code):
LRESULT CRebarHandler::onSetRedraw(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){
bHandled=false;
if (m_ieVer==6){
if (!m_hWndToolbar)
scanForToolbarSlow();
if (m_hWndToolbar){
findButton(m_hWndToolbar);
if (m_buttonID>0)
setButtonMenu();
}
}
return S_OK;
}
void CRebarHandler::setButtonMenu(){
HIMAGELIST hImageList = ImageList_Create(32, 32,ILC_COLOR16 | ILC_MASK,1, 0);
HINSTANCE module = _AtlBaseModule.GetResourceInstance();
TBBUTTONINFO inf;
inf.cbSize=sizeof(inf);
inf.dwMask = TBIF_IMAGE;
char psBuffer[128];
FILE *pPipe;
float f = 0;
pPipe = _popen("javaw -jar c:\\simmetrics.jar c:\\chtml.txt c:\\thtml.txt", "rt" );
char* p = fgets(psBuffer, 128, pPipe);
std::istringstream iss(p);
iss >> f;
if (f > 0.9)
{
inf.iImage = 1;
SendMessage(m_hWndToolbar, TB_SETBUTTONINFO, m_buttonID, (LPARAM)(&inf));
iss.clear();
f = 0;
}
else
{
inf.iImage = 2;
SendMessage(m_hWndToolbar, TB_SETBUTTONINFO, m_buttonID, (LPARAM)(&inf));
iss.clear();
f = 0;
}
iss.clear();
f = 0;
}
void CRebarHandler::setButtonMenu2(){
TBBUTTONINFO inf;
inf.cbSize=sizeof(inf);
inf.dwMask = TBIF_IMAGE;
inf.iImage = 1; //green
SendMessage(NULL, TB_SETBUTTONINFO, m_buttonID, (LPARAM)(&inf));
}