| |

VerySource

 Forgot password?
 Register
Search
View: 1136|Reply: 10

Has anyone used MfcGridCtrl, if you want to use different colors for different characters in a cell, is there any way?

[Copy link]

2

Threads

18

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-2-14 22:00:02
| Show all posts |Read mode
MfcGridCtrl is said to be the best grid
Reply

Use magic Report

0

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-6-14 13:45:01
| Show all posts
To achieve your requirements, you must modify the setting text function in gridctrl
An additional parameter must be added to pass the font color you want in the past. It is estimated that it will be more troublesome to modify
You must be familiar with gridctrl class
Reply

Use magic Report

0

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-8-4 14:45:02
| Show all posts
I think it is really troublesome to modify
The GridCtrl class itself is very cumbersome. To realize the function you mentioned, it is not clear in a sentence or two.
So everyone can't answer
I think it’s better to write a CWnd to draw a grid and fill CRichEdit in each cell
You can download this MultilineListControl on codeproject to see
Reply

Use magic Report

2

Threads

18

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

 Author| Post time: 2020-8-5 14:45:01
| Show all posts
Upstairs is right, but filling RichEdit in each cell takes up resources.
Let me see what you said MultilineListControl
Reply

Use magic Report

2

Threads

18

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-8-6 09:15:01
| Show all posts
he is right.

Why don't you redraw on the basis of listctrl?
That's low resources.
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-6 23:15:01
| Show all posts
BOOL CGridCellBase::Draw(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBkgnd /*=TRUE*/)
{
.....
  //pDC->SetTextColor(); modify the color of the character, add your code here
   DrawText(pDC->m_hDC, GetText(), -1, rect, GetFormat() | DT_NOPREFIX);//Text output

    pDC->RestoreDC(nSavedDC);

    return TRUE;
}
Reply

Use magic Report

2

Threads

18

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

 Author| Post time: 2020-8-7 10:45:01
| Show all posts
The upstairs seems to have used the MFCGridCtrl control, but your method just changed the font color of the entire Cell.
I want to use different colors for different characters in a cell (multi-line display) (for example, the searched characters use red).
Reply

Use magic Report

2

Threads

18

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

 Author| Post time: 2020-8-7 22:45:01
| Show all posts
I spy a program written by others (implement the function I said), can the experts see how others do it?

<02381> 00100458 S WM_COMMAND wNotifyCode:BN_CLICKED wID:2026 hwndCtl:000D0558 [wParam:000007EA lParam:000D0558]
<02382> 000A05C2 S .WM_VSCROLL nScrollCode:SB_PAGEDOWN hwndScrollBar:(null) [wParam:00000003 lParam:00000000]
<02383> 000D0558 S ..WM_KILLFOCUS hwndGetFocus:000A05C2 [wParam:000A05C2 lParam:00000000]
<02384> 00100458 S ...WM_CTLCOLORBTN hdcButton:01010FA1 hwndButton:000D0558 [wParam:01010FA1 lParam:000D0558]
<02385> 00100458 R ...WM_CTLCOLORBTN hBrush:0110005A [lResult:0110005A]
<02386> 00100458 S ...WM_DRAWITEM idCtl:2026 lpdis:0012EF64 [wParam:000007EA lParam:0012EF64]
<02387> 00100458 R ...WM_DRAWITEM fProcessed:True [lResult:00000001]
<02388> 000D0558 R ..WM_KILLFOCUS lResult:00000000
<02389> 000E0514 S ..message:0x0287 [Unknown] wParam:00000018 lParam:000D0558
<02390> 000D0558 S ...WM_IME_SETCONTEXT fSet:0 (LONG)iShow:C000000F [wParam:00000000 lParam:C000000F]
<02391> 000E0514 S ....WM_IME_SETCONTEXT fSet:0 (LONG)iShow:C000000F [wParam:00000000 lParam:C000000F]
<02392> 000E050C S .....WM_IME_SETCONTEXT fSet:0 (LONG)iShow:C000000F [wParam:00000000 lParam:C000000F]
<02393> 000E050C R .....WM_IME_SETCONTEXT lResult:00000000
<02394> 000E0514 R ....WM_IME_SETCONTEXT lResult:00000000
<02395> 000D0558 R ...WM_IME_SETCONTEXT lResult:00000000
<02396> 000E0514 R ..message:0x0287 [Unknown] lResult:00000000
<02397> 000E0514 S ..message:0x0287 [Unknown] wParam:00000017 lParam:000A05C2
<02398> 000A05C2 S ...WM_IME_SETCONTEXT fSet:1 (LONG)iShow:C000000F [wParam:00000001 lParam:C000000F]
<02399> 000E0514 S ....WM_IME_SETCONTEXT fSet:1 (LONG)iShow:C000000F [wParam:00000001 lParam:C000000F]
<02400> 000E050C S .....WM_IME_SETCONTEXT fSet:1 (LONG)iShow:C000000F [wParam:00000001 lParam:C000000F]
<02401> 000E050C R .....WM_IME_SETCONTEXT lResult:00000000
<02402> 000E0514 R ....WM_IME_SETCONTEXT lResult:00000000
<02403> 000A05C2 R ...WM_IME_SETCONTEXT lResult:00000000
<02404> 000E0514 R ..message:0x0287 [Unknown] lResult:00000000
<02405> 000A05C2 S ..WM_SETFOCUS hwndLoseFocus:000D0558 [wParam:000D0558 lParam:00000000]
<02406> 000A05C2 R ..WM_SETFOCUS lResult:00000000
<02407> 000A05C2 R .WM_VSCROLL lResult:00000000
<02408> 00100458 R WM_COMMAND lResult:00000001
<02409> 000E050C P message:0xC16A [Registered:"MSPY Private"] wParam:00000119 lParam:00000000 time:7:40:22.875 point:(824, 416)
<02410> 000E050C P message:0xC16A [Registered:"MSPY Private"] wParam:00000105 lParam:00000000 time:7:40:22.875 point:(824, 416)
<02411> 000E050C P message:0xC16A [Registered:"MSPY Private"] wParam:00000131 lParam:001A051B time:7:40:22.875 point:(824, 416)
<02412> 000E050C P message:0xC16A [Registered:"MSPY Private"] wParam:00000119 lParam:00000000 time:7:40:22.875 point:(824, 416)
<02413> 000E050C P message:0xC16A [Registered:"MSPY Private"] wParam:00000105 lParam:00000000 time:7:40:22.875 point:(824, 416)
<02414> 000F05DA P message:0xC0B4 [Registered:"MSUIM.Msg.MuiMgrDirtyUpdate"] wParam:00000000 lParam:00000000 time:7:40:22.875 point:(824, 416)
<02415> 000D0558 S WM_NCHITTEST xPos:824 yPos:416 [wParam:00000000 lParam:01A00338]
<02416> 000D0558 R WM_NCHITTEST nHittest:HTCLIENT [lResult:00000001]
<02417> 000D0558 S WM_NCHITTEST xPos:824 yPos:416 [wParam:00000000 lParam:01A00338]
<02418> 000D0558 R WM_NCHITTEST nHittest:HTCLIENT [lResult:00000001]
<02419> 000D0558 S WM_SETCURSOR hwnd:000D0558 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE [wParam:000D0558 lParam:02000001]
<02420> 00100458 S .WM_SETCURSOR hwnd:000D0558 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE [wParam:000D0558 lParam:02000001]
<02421> 00100446 S ..WM_SETCURSOR hwnd:000D0558 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE [wParam:000D0558 lParam:02000001]
<02422> 0021045C S ...WM_SETCURSOR hwnd:000D0558 nHittest:HTCLIENT
Reply

Use magic Report

2

Threads

18

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

 Author| Post time: 2020-8-7 23:00:01
| Show all posts
wMouseMsg:WM_MOUSEMOVE [wParam:000D0558 lParam:02000001]
<02423> 000E0460 S ....WM_SETCURSOR hwnd:000D0558 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE [wParam:000D0558 lParam:02000001]
<02424> 00180532 S ..... WM_SETCURSOR hwnd:000D0558 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE [wParam:000D0558 lParam:02000001]
<02425> 000C051C S ......WM_SETCURSOR hwnd:000D0558 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE [wParam:000D0558 lParam:02000001]
<02426> 000C051C R ......WM_SETCURSOR fHaltProcessing:False [lResult:00000000]
<02427> 00180532 R .....WM_SETCURSOR fHaltProcessing:False [lResult:00000000]
<02428> 000E0460 R ....WM_SETCURSOR fHaltProcessing:False [lResult:00000000]
<02429> 0021045C R ...WM_SETCURSOR fHaltProcessing:False [lResult:00000000]
<02430> 00100446 R ..WM_SETCURSOR fHaltProcessing:False [lResult:00000000]
<02431> 00100458 R .WM_SETCURSOR fHaltProcessing:False [lResult:00000000]
<02432> 000D0558 R WM_SETCURSOR fHaltProcessing:False [lResult:00000000]
<02433> 000D0558 P WM_MOUSEMOVE fwKeys:0000 xPos:7 yPos:11 [wParam:00000000 lParam:000B0007 time:7:40:22.875 point:(824, 416)]
<02434> 000F04F6 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000 time:7:40:22.890 point:(824, 416)]
<02435> 000F04F6 S WM_NCPAINT hrgn:00000001 [wParam:00000001 lParam:00000000]
<02436> 000F04F6 R WM_NCPAINT lResult:00000000
<02437> 000F04F6 S WM_ERASEBKGND hdc:4D011AF1 [wParam:4D011AF1 lParam:00000000]
<02438> 00100508 S .WM_CTLCOLORBTN hdcButton:4D011AF1 hwndButton:000F04F6 [wParam:4D011AF1 lParam:000F04F6]
<02439> 00100508 R .WM_CTLCOLORBTN hBrush:0110005A [lResult:0110005A]
<02440> 000F04F6 R WM_ERASEBKGND fErased:True [lResult:00000001]
<02441> 00100508 S WM_CTLCOLORBTN hdcButton:4D011AF1 hwndButton:000F04F6 [wParam:4D011AF1 lParam:000F04F6]
<02442> 00100508 R WM_CTLCOLORBTN hBrush:0110005A [lResult:0110005A]
<02443> 00100508 S WM_DRAWITEM idCtl:2024 lpdis:0012F978 [wParam:000007E8 lParam:0012F978]
<02444> 00100508 R WM_DRAWITEM fProcessed:True [lResult:00000001]
<02445> 000E0486 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000 time:7:40:22.890 point:(824, 416)]
<02446> 000E0486 S WM_NCPAINT hrgn:00000001 [wParam:00000001 lParam:00000000]
<02447> 000E0486 R WM_NCPAINT lResult:00000000
<02448> 000E0486 S WM_ERASEBKGND hdc:4D011AF1 [wParam:4D011AF1 lParam:00000000]
<02449> 00100508 S .WM_CTLCOLORBTN hdcButton:4D011AF1 hwndButton:000E0486 [wParam:4D011AF1 lParam:000E0486]
<02450> 00100508 R .WM_CTLCOLORBTN hBrush:0110005A [lResult:0110005A]
<02451> 000E0486 R WM_ERASEBKGND fErased:True [lResult:00000001]
<02452> 00100508 S WM_CTLCOLORBTN hdcButton:4D011AF1 hwndButton:000E0486 [wParam:4D011AF1 lParam:000E0486]
<02453> 00100508 R WM_CTLCOLORBTN hBrush:0110005A [lResult:0110005A]
<02454> 00100508 S WM_DRAWITEM idCtl:2025 lpdis:0012F978 [wParam:000007E9 lParam:0012F978]
<02455> 00100508 R WM_DRAWITEM fProcessed:True [lResult:00000001]
<02456> 000E0474 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000 time:7:40:22.890 point:(824, 416)]
<02457> 000E0474 S WM_NCPAINT hrgn:00000001 [wParam:00000001 lParam:00000000]
<02458> 000E0474 R WM_NCPAINT lResult:00000000
<02459> 000E0474 S WM_ERASEBKGND hdc:4D011AF1 [wParam:4D011AF1 lParam:00000000]
<02460> 00100508 S .WM_CTLCOLORBTN hdcButton:4D011AF1 hwndButton:000E0474 [wParam:4D011AF1 lParam:000E0474]
<02461> 00100508 R .WM_CTLCOLORBTN hBrush:0110005A [lResult:0110005A]
<02462> 000E0474 R WM_ERASEBKGND fErased:True [lResult:00000001]
<02463> 00100508 S WM_CTLCOLORBTN hdcButton:4D011AF1 hwndButton:000E0474 [wParam:4D011AF1 lParam:000E0474]
<02464> 00100508 R WM_CTLCOLORBTN hBrush:0110005A [lResult:0110005A]
<02465> 00100508 S WM_DRAWITEM idCtl:2026 lpdis:0012F978 [wParam:000007EA lParam:0012F978]
<02466> 00100508 R WM_DRAWITEM fProcessed:True [lResult:00000001]
<02467> 000E05A2 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000 time:7:40:22.890 point:(824, 416)]
<02468> 000E05A2 S WM_NCPAINT hrgn:00000001 [wParam:00000001 lParam:00000000]
<02469> 000E05A2 R WM_NCPAINT lResult:00000000
<02470> 000E05A2 S WM_ERASEBKGND hdc:4D011AF1 [wParam:4D011AF1 lParam:00000000]
<02471> 00100508 S .WM_CTLCOLORBTN hdcButton:4D011AF1 hwndButton:000E05A2 [wParam:4D011AF1 lParam:000E05A2]
<02472> 00100508 R .WM_CTLCOLORBTN hBrush:0110005A [lResult:0110005A]
<02473> 000E05A2 R WM_ERASEBKGND fErased:True [lResult:00000001]
<02474> 00100508 S WM_CTLCOLORBTN hdcButton:4D011AF1 hwndButton:000E05A2 [wParam:4D011AF1 lParam:000E05A2]
<02475> 00100508 R WM_CTLCOLORBTN hBrush:0110005A [lResult:0110005A]
<02476> 00100508 S WM_DRAWITEM idCtl:2027 lpdis:0012F978 [wParam:000007EB lParam:0012F978]
<02477> 00100508 R WM_DRAWITEM fProcessed:True [lResult:00000001]
<02478> 000A05C2 P WM_PAINT hdc:00000000 [wParam:00000000 lParam:00000000 time:7:40:22.890 point:(824, 416)]
<02479> 000A05C2 S WM_ERASEBKGND hdc:0D010F8E [wParam:0D010F8E lParam:00000000]
<02480> 000A05C2 R WM_ERASEBKGND fErased:True [lResult:00000001]
<02481> 000D0558 S WM_NCHITTEST xPos:824 yPos:416 [wParam:00000000 lParam:01A00338]
<02482> 000D0558 R WM_NCHITTEST nHittest:HTCLIENT [lResult:00000001]
<02483> 000D0558 S WM_NCHITTEST xPos:824 yPos:416 [wParam:00000000 lParam:01A00338]
<02484> 000D0558 R WM_NCHITTEST nHittest:HTCLIENT [lResult:00000001]
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-8-9 15:30:01
| Show all posts
He uses WM_CTLCOLORBTN for message reflection to modify the background color of the control
This cannot meet your requirements in MFCGridCtrl
Try the method I said for yourself
Replace this code
CString strText = GetText();
CString strTemp = strText.Left(1);
if (strTemp == "1")
{
CSize szText = pDC->GetTextExtent( strTemp );
for (int x = 0; x <strText.GetLength(); x++)
{
strTemp = strText.Mid(x, 1);
rect.left += szText.cx*x;
if (x% 2)
{
pDC->SetTextColor( 0x00ff0000);
} else
{
pDC->SetTextColor( 0x0000ff00);
}

DrawText(pDC->m_hDC, strTemp, -1, rect, GetFormat() | DT_NOPREFIX);
}
} else DrawText(pDC->m_hDC, GetText(), -1, rect, GetFormat() | DT_NOPREFIX);
   


The original
DrawText(pDC->m_hDC, GetText(), -1, rect, GetFormat() | DT_NOPREFIX);

See if the characters in the demo are displayed in color?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list