vendredi 1 avril 2016

Checkbox Checked problems in win32 api c++

I've this code done in c++ and I want to ask why when I press one CheckBox all of them change status. Example:

CB1 = Checked CB2 = UnChecked

CB1 = Press

CB1 = UnChecked CB2 = Checked

I want just to make work one of them, not the two at the same time.

Here you have the code:

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

    switch (msg)
    {
    case WM_CREATE:
    {

        //Load the background image
        HWND hWndBackground;
        HANDLE hBitmap;
        hBitmap = LoadImage(NULL, TEXT("\header.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
        if (hBitmap != NULL)
        {
            hWndBackground = CreateWindow(TEXT("STATIC"), TEXT("image box"),
                WS_CHILD | WS_VISIBLE | SS_BITMAP, 
                0, 0, 470, 130, 
                hwnd, (HMENU)2000, NULL, NULL);
            SendMessage(hWndBackground, STM_SETIMAGE, IMAGE_BITMAP, LPARAM(hBitmap));
        }

        //Load CheckBox1
        CreateWindow(TEXT("button"), TEXT("Show Title"),
            WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
            25, 220, 114, 45,
            hwnd, (HMENU)1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
        CheckDlgButton(hwnd, 1, BST_CHECKED);

        //Load Textbox1
        CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT("140"),
            WS_CHILD | WS_VISIBLE, 
            115, 230, 50, 25,
            hwnd, NULL, NULL, NULL);

        //Load Label1
        CreateWindowW(L"Static", L"0",
            WS_CHILD | WS_VISIBLE, 0, 0, 10, 30, hwnd, (HMENU)1, NULL, NULL);

        //Load CheckBox2
        CreateWindow(TEXT("button"), TEXT("Show Title1"),
            WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
            25, 250, 114, 45,
            hwnd, (HMENU)2, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
        CheckDlgButton(hwnd, 2, BST_UNCHECKED);

        break;
    }

    case WM_COMMAND:
    {
        BOOL checked = IsDlgButtonChecked(hwnd, 1);
        if (checked) {
            CheckDlgButton(hwnd, 1, BST_UNCHECKED); //SetWindowText(hwnd, title or TEXT("algo");

        }
        else {
            CheckDlgButton(hwnd, 1, BST_CHECKED);
            //action("chatlim", 150, 0, 0);
        }

        BOOL checked1 = IsDlgButtonChecked(hwnd, 2);
        if (checked1) {
            CheckDlgButton(hwnd, 2, BST_UNCHECKED);
        }
        else {
            CheckDlgButton(hwnd, 2, BST_CHECKED);
        }
        break;
    }

    case WM_DESTROY:
    {
        PostQuitMessage(0);
        break;
    }
    }
    return DefWindowProc(hwnd, msg, wParam, lParam);
}




Aucun commentaire:

Enregistrer un commentaire