Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. RegSetValueEx setting a strange value

RegSetValueEx setting a strange value

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    locoone
    wrote on last edited by
    #1

    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 €€€.

    J 1 Reply Last reply
    0
    • L locoone

      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 €€€.

      J Offline
      J Offline
      Johan Pretorius
      wrote on last edited by
      #2

      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?

      L 1 Reply Last reply
      0
      • J Johan Pretorius

        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?

        L Offline
        L Offline
        locoone
        wrote on last edited by
        #3

        that part i can do but when i try to write it to the registry it changes it from numbers to extended char set.

        J 1 Reply Last reply
        0
        • L locoone

          that part i can do but when i try to write it to the registry it changes it from numbers to extended char set.

          J Offline
          J Offline
          Johan Pretorius
          wrote on last edited by
          #4

          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?

          L 1 Reply Last reply
          0
          • J Johan Pretorius

            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?

            L Offline
            L Offline
            locoone
            wrote on last edited by
            #5

            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 ); }

            J 1 Reply Last reply
            0
            • L locoone

              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 ); }

              J Offline
              J Offline
              Johan Pretorius
              wrote on last edited by
              #6

              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?

              L 1 Reply Last reply
              0
              • J Johan Pretorius

                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?

                L Offline
                L Offline
                locoone
                wrote on last edited by
                #7

                thank you that worked.

                J M 3 Replies Last reply
                0
                • L locoone

                  thank you that worked.

                  J Offline
                  J Offline
                  Johan Pretorius
                  wrote on last edited by
                  #8

                  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?

                  1 Reply Last reply
                  0
                  • L locoone

                    thank you that worked.

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    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);

                    1 Reply Last reply
                    0
                    • L locoone

                      thank you that worked.

                      M Offline
                      M Offline
                      Mark Salsbery
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups