Click here to Skip to main content
15,903,012 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow to solve WASENOBUFS error? Pin
tyr200015-Mar-09 21:05
tyr200015-Mar-09 21:05 
AnswerRe: how to solve WASENOBUFS error? Pin
Hamid_RT15-Mar-09 21:13
Hamid_RT15-Mar-09 21:13 
GeneralRe: how to solve WASENOBUFS error? Pin
tyr200015-Mar-09 21:16
tyr200015-Mar-09 21:16 
GeneralRe: how to solve WASENOBUFS error? Pin
Eytukan15-Mar-09 22:21
Eytukan15-Mar-09 22:21 
GeneralRe: how to solve WASENOBUFS error? Pin
tyr200016-Mar-09 16:58
tyr200016-Mar-09 16:58 
GeneralRe: how to solve WASENOBUFS error? [Added] Pin
Eytukan15-Mar-09 22:23
Eytukan15-Mar-09 22:23 
QuestionPSSM and deferred shading (unfilled shadow) [modified] Pin
akira3215-Mar-09 21:04
akira3215-Mar-09 21:04 
QuestionOffice toolbar item - Generic Pin
ERLN15-Mar-09 20:46
ERLN15-Mar-09 20:46 
Hi !

I have using the following code for creating the toolbar button for office 2000 to office 2003.
It is generic. So I am using this code.
Actually I need 2 buttons in 1 single toolbar. how to do that.
Also Help to how to add the same in file menu item. and also it should work office 2000 to office 2003.

Give a solution for this.
also following code object model is like this commandbars("standard").controls.add (,,,,,)
how to change the code refer like this commandbars(0).controls(2).add.
I have tried to add "Index as property" but no use

STDMETHODIMP CSampleAddin::AddToolBarButton(LPOLESTR lpToolBarName,LPOLESTR lpButtonName,LPOLESTR lpToolTip,LPOLESTR lpTag,long lFaceId,long lBitmapResource)
{
	TCHAR szTest[MAX_PATH]={0};
	// Add a new CommandBar and Button using Automation...
    VARIANT vtCmdBars;    VariantInit(&vtCmdBars);
    VARIANT vtCmdBar;     VariantInit(&vtCmdBar);
    VARIANT vtCtrls;      VariantInit(&vtCtrls);
    VARIANT vtButton;     VariantInit(&vtButton);
    VARIANT vtParam;      VariantInit(&vtParam);
	VARIANT vtButton1;     VariantInit(&vtButton1);
	VARIANT vtExp; VariantInit(&vtExp);
	HRESULT hr = S_FALSE;

	ZeroMemory(szTest,sizeof(szTest));
	hr = GetProperty(m_pParentApp, L"CommandBars", &vtCmdBars);
	if (FAILED(hr)) goto cleanup;

 // Look for our command bar -- this prevents us from making a new one
 // if the old one was never deleted.
    vtParam.vt = VT_BSTR; vtParam.bstrVal = ::SysAllocString(lpToolBarName);
    hr = CallMethod(vtCmdBars.pdispVal, L"Item", &vtCmdBar, 1, &vtParam);
        VariantClear(&vtParam);

 // If we can't find it, make a new bar...
    if (FAILED(hr)) {
        vtParam.vt = VT_BSTR; vtParam.bstrVal = ::SysAllocString(lpToolBarName);
        hr = CallMethod(vtCmdBars.pdispVal, L"Add", &vtCmdBar, 1, &vtParam);
            VariantClear(&vtParam);
        if (FAILED(hr)) goto cleanup;
    }

 // Store a reference...
    m_pOurCmdBar[nCount] = vtCmdBar.pdispVal;
    m_pOurCmdBar[nCount]->AddRef();

    hr = GetProperty(m_pOurCmdBar[nCount], L"Controls", &vtCtrls);
    if (FAILED(hr)) goto cleanup;

 // Grab our button to sink events...
    vtParam.vt = VT_BSTR; vtParam.bstrVal = ::SysAllocString(lpButtonName);
    hr = CallMethod(vtCtrls.pdispVal, L"Item", &vtButton, 1, &vtParam);
        VariantClear(&vtParam);


	_stprintf(szTest,TEXT("Value of hr at button item is (Item):  %X"),hr);
	OutputDebugString(szTest);


 // If we can't find it, make a new button...
    if (FAILED(hr))
	{

        vtParam.vt = VT_I4; vtParam.lVal = 1;
		hr = CallMethod(vtCtrls.pdispVal, L"Add", &vtButton, 1, &vtParam);
        if (FAILED(hr)) goto cleanup;







        vtParam.vt = VT_I4; vtParam.lVal = 3;
        hr = PutProperty(vtButton.pdispVal, L"Style", &vtParam);
        if (FAILED(hr)) goto cleanup;


		
		if(lBitmapResource > 0 )
		{
			HANDLE hBmp = NULL;
			hBmp = (HANDLE)LoadImage(_Module.m_hInst,MAKEINTRESOURCE(lBitmapResource),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS);
			
			
			// put bitmap into Clipboard
			::OpenClipboard(NULL);
			::EmptyClipboard();
			::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
			::CloseClipboard();
			::DeleteObject(hBmp);
			// set style before setting bitmap
			
			hr = CallMethod(vtButton.pdispVal, L"PasteFace", NULL, 0, NULL);
			if (FAILED(hr)) goto cleanup;
		}


		
        vtParam.vt = VT_BSTR; vtParam.bstrVal = ::SysAllocString(lpButtonName);
        hr = PutProperty(vtButton.pdispVal, L"Caption", &vtParam);
            VariantClear(&vtParam);
        if (FAILED(hr)) goto cleanup;


		 vtParam.vt = VT_I4; vtParam.lVal = 100;
        hr = PutProperty(vtButton.pdispVal, L"Width", &vtParam);
        if (FAILED(hr)) goto cleanup;

	
        vtParam.vt = VT_BSTR; vtParam.bstrVal = ::SysAllocString(lpTag);
        hr = PutProperty(vtButton.pdispVal, L"Tag", &vtParam);
            VariantClear(&vtParam);
        if (FAILED(hr)) goto cleanup;



        vtParam.vt = VT_I4; vtParam.lVal = 1;
        hr = PutProperty(vtButton.pdispVal, L"Visible", &vtParam);
        if (FAILED(hr)) goto cleanup;


		if(lFaceId > 0 )
		{
			vtParam.vt = VT_I4; vtParam.lVal = lFaceId;
			hr = PutProperty(vtButton.pdispVal, L"FaceId", &vtParam);
			if (FAILED(hr)) goto cleanup;
		}
		//TooltipText

		//TooltipText

		vtParam.vt = VT_BSTR; vtParam.bstrVal = ::SysAllocString(lpToolTip);
        hr = PutProperty(vtButton.pdispVal, L"TooltipText", &vtParam);
				VariantClear(&vtParam);
        if (FAILED(hr)) goto cleanup;

    }
	else
	{
		
        vtParam.vt = VT_I4; vtParam.lVal = 1;
        hr = PutProperty(vtButton.pdispVal, L"Visible", &vtParam);
        if (FAILED(hr)) goto cleanup;

	}



 // Now, set up an event sink for the Button...
    m_pButtonHandler = new CButtonHandler();
    if (NULL == m_pButtonHandler) goto cleanup;
    m_pButtonHandler->AddRef();
    m_pButtonHandler->SinkEvents(vtButton.pdispVal);

	m_pButtonHandler->m_pParentApp = m_pParentApp;

	
 // Make the CommandBar visible...
	vtParam.vt = VT_I4; 
	vtParam.lVal = 1;
    hr = PutProperty(m_pOurCmdBar[nCount], L"Visible", &vtParam);
    if (FAILED(hr)) goto cleanup;

 // Notify user that we are running (just for fun)...
    CHAR szBuffer[512];
    CHAR szName[256];

    hr = GetProperty(m_pParentApp, L"Name", &vtParam);
    if (FAILED(hr)) goto cleanup;
    
	::WideCharToMultiByte(CP_ACP, 0, vtParam.bstrVal, -1, szName, 256, 0, 0);
    wsprintf(szBuffer, "Hello from a VC COM addin. You are running in %s.", szName);
    //MessageBox(NULL, szBuffer, "My Addin", MB_SETFOREGROUND);

cleanup:
    VariantClear(&vtParam);
	VariantClear(&vtButton);
    VariantClear(&vtCtrls);
    VariantClear(&vtCmdBar);
    VariantClear(&vtCmdBars);
    

	if (nCount > 1)
		nCount = 0;
	else
		nCount++;
	return hr;
}

QuestionPlotting graph in MFC Pin
Febin Elizabeth15-Mar-09 20:14
Febin Elizabeth15-Mar-09 20:14 
AnswerRe: Plotting graph in MFC Pin
Eytukan15-Mar-09 20:19
Eytukan15-Mar-09 20:19 
GeneralRe: Plotting graph in MFC Pin
Febin Elizabeth15-Mar-09 22:42
Febin Elizabeth15-Mar-09 22:42 
GeneralRe: Plotting graph in MFC Pin
Eytukan15-Mar-09 23:13
Eytukan15-Mar-09 23:13 
GeneralRe: Plotting graph in MFC Pin
Cedric Moonen15-Mar-09 23:18
Cedric Moonen15-Mar-09 23:18 
GeneralRe: Plotting graph in MFC Pin
Febin Elizabeth16-Mar-09 18:28
Febin Elizabeth16-Mar-09 18:28 
GeneralRe: Plotting graph in MFC Pin
Cedric Moonen16-Mar-09 21:29
Cedric Moonen16-Mar-09 21:29 
GeneralRe: Plotting graph in MFC Pin
Febin Elizabeth17-Mar-09 4:35
Febin Elizabeth17-Mar-09 4:35 
GeneralRe: Plotting graph in MFC Pin
Cedric Moonen17-Mar-09 4:37
Cedric Moonen17-Mar-09 4:37 
GeneralRe: Plotting graph in MFC Pin
kip_chuko21-Dec-09 16:30
kip_chuko21-Dec-09 16:30 
QuestionUpdate CListCtrl Pin
durban215-Mar-09 20:08
durban215-Mar-09 20:08 
AnswerRe: Update CListCtrl Pin
CPallini15-Mar-09 21:27
mveCPallini15-Mar-09 21:27 
Questionshadow aliasing by using PSSM(one is right,another is error) Pin
akira3215-Mar-09 19:56
akira3215-Mar-09 19:56 
Questionresource script of hindi language Pin
Purish Dwivedi15-Mar-09 19:46
Purish Dwivedi15-Mar-09 19:46 
AnswerRe: resource script of hindi language Pin
Eytukan15-Mar-09 20:15
Eytukan15-Mar-09 20:15 
QuestionRe: resource script of hindi language Pin
Purish Dwivedi15-Mar-09 20:36
Purish Dwivedi15-Mar-09 20:36 
AnswerRe: resource script of hindi language Pin
Hamid_RT15-Mar-09 21:44
Hamid_RT15-Mar-09 21:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.