Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to all who gave advice and help. I now have this working to my satisfaction. I have successfully colored the buttons and surrounded them with a black outline if selected or if they have the input focus. I'll add some code snippets below to show the final state of things but here is synopsis. First, I believe there is some legacy code in my system which makes owner drawn buttons respond to the WM_CTLCOLORBTN for the first child 64 buttons created. Second, I believe the only thing one needs to do is create the buttons, respond properly to the WM_DRAWITEM and WM_COMMAND/BN_CLICKED messages. </p> <p>Here are the code snippets from my dialog box handler.</p> <p>In the WM_INITDIALOG code -- create the buttons</p> <pre><code> for (i=0; i&lt;=255; i++) { int xp, yp; HWND status; xp = rect_pos.left+16*(i&amp;0x0F); yp = rect_pos.top+16*(i&gt;&gt;4); status = CreateWindow ( TEXT("button"), "\0", WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_OWNERDRAW, xp, yp, 15, 15, hDlg, (HMENU) (5000+i), // id used to report events hInst, NULL ); if (status == NULL) xp =7; SetFocus (status); } </code></pre> <p>Respond to the WM_DRAWITEM message</p> <pre><code>case WM_DRAWITEM: // Owner drawn botton { LPDRAWITEMSTRUCT lpDrawItem; HBRUSH BS, BS_Old; HPEN PN_Old; int sz=15; int cntl; cntl = LOWORD (wParam) - 5000; lpDrawItem = (LPDRAWITEMSTRUCT) lParam; if (lpDrawItem-&gt;CtlType != ODT_BUTTON) return FALSE; BS = CreateSolidBrush (ColorRef[cntl]); if (lpDrawItem-&gt;itemState &amp; (ODS_SELECTED | ODS_FOCUS)) { sz = 14; PN_Old = (HPEN) SelectObject(lpDrawItem-&gt;hDC, GetStockObject(BLACK_PEN)); } else PN_Old = (HPEN) SelectObject(lpDrawItem-&gt;hDC, GetStockObject(NULL_PEN)); BS_Old = (HBRUSH) SelectObject(lpDrawItem-&gt;hDC, BS); Rectangle (lpDrawItem-&gt;hDC, 0, 0, sz, sz); SelectObject(lpDrawItem-&gt;hDC, PN_Old); SelectObject(lpDrawItem-&gt;hDC, BS_Old); DeleteObject (BS); return true; } </code></pre> <p>and finally in the WM_COMMAND code</p> <pre><code> if (HIWORD(wParam) == BN_CLICKED) { if ((LOWORD(wParam) &gt;= 5000) &amp;&amp; (LOWORD(wParam) &lt;=5255)) { Color[0] = ColorRef[LOWORD(wParam)-5000] &amp; 0xFF; Color[1] = (ColorRef[LOWORD(wParam)-5000] &gt;&gt; 16) &amp; 0xFF; Color[2] = (ColorRef[LOWORD(wParam)-5000] &gt;&gt; 8 ) &amp; 0xFF; InvalidateRect (hDlg, NULL, TRUE); goto Set_Color; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload