winapi

After a button is clicked, its perimeter remains highlighted. I would like to find out how to cancel this


I have many buttons on a dialog page. Once, created one of them has the perimeter highlighted. After looking at this I determined that the same thing happens after a button is pressed. Once it is released, the perimeter remains slightly highlighted. The buttons are all created in the .rc file using DIALOGEX.

More than 50 buttons are created using code like this:

DEFPUSHBUTTON "  P0100 MASS AIR FLOW SENSOR CIRCUIT INSUFFICIENT ACTIVITY", IDC_M17_P0100, 5, 45, 300, 14, BS_LEFT, WS_EX_CLIENTEDGE

I overlap buttons and enable/disable them with this sort of code:

ShowWindow(GetDlgItem(hDlg, IDC_M17_P0100), nShow);

Once created and better, after pressing a button I would like them to remain un-highlighted. I have been looking for a style/extended style, but I just have come up empty.

Edit: here's one of the dialog segments

    IDD_MODE_$17 DIALOGEX 0, 0, 500, 500
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU //| DS_CONTROL | WS_THICKFRAME  | WS_VSCROLL
//EXSTYLE WS_EX_WINDOWEDGE
CAPTION "Mode $17 Diagnostics"
FONT 10, "MS Shell Dlg"
BEGIN
//SCROLLBAR IDC_VSCROLLBAR, 570, 0, 10, 300, SBS_VERT
LTEXT           "Mode $17: Request status of diagnostic trouble codes (DTC)", IDC_STATIC, 5, 5, 200, 10, SS_NOPREFIX

DEFPUSHBUTTON "  P0100 MASS AIR FLOW SENSOR CIRCUIT INSUFFICIENT ACTIVITY", IDC_M17_P0100, 5, 45, 300, 14, BS_LEFT, WS_EX_CLIENTEDGE
...
DEFPUSHBUTTON "  P1886 3-2 SHIFT SOLENOID VALVE CIRCUIT", IDC_M17_P1886, 5, 285, 300, 14, BS_LEFT, WS_EX_CLIENTEDGE

LTEXT           "", IDS_RESULT, 310, 45, 200, 300, SS_NOPREFIX | BS_LEFT, WS_EX_CLIENTEDGE

END

Jabberwocky's comment re DEFPUSHBUTTON vs PUSHBUTTON is correct. I gained an understanding of the difference, thank you. Raymond's comment re only one default I am now sure is also correct but doesn't affect the outcome. Seems that the last DEFPUSHBUTTON generated just becomes the default. This is not as I intended so I changed all to PUSHBUTTON . The highlighting remains though. Is there no style I can add to make the button not highlight? Some ways out of my depth here...

Highlighted button is "P1886 2-3 shift..."

The trouble is not so much with the code as understanding why the button marked P1886 is slightly highlighted. If I could know why this is so, perhaps I could send a message to reset the parameter. At the moment the app runs, and ok but it is difficult not understanding the highlight & how to work with it. I have tried adjusting focus and highlight. I am not sure what code to publish that would help better show the issue.


Solution

  • This answer is more of a work-around. The first button defined in the dialog receives this highlighting. In my case I have seven pages of buttons. To resolve having one of the selections highlighted I reordered the button definitions. Since I have buttons to select the page to be displayed, I added those buttons first. Now when the dialog is displayed all the buttons are displayed without highlight except the page button. Since I initialize with page 1 viewed and that is the first button defined, all looks proper. I don't know the reason for this all but it does seem related to the default button for the dialog. I tested with various messages like DM_SETDEFID, BM_SETSTYLE and DM_SETDEFID but was never able to rid myself of the highlight. Another way might be to first create an unused button and make it invisible. For now, I have probably spent too much of your time fussing with this. I have the result I want in the app even if I lack understanding of the reason behind it.