Click here to Skip to main content
15,071,729 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,
I'm writing native c programs since 30 years, but now I have the task by my boss to improve the existing programs with a ribbon menu without writing all programs new in c++ or c#.
I was guided perfect by the program "Windows Ribbon Framework in Win32 C Application" from Stephen Wiria from the year 2010 (thanks a lot for this great program!) and all lools very good with one exception:
I'm not able to set the global background color of the ribbon using "UI_PKEY_GlobalBackgroundColor".
I'm abolute not familar with C++ and all my attemps to translate an example c++ code to pure c to set the backgrouind color of a ribbon failed.
Has somebody a short solution for me?
Thank you so much.
Detlef

What I have tried:

HRESULT STDMETHODCALLTYPE OnCreateUICommand(IUIApplication *This, UINT32 commandId, UI_COMMANDTYPE typeID, IUICommandHandler **commandHandler)
{
	HRESULT hr;
	VOID *ppvObj = NULL;
	PROPVARIANT pv;
	
	
	/* allocate pApplication */
	
	// Command-Handler für das Abfragen der Command-Ids
	pCommandHandler = (IUICommandHandler *)GlobalAlloc(GMEM_FIXED, sizeof(IUICommandHandler));
	(IUICommandHandlerVtbl *)pCommandHandler->lpVtbl = &myCommand_Vtbl;
	hr = pCommandHandler->lpVtbl->QueryInterface(pCommandHandler, &IID_IUICommandHandler, (void**)commandHandler);
	


	// Property-Handler
	pPropertyStore = (IPropertyStore *)GlobalAlloc(GMEM_FIXED, sizeof(IPropertyStore));
	
	(IPropertyStoreVtbl*)pPropertyStore->lpVtbl = &myPropertyStore_Vtbl;

	pPropertyStore->lpVtbl->QueryInterface(pPropertyStore, &IID_IUIPropertyHandler, &ppvObj);

		

	UI_HSBCOLOR BackgroundColor = UI_HSB(0xFF, 0xFF, 0x00);
	

	PropVariantInit (&pv);

	pv.vt = VT_UI4;
	pv.lVal = BackgroundColor;
		
	hr = pPropertyStore->lpVtbl->SetValue(pPropertyStore, &UI_PKEY_GlobalBackgroundColor, &pv);
	hr = pPropertyStore->lpVtbl->Commit(pPropertyStore);
	
	
	return hr;

}
Posted
Updated 25-Jan-21 1:55am
v3
Comments
KarstenK 4-Feb-19 13:19pm
   
You should provide the whole error message. Best is that you google for its keywords :-O
Member 13518242 5-Feb-19 6:18am
   
Hi Karsten,

thank you for your replay.
The problem is, that I get no error message, but the background color remains unchanged in its old status.

I think, in c++ it is very easy to change the color and I need a function like this:


CComPtr<ipropertystore> spPropertyStore;

// _spFramework is a pointer to the IUIFramework interface that is assigned
// when the Ribbon is initialized.
if (SUCCEEDED(_spFramework->QueryInterface(&spPropertyStore)))
{
PROPVARIANT propvarBackground;
PROPVARIANT propvarHighlight;
PROPVARIANT propvarText;

// UI_HSBCOLOR is a type defined in UIRibbon.h that is composed of
// three component values: hue, saturation and brightness, respectively.
UI_HSBCOLOR BackgroundColor = UI_HSB(0x14, 0x38, 0x54);
UI_HSBCOLOR HighlightColor = UI_HSB(0x00, 0x36, 0x87);
UI_HSBCOLOR TextColor = UI_HSB(0x2B, 0xD6, 0x00);

InitPropVariantFromUInt32(BackgroundColor, &propvarBackground);
InitPropVariantFromUInt32(HighlightColor, &propvarHighlight);
InitPropVariantFromUInt32(TextColor, &propvarText);

spPropertyStore->SetValue(UI_PKEY_GlobalBackgroundColor, propvarBackground);
spPropertyStore->SetValue(UI_PKEY_GlobalTextColor, propvarText);

spPropertyStore->Commit();
}


But in pure c I can not find a similar function as "InitPropVariantFromUInt32".

May be that this would solve the problem.
Google did not help :-(.

Thank you again and best regards.
Detlef

Not shure if this will help:

https://docs.microsoft.com/de-de/windows/desktop/windowsribbon/windowsribbon-templates
   
v2
Comments
Member 13518242 4-Mar-19 6:02am
   
Thank you merano99. This is helpfull, but still I have the problem to create a PropertyHandler in pure c that works. I tried the solution below, but the backgroundclor vremain unchanged. Nevertheless thank you.
Detlef
IPropertyStoreCache *ppvObj_propertystore = NULL;
PROPVARIANT    pvBackgroundColor;

UI_HSBCOLOR BackgroundColor = UI_HSB(0xFF, 0xFF, 0x54);
HRESULT hr;

hr = CoCreateInstance(&CLSID_InMemoryPropertyStore, NULL, CLSCTX_INPROC_SERVER, &IID_IPropertyStoreCache, (void**)&ppvObj_propertystore);

hr = ppvObj_propertystore->lpVtbl->Release(ppvObj_propertystore);

hr = ppvObj_propertystore->lpVtbl->QueryInterface(ppvObj_propertystore, &IID_IPropertyStoreCache, &ppvObj_propertystore);


	
PropVariantInit (&pvBackgroundColor);
hr = InitPropVariantFromUInt32(BackgroundColor, &pvBackgroundColor);

PropVariantInit(&pvBackgroundColorIn);
hr = InitPropVariantFromUInt32(BackgroundColor, &pvBackgroundColorIn);

hr = ppvObj_propertystore->lpVtbl->GetValue(ppvObj_propertystore, &UI_PKEY_GlobalBackgroundColor, &pvBackgroundColorIn);

PropVariantToUInt32(&pvBackgroundColorIn, &uErgebnis);


hr = ppvObj_propertystore->lpVtbl->SetValue(ppvObj_propertystore,  
        &UI_PKEY_GlobalBackgroundColor, &pvBackgroundColor);
hr = ppvObj_propertystore->lpVtbl->Commit(ppvObj_propertystore);
   
Comments
Member 13518242 25-Mar-19 3:22am
   
In the meantime I found the solution by myself.
May be that someone needs the solution. Here it is:

// Property-Handler
pPropertyStore = (IPropertyStore *) GlobalAlloc(GMEM_FIXED, sizeof(IPropertyStore));

(IPropertyStoreVtbl*)pPropertyStore->lpVtbl = &myPropertyStore_Vtbl;

hr = g_pFramework->lpVtbl->QueryInterface(g_pFramework, &IID_IPropertyStore, &pPropertyStore);


InitPropVariantFromUInt32(BackgroundColor, &pvBackgroundColor);
InitPropVariantFromUInt32(TextColor, &pvTextColor);


hr = pPropertyStore->lpVtbl->SetValue(pPropertyStore, &UI_PKEY_GlobalBackgroundColor, &pvBackgroundColor);
hr = pPropertyStore->lpVtbl->SetValue(pPropertyStore, &UI_PKEY_GlobalTextColor, &pvTextColor);


hr = pPropertyStore->lpVtbl->Commit(pPropertyStore);
hr = pPropertyStore->lpVtbl->Release(pPropertyStore);
Member 14340223 25-Jan-21 9:09am
   
Hi thank you for your input, I would like to know how did you implement the commandhandler I have a problem with that

best regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900