RegSetValueEx setting a strange value
-
im using a CColorDialog to get the numbers of a color but i cant figure out how to set it as a number it keeps setting it as €€€ the return of CColorDialog is formatted as 128128128 i need it as 128 128 128 i can get it that far i just cant figure out how to write it without it changing to €€€.
-
im using a CColorDialog to get the numbers of a color but i cant figure out how to set it as a number it keeps setting it as €€€ the return of CColorDialog is formatted as 128128128 i need it as 128 128 128 i can get it that far i just cant figure out how to write it without it changing to €€€.
COLORREF temp = RGB(20,155,10); int red = (temp & 0x0000ff); int green = ((temp >> 8) & 0x0000ff); int blue = temp >> 16; char str[100]; sprintf(str,"red %i green %i blue %i",red,green,blue);
output : red 20 green 155 blue 10 Hope this helps :)
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
COLORREF temp = RGB(20,155,10); int red = (temp & 0x0000ff); int green = ((temp >> 8) & 0x0000ff); int blue = temp >> 16; char str[100]; sprintf(str,"red %i green %i blue %i",red,green,blue);
output : red 20 green 155 blue 10 Hope this helps :)
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
that part i can do but when i try to write it to the registry it changes it from numbers to extended char set.
save it as a string in the registry sprintf(thestring,"%i %i %i",iRed,iGreen,iBlue) will format the stirng -> 155 155 155 then you dont have to warry about extended chars?
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
save it as a string in the registry sprintf(thestring,"%i %i %i",iRed,iGreen,iBlue) will format the stirng -> 155 155 155 then you dont have to warry about extended chars?
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I?thats what im trying to do RegSetValueEx(hKey, "Background", 0, REG_SZ, (const unsigned char *)"0 78 152", dwvalue); that works fine but when i get the color from the dialog is when it kicks me in the head
COLORREF color; CString c; DWORD r, g, b; if (m_check3.GetCheck() == 1) { CColorDialog dlg; if(dlg.DoModal()== IDOK) { color = dlg.GetColor(); r = GetRValue(color); g = GetGValue(color); b = GetBValue(color); } c.Format("%d %d %d", r, g, b); hKey = HKEY_USERS; path = ".DEFAULT\\Control Panel\\Colors"; DWORD value = color; MessageBox(c); DWORD dwvalue = sizeof(DWORD); RegOpenKeyEx(hKey, path, 0, KEY_ALL_ACCESS, &hKey); RegSetValueEx( hKey, "Background", 0, REG_SZ, (const unsigned char *)&value, <--- here dwvalue ); }
-
thats what im trying to do RegSetValueEx(hKey, "Background", 0, REG_SZ, (const unsigned char *)"0 78 152", dwvalue); that works fine but when i get the color from the dialog is when it kicks me in the head
COLORREF color; CString c; DWORD r, g, b; if (m_check3.GetCheck() == 1) { CColorDialog dlg; if(dlg.DoModal()== IDOK) { color = dlg.GetColor(); r = GetRValue(color); g = GetGValue(color); b = GetBValue(color); } c.Format("%d %d %d", r, g, b); hKey = HKEY_USERS; path = ".DEFAULT\\Control Panel\\Colors"; DWORD value = color; MessageBox(c); DWORD dwvalue = sizeof(DWORD); RegOpenKeyEx(hKey, path, 0, KEY_ALL_ACCESS, &hKey); RegSetValueEx( hKey, "Background", 0, REG_SZ, (const unsigned char *)&value, <--- here dwvalue ); }
CString c; DWORD r, g, b; CColorDialog dlg; COLORREF color; if(dlg.DoModal()== IDOK) { color = dlg.GetColor(); r = GetRValue(color); g = GetGValue(color); b = GetBValue(color); } c.Format("%d %d %d", r, g, b); MessageBox(c); HKEY hKey = HKEY_USERS; CString path = ".DEFAULT\\Control Panel\\Colors"; DWORD value = color; DWORD dwvalue = sizeof(unsigned char) * c.GetLength(); RegOpenKeyEx(hKey, path.GetBuffer(0), 0, KEY_ALL_ACCESS, &hKey); RegSetValueEx( hKey, "Background", 0, REG_SZ, (const unsigned char *)c.GetBuffer(0), dwvalue );
The code on top will work. the problem is that you are sending in a DWORD as a string.
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
CString c; DWORD r, g, b; CColorDialog dlg; COLORREF color; if(dlg.DoModal()== IDOK) { color = dlg.GetColor(); r = GetRValue(color); g = GetGValue(color); b = GetBValue(color); } c.Format("%d %d %d", r, g, b); MessageBox(c); HKEY hKey = HKEY_USERS; CString path = ".DEFAULT\\Control Panel\\Colors"; DWORD value = color; DWORD dwvalue = sizeof(unsigned char) * c.GetLength(); RegOpenKeyEx(hKey, path.GetBuffer(0), 0, KEY_ALL_ACCESS, &hKey); RegSetValueEx( hKey, "Background", 0, REG_SZ, (const unsigned char *)c.GetBuffer(0), dwvalue );
The code on top will work. the problem is that you are sending in a DWORD as a string.
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
My pleasure.
Artificial Intelligence is no match for Natural Stupidity
No one can understand the truth until he drinks of coffee's frothy goodness. ~Sheik Abd-al-Kadir
I can't always be wrong ... or can I? -
You should save the null terminator too (according to the docs) DWORD dwvalue = sizeof(unsigned char) * c.GetLength(); should be DWORD dwvalue = sizeof(unsigned char) * (c.GetLength() + 1);
-
Here's a tip, for what it's worth. With CString objects, unless you need to change the buffer directly, it's safer to use the const accessor methods (the LPCSTR cast or the GetString() method. CString::GetBuffer() is over-used (when not necessary) IMO :) (const unsigned char *)c.GetString(), instead of (const unsigned char *)c.GetBuffer(0), Mark