| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
Felip Master

Registrado: 09 Jun 2004Mensajes: 200
|
Publicado: Mie 08 Jun, 2022 8:51 pm Asunto: Obtener el color de una celda de un TStringGrid |
|
|
Quiero capturar el color de una celda de un TStringGrid que fue coloreado por el evento OnDrawCell.
Obtuve un código en Internet, pero solo devuelve clBlack:
| Código: | void __fastcall TForm1::StringGrid1DblClick(TObject *Sender)
{
TColor CurrCellColor;
int CurrCol, CurrRow;
// Save typing by grabbing the currently selected cell col/row
CurrCol = StringGrid1->Col;
CurrRow = StringGrid1->Row;
// Get the stored color for the selected cell
CurrCellColor = TColor(StringGrid1->Objects[CurrCol][ CurrRow]);
ShowMessage( ColorToString(CurrCellColor));
} |
Gracias |
|
| Volver arriba |
|
 |
escafandra Master

Registrado: 29 Nov 2007Mensajes: 625Ubicación: Madrid - España
|
Publicado: Mie 08 Jun, 2022 10:48 pm Asunto: |
|
|
Ese código no puede funcionar pues StringGrid1->Objects[CurrCol][ CurrRow] es un puntero a TObject y no un color
Prueba de esta manera
| Código: |
void __fastcall TForm1::StringGrid1DblClick(TObject *Sender)
{
TPoint P;
GetCursorPos(&P);
HWND hWnd = WindowFromPoint(P);
::ScreenToClient(hWnd, &P);
HDC DC = GetDC(hWnd);
COLORREF Color = GetPixel(DC, P.x, P.y);
ReleaseDC(hWnd, DC);
ShowMessage(ColorToString(Color));
}
|
Saludos. |
|
| Volver arriba |
|
 |
Felip Master

Registrado: 09 Jun 2004Mensajes: 200
|
Publicado: Mie 08 Jun, 2022 11:53 pm Asunto: |
|
|
¡Perfecto! ¡Muchas gracias! |
|
| Volver arriba |
|
 |
|