Check if a button has been pressed?

I know how to check if a particular button has been pressed but I basically want to disable the delete button when ever the listbox has lost focus. I am having issues with the fact the button gets disabled before it receives the message. Is their a way around this that is non hacky?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_INITDIALOG:
        {
            refreshListboxWithDataLogs(hwndDlg, LOGS_LISTBOX);
            Misc::enableDlgItm(hwndDlg, DELETE_BTN, false);
        }
        return TRUE;

        case WM_CLOSE:
        {
            EndDialog(hwndDlg, 0);
        }
        return TRUE;

        case WM_COMMAND:
        {
            switch(LOWORD(wParam))
            {
                case MENU_NEW_ROYAL_PYTHON:
                    DialogBox(hInst, MAKEINTRESOURCE(NEW_PYTHON_DLG), NULL, (DLGPROC)DlgMain);
                break;

                case FED_TODAY_BTN:
                    refreshListboxWithDataLogs(hwndDlg, LOGS_LISTBOX);
                    Manager::snakeFed(30, time(NULL));
                break;

                case DELETE_BTN:
                    int a;
                    a = MessageBoxA(0, (LPCSTR)"Are you sure you want to delete this log?", "", MB_YESNO);
                    if (a == IDYES)
                    {
                        cout << "Deleting " << pythonFedId;
                        Misc::enableDlgItm(hwndDlg, DELETE_BTN, false);
                    }
                    break;


                case LOGS_LISTBOX:
                    switch(HIWORD(wParam))
                    {
                        case LBN_SELCHANGE:
                            int lblItem, recordId;
                            Leaf::Record* selRecord;
                            Leaf::Column* pfid;
                            HWND listbox;
                            listbox = GetDlgItem(hwndDlg, LOGS_LISTBOX);
                            lblItem = (int)SendMessage(listbox, LB_GETCURSEL, 0, 0);
                            recordId = (int)SendMessage(listbox, LB_GETITEMDATA, lblItem, 0);
                            selRecord = records->getRecord(recordId);
                            pfid = selRecord->getColumn("PYTHON_FED_ID");
                            pythonFedId = pfid->data.datai;
                            Misc::enableDlgItm(hwndDlg, DELETE_BTN, true);
                        break;
                    }
                break;
            }
        }
        return TRUE;
    }

    return FALSE;
}


Thanks
Last edited on
closed account (10X9216C)
I wouldn't recommending using WinAPI for GUI. There are a lot of libraries out there that wrap around it so you don't have to work with the terrible (my personal opinion) API. I'd recommend Qt, though there are still some other's worth investigating.
Topic archived. No new replies allowed.