Strange effect when creating a ListView

I noticed a strange effect when I create a Listview.

When I create a ListView without creating a button, the selected item in the ListView has a dashed border. However, when I also create the button, the ListView list item no longer has a dotted border. This only happens when I have a manifest file that allows the use of common 6 controls:

enter image description here

This is the code I used to create Window and ListView and Button:

// Create Window HWND hWnd = CreateWindowEx(0, "WinClass", "My Window", WS_OVERLAPPEDWINDOW, 261, 172, 394, 284, NULL, NULL, hInstance, NULL); // Create ListView HWND hListView = CreateWindowEx(0, WC_LISTVIEW, "", WS_CHILD | LVS_REPORT | WS_VISIBLE, 0, 0, 232, 190, hWnd, 0, GetModuleHandle(NULL), NULL); // Create Button HWND hButtonRefresh = CreateWindowEx(NULL, "BUTTON", "OK", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 10, 200, 110, 25, hWnd, NULL, GetModuleHandle(NULL), NULL); 

Note: I have no problem with this effect, I just want to understand why this is happening!

+5
source share
3 answers

This only happens because the button has focus and the view of the list is lost, click on the list and the dots should appear again.

+1
source

I believe that the dotted border indicates the default control. In the second screenshot, go to the "Button Properties" and set the "Default" button to false, and then you will see a dashed border around the text, as in the first screenshot.

To do this, open the dialog box in the "Resources" window, select the button and select "Properties" in the right-click menu. In the "Properties" window, you should see the "Default" button in the "Behavior" section - just change it to "False".

Alternatively, in code, try something like this: -

 DWORD style = m_BtnOk.GetStyle(); // remove default push button style style &= ~BS_DEFPUSHBUTTON; // set the style ::SendMessage(m_BtnClose.GetSafeHwnd(), BM_SETSTYLE, (WPARAM)style, (LPARAM)TRUE); 
0
source

As others have pointed out, the goal is to indicate the focus of the input. If you tab around any native shape, you will see that the rectangle jumps around the indices configured by the developer.

The reason it appears at all is because it has TabStop . Since in the first example there is only one element, there is only one possibility for tabulation, therefore it is indicated by a rectangle. Play with TabStop , Tab around, see what changes.

0
source

All Articles