Skip to content

Commit 2c074fe

Browse files
committed
Remove the selected item when Delete is pressed
1 parent 37f2f5d commit 2c074fe

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Small Win32 programs written in C, for learning.
66
| --- | --- |
77
| `hello.c` | A message box. |
88
| `textbox.c` | A window with a multiline edit control that follows the window size. |
9-
| `list.c` | A list box, buttons, freehand drawing and a double-buffered window. |
9+
| `list.c` | A list box, buttons (also Enter and Delete), freehand drawing and a double-buffered window. |
1010
| `shape_list.h` | Window-free helpers for the shape list used by `list.c`. |
1111
| `backbuffer.h` | GDI helpers for the off-screen buffer, shapes and repainting. |
1212

‎tests/list_ui_test.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ int main(int argc, char **argv) {
103103
failed = 1;
104104
}
105105

106+
/* Delete in the list box removes the selected item like the button, and nothing without a selection */
107+
SendMessage(listBox, LB_SETCURSEL, 0, 0);
108+
PostMessage(listBox, WM_KEYDOWN, VK_DELETE, 0);
109+
Sleep(300);
110+
if (ListCount() != 2) {
111+
puts("FAIL: Delete did not remove the selected item");
112+
failed = 1;
113+
}
114+
SendMessage(listBox, LB_SETCURSEL, (WPARAM)-1, 0);
115+
PostMessage(listBox, WM_KEYDOWN, VK_DELETE, 0);
116+
Sleep(300);
117+
if (ListCount() != 2) {
118+
puts("FAIL: Delete without a selection removed an item");
119+
failed = 1;
120+
}
121+
106122
/* a full list tells the user why Add does nothing */
107123
while (ListCount() < 100) {
108124
SetWindowText(edit, "item");

0 commit comments

Comments
 (0)