• Domingo 19 de Mayo de 2024, 06:34

Autor Tema:  Color En Controles  (Leído 954 veces)

nostromo

  • Miembro MUY activo
  • ***
  • Mensajes: 134
    • Ver Perfil
    • http://win32cpp.cjb.net
Color En Controles
« en: Jueves 9 de Febrero de 2006, 00:52 »
0
Holas;

Estaba programando Cuadros de Diálogos, a los controles Edit y Radio Button,
les cambiaba el background y color de la fuente, ningún problema.

Ahora estaba programando ventanas sin recurrir a recursos, ahora no puedo hacer que se modifique
los colores de los controles, ejemplo;

Código: Text
  1.  
  2. #include <windows.h>
  3.  
  4. /*  Declare Windows procedure  */
  5. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  6. HINSTANCE inst;
  7. /*-----------------------*/
  8. #define CB_OCULTAR  10
  9. #define RB_RADIO_1  11
  10. #define RB_RADIO_2  12
  11. #define BG_GRUPO    13
  12. #define RB_RADIO_3  14
  13. #define RB_RADIO_4  15
  14.  
  15. //-----
  16. #define EstiloRadios    WS_CHILD | WS_VISIBLE |BS_AUTORADIOBUTTON
  17. #define EstiloGrupos    WS_CHILD | WS_VISIBLE | BS_GROUPBOX | WS_GROUP
  18. #define EstiloEdit      WS_CHILD | WS_VISIBLE | WS_BORDER
  19. /*-----------------------*/
  20. char szClassName[ ] = "Ejemplo Controles";
  21. //
  22. int WINAPI WinMain (HINSTANCE hThisInstance,
  23.                     HINSTANCE hPrevInstance,
  24.                     LPSTR lpszArgument,
  25.                     int nFunsterStil)
  26.  
  27. {
  28.     HWND hwnd;
  29.     MSG messages;
  30.     WNDCLASSEX wincl;
  31.  
  32.     /* The Window structure */
  33.     wincl.hInstance = hThisInstance;
  34.     wincl.lpszClassName = szClassName;
  35.     wincl.lpfnWndProc = WindowProcedure;
  36.     wincl.style = CS_DBLCLKS;
  37.     wincl.cbSize = sizeof (WNDCLASSEX);
  38.  
  39.     /* Use default icon and mouse-pointer */
  40.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  41.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  42.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  43.     wincl.lpszMenuName = NULL;
  44.     wincl.cbClsExtra = 0;
  45.     wincl.cbWndExtra = 0;
  46.     /* Use Windows's default color as the background of the window */
  47.     wincl.hbrBackground = (HBRUSH) (COLOR_BTNFACE+1);//COLOR_BACKGROUND;
  48.     /* Register the window class, and if it fails quit the program */
  49.     if (!RegisterClassEx (&wincl))
  50.         return 0;
  51.     /* */
  52.     hwnd = CreateWindowEx (
  53.            0,
  54.            szClassName,
  55.            "Ejemplos Controles",
  56.            WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX,
  57.            CW_USEDEFAULT,
  58.            CW_USEDEFAULT,
  59.            544,
  60.            375,
  61.            HWND_DESKTOP,
  62.            NULL,
  63.            hThisInstance,
  64.            NULL
  65.            );
  66. //
  67.     ShowWindow (hwnd, nFunsterStil);
  68. //
  69.     while (GetMessage (&messages, NULL, 0, 0))
  70.     {
  71.         TranslateMessage(&messages);
  72.         DispatchMessage(&messages);
  73.     }
  74.     return messages.wParam;
  75. }
  76.  
  77. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  78. {
  79.     static HWND hedit,hboton,hradio_1,hradio_2;
  80.     static HWND hgrupo;
  81.     static HWND hradio_3,hradio_4;
  82.     int optar = 11;
  83.     //--- COLOR BACKGROUND CONTROLES
  84.     static HBRUSH RadioBrush;
  85.     static COLORREF BkRadioColor;
  86.     static COLORREF TextoRadio;
  87.     switch (message)
  88.     {
  89.         case WM_CREATE:
  90.             hedit = CreateWindowEx(
  91.                         0,
  92.                         "edit","",
  93.                         EstiloEdit,
  94.                         10,10,80,20,
  95.                         hwnd,NULL,
  96.                         inst,NULL
  97.                         );
  98.             hboton = CreateWindowEx(
  99.                         0,
  100.                         "button","Ocultar",
  101.                         WS_CHILD | WS_VISIBLE,
  102.                         10,40,60,22,
  103.                         hwnd,(HMENU)CB_OCULTAR,
  104.                         inst,NULL
  105.                         );
  106.             hgrupo = CreateWindowEx(
  107.                         0,
  108.                         "button","OPciones",
  109.                         EstiloGrupos, 15,70,150,80,
  110.                         hwnd,(HMENU)BG_GRUPO,
  111.                         inst,NULL
  112.                         );
  113.             hradio_1 = CreateWindowEx(
  114.                         0,
  115.                         "Button","Marcar",
  116.                         EstiloRadios, 30,88,60,20,
  117.                         hwnd,(HMENU)RB_RADIO_1,
  118.                         inst,NULL
  119.                         );
  120.             hradio_2 = CreateWindowEx(
  121.                         0,
  122.                         "button","Marca 2",
  123.                         EstiloRadios, 30,113,70,20,
  124.                         hwnd,(HMENU)RB_RADIO_2,
  125.                         inst,NULL
  126.                         );
  127.             hgrupo = CreateWindowEx(
  128.                         0,
  129.                         "button","Opciones 2",
  130.                         EstiloGrupos, 15,150,150,80,
  131.                         hwnd,(HMENU)BG_GRUPO,
  132.                         inst,NULL
  133.                         );
  134.             hradio_3 = CreateWindowEx(
  135.                         0,
  136.                         "button","Marca 3",
  137.                         EstiloRadios, 30,175,70,20,
  138.                         hwnd,(HMENU)RB_RADIO_3,
  139.                         inst,NULL
  140.                         );
  141.             hradio_4 = CreateWindowEx(
  142.                         WS_EX_TRANSPARENT,
  143.                         "button","Marca 4",
  144.                         EstiloRadios, 30,192,70,20,
  145.                         hwnd,(HMENU)RB_RADIO_4,
  146.                         inst, NULL
  147.                         );
  148.             //---------
  149.             TextoRadio = RGB(0,0,254);
  150.             BkRadioColor = GetSysColor(COLOR_WINDOW);//RGB(225,225,225) GetSysColor(COLOR_BACKGROUND);
  151.             RadioBrush = CreateSolidBrush(BkRadioColor);
  152.             break;
  153.         case WM_CTLCOLORBTN:
  154.             if((HWND)lParam == (HWND)RB_RADIO_4)
  155.             {
  156.                 SetTextColor((HDC)wParam,TextoRadio);
  157.                 SetBkColor((HDC)wParam,BkRadioColor);
  158.                 return (LONG)RadioBrush;
  159.             }
  160.             break;
  161.         case WM_COMMAND:
  162.             switch(LOWORD(wParam))
  163.             {
  164.                 case CB_OCULTAR:
  165.                     SetWindowText(hedit,"Holas");
  166.                     break;
  167.                 case RB_RADIO_1:
  168.                     SetWindowText(hedit,"Radio1");
  169.                     break;
  170.                 case RB_RADIO_2:
  171.                     SetWindowText(hedit,"Radio2");
  172.                     break;
  173.                 case RB_RADIO_3:
  174.                     SetWindowText(hedit,"Radio3");
  175.                     ShowWindow(hboton,FALSE);
  176.                     break;
  177.                 case RB_RADIO_4:
  178.                     SetWindowText(hedit,"Radio4");
  179.                     ShowWindow(hboton,TRUE);
  180.                     break;
  181.             }
  182.             break;
  183.         case WM_DESTROY:
  184.             DeleteObject(RadioBrush);
  185.             PostQuitMessage (0);
  186.             break;
  187.         default:
  188.             return DefWindowProc (hwnd, message, wParam, lParam);
  189.     }
  190.  
  191.     return 0;
  192. }
  193.  
  194.  

Gracias, por cualquier ayuda.