Ejemplo n.º 1
0
static void test_CB_GETLBTEXT(void)
{
    HWND hCombo;
    CHAR buff[1];
    COMBOBOXEXITEMA item;
    LRESULT ret;

    hCombo = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);

    /* set text to null */
    addItem(hCombo, 0, NULL);

    buff[0] = 'a';
    item.mask = CBEIF_TEXT;
    item.iItem = 0;
    item.pszText = buff;
    item.cchTextMax = 1;
    ret = SendMessageA(hCombo, CBEM_GETITEMA, 0, (LPARAM)&item);
    ok(ret != 0, "CBEM_GETITEM failed\n");
    ok(buff[0] == 0, "\n");

    ret = SendMessageA(hCombo, CB_GETLBTEXTLEN, 0, 0);
    ok(ret == 0, "Expected zero length\n");

    ret = SendMessageA(hCombo, CB_GETLBTEXTLEN, 0, 0);
    ok(ret == 0, "Expected zero length\n");

    buff[0] = 'a';
    ret = SendMessageA(hCombo, CB_GETLBTEXT, 0, (LPARAM)buff);
    ok(ret == 0, "Expected zero length\n");
    ok(buff[0] == 0, "Expected null terminator as a string, got %s\n", buff);

    DestroyWindow(hCombo);
}
Ejemplo n.º 2
0
static void test_WM_WINDOWPOSCHANGING(void)
{
    HWND hCombo;
    WINDOWPOS wp;
    RECT rect;
    int combo_height;
    int ret;

    hCombo = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);
    ok(hCombo != NULL, "createComboEx failed\n");
    ret = GetWindowRect(hCombo, &rect);
    ok(ret, "GetWindowRect failed\n");
    combo_height = rect.bottom - rect.top;
    ok(combo_height > 0, "wrong combo height\n");

    /* Test height > combo_height */
    wp.x = rect.left;
    wp.y = rect.top;
    wp.cx = (rect.right - rect.left);
    wp.cy = combo_height * 2;
    wp.flags = 0;
    wp.hwnd = hCombo;
    wp.hwndInsertAfter = NULL;

    ret = SendMessageA(hCombo, WM_WINDOWPOSCHANGING, 0, (LPARAM)&wp);
    ok(ret == 0, "expected 0, got %x\n", ret);
    ok(wp.cy == combo_height,
            "Expected height %d, got %d\n", combo_height, wp.cy);

    /* Test height < combo_height */
    wp.x = rect.left;
    wp.y = rect.top;
    wp.cx = (rect.right - rect.left);
    wp.cy = combo_height / 2;
    wp.flags = 0;
    wp.hwnd = hCombo;
    wp.hwndInsertAfter = NULL;

    ret = SendMessageA(hCombo, WM_WINDOWPOSCHANGING, 0, (LPARAM)&wp);
    ok(ret == 0, "expected 0, got %x\n", ret);
    ok(wp.cy == combo_height,
            "Expected height %d, got %d\n", combo_height, wp.cy);

    ret = DestroyWindow(hCombo);
    ok(ret, "DestroyWindow failed\n");
}
Ejemplo n.º 3
0
static void test_comboboxex_subclass(void)
{
    HWND hComboEx, hCombo, hEdit;

    hComboEx = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);

    hCombo = (HWND)SendMessageA(hComboEx, CBEM_GETCOMBOCONTROL, 0, 0);
    ok(hCombo != NULL, "Failed to get internal combo\n");
    hEdit = (HWND)SendMessageA(hComboEx, CBEM_GETEDITCONTROL, 0, 0);
    ok(hEdit != NULL, "Failed to get internal edit\n");

    if (pSetWindowSubclass)
    {
        ok(GetPropA(hCombo, "CC32SubclassInfo") != NULL, "Expected CC32SubclassInfo property\n");
        ok(GetPropA(hEdit, "CC32SubclassInfo") != NULL, "Expected CC32SubclassInfo property\n");
    }

    DestroyWindow(hComboEx);
}
Ejemplo n.º 4
0
static void test_get_set_item(void)
{
    char textA[] = "test";
    HWND hComboEx;
    COMBOBOXEXITEMA item;
    BOOL ret;

    hComboEx = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);

    subclass_editbox(hComboEx);

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    memset(&item, 0, sizeof(item));
    item.mask = CBEIF_TEXT;
    item.pszText = textA;
    item.iItem = -1;
    ret = SendMessageA(hComboEx, CBEM_SETITEMA, 0, (LPARAM)&item);
    expect(TRUE, ret);

    ok_sequence(sequences, EDITBOX_SEQ_INDEX, test_setitem_edit_seq, "set item data for edit", FALSE);

    /* get/set lParam */
    item.mask = CBEIF_LPARAM;
    item.iItem = -1;
    item.lParam = 0xdeadbeef;
    ret = SendMessageA(hComboEx, CBEM_GETITEMA, 0, (LPARAM)&item);
    expect(TRUE, ret);
    ok(item.lParam == 0, "Expected zero, got %lx\n", item.lParam);

    item.lParam = 0x1abe11ed;
    ret = SendMessageA(hComboEx, CBEM_SETITEMA, 0, (LPARAM)&item);
    expect(TRUE, ret);

    item.lParam = 0;
    ret = SendMessageA(hComboEx, CBEM_GETITEMA, 0, (LPARAM)&item);
    expect(TRUE, ret);
    ok(item.lParam == 0x1abe11ed, "Expected 0x1abe11ed, got %lx\n", item.lParam);

    DestroyWindow(hComboEx);
}
Ejemplo n.º 5
0
static void test_comboboxex(void) {
    HWND myHwnd = 0;
    LONG res = -1;
    COMBOBOXEXITEMA cbexItem;
    static const char *first_item  = "First Item",
                *second_item = "Second Item",
                *third_item  = "Third Item",
                *middle_item = "Between First and Second Items",
                *replacement_item = "Between First and Second Items",
                *out_of_range_item = "Out of Range Item";

    /* Allocate space for result */
    textBuffer = HeapAlloc(GetProcessHeap(), 0, MAX_CHARS);

    /* Basic comboboxex test */
    myHwnd = createComboEx(WS_BORDER | WS_VISIBLE | WS_CHILD | CBS_DROPDOWN);

    /* Add items onto the end of the combobox */
    res = addItem(myHwnd, -1, first_item);
    ok(res == 0, "Adding simple item failed (%d)\n", res);
    res = addItem(myHwnd, -1, second_item);
    ok(res == 1, "Adding simple item failed (%d)\n", res);
    res = addItem(myHwnd, 2, third_item);
    ok(res == 2, "Adding simple item failed (%d)\n", res);
    res = addItem(myHwnd, 1, middle_item);
    ok(res == 1, "Inserting simple item failed (%d)\n", res);

    /* Add an item completely out of range */
    res = addItem(myHwnd, 99, out_of_range_item);
    ok(res == -1, "Adding using out of range index worked unexpectedly (%d)\n", res);
    res = addItem(myHwnd, 5, out_of_range_item);
    ok(res == -1, "Adding using out of range index worked unexpectedly (%d)\n", res);
    /* Removed: Causes traps on Windows XP
       res = addItem(myHwnd, -2, "Out Of Range Item");
       ok(res == -1, "Adding out of range worked unexpectedly (%ld)\n", res);
     */

    /* Get an item completely out of range */ 
    res = getItem(myHwnd, 99, &cbexItem); 
    ok(res == 0, "Getting item using out of range index worked unexpectedly (%d, %s)\n", res, cbexItem.pszText);
    res = getItem(myHwnd, 4, &cbexItem); 
    ok(res == 0, "Getting item using out of range index worked unexpectedly (%d, %s)\n", res, cbexItem.pszText);
    res = getItem(myHwnd, -2, &cbexItem); 
    ok(res == 0, "Getting item using out of range index worked unexpectedly (%d, %s)\n", res, cbexItem.pszText);

    /* Get an item in range */ 
    res = getItem(myHwnd, 0, &cbexItem); 
    ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
    ok(strcmp(first_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);

    res = getItem(myHwnd, 1, &cbexItem); 
    ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
    ok(strcmp(middle_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);

    res = getItem(myHwnd, 2, &cbexItem); 
    ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
    ok(strcmp(second_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);

    res = getItem(myHwnd, 3, &cbexItem); 
    ok(res != 0, "Getting item using valid index failed unexpectedly (%d)\n", res);
    ok(strcmp(third_item, cbexItem.pszText) == 0, "Getting item returned wrong string (%s)\n", cbexItem.pszText);

    /* Set an item completely out of range */ 
    res = setItem(myHwnd, 99, replacement_item); 
    ok(res == 0, "Setting item using out of range index worked unexpectedly (%d)\n", res);
    res = setItem(myHwnd, 4, replacement_item); 
    ok(res == 0, "Setting item using out of range index worked unexpectedly (%d)\n", res);
    res = setItem(myHwnd, -2, replacement_item); 
    ok(res == 0, "Setting item using out of range index worked unexpectedly (%d)\n", res);

    /* Set an item in range */ 
    res = setItem(myHwnd, 0, replacement_item);
    ok(res != 0, "Setting first item failed (%d)\n", res);
    res = setItem(myHwnd, 3, replacement_item);
    ok(res != 0, "Setting last item failed (%d)\n", res);

    /* Remove items completely out of range (4 items in control at this point) */
    res = delItem(myHwnd, -1);
    ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%d)\n", res);
    res = delItem(myHwnd, 4);
    ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%d)\n", res);

    /* Remove items in range (4 items in control at this point) */
    res = delItem(myHwnd, 3);
    ok(res == 3, "Deleting using out of range index failed (%d)\n", res);
    res = delItem(myHwnd, 0);
    ok(res == 2, "Deleting using out of range index failed (%d)\n", res);
    res = delItem(myHwnd, 0);
    ok(res == 1, "Deleting using out of range index failed (%d)\n", res);
    res = delItem(myHwnd, 0);
    ok(res == 0, "Deleting using out of range index failed (%d)\n", res);

    /* Remove from an empty box */
    res = delItem(myHwnd, 0);
    ok(res == CB_ERR, "Deleting using out of range index worked unexpectedly (%d)\n", res);


    /* Cleanup */
    HeapFree(GetProcessHeap(), 0, textBuffer);
    DestroyWindow(myHwnd);
}
Ejemplo n.º 6
0
LRESULT CALLBACK wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;   
    static int dwPos;
    switch (message) 
    { 

    case WM_CREATE:{ 
        toolBar = createToolbar(hWnd); 
        objectSelector = createComboEx(hWnd); 
        initButtons(hWnd);
        break;
    }  
    case WM_SIZE:{ 
        width = LOWORD(lParam);
        height = HIWORD(lParam);
        MoveWindow(toolBar, 0, 20, width, 5, TRUE);
        MoveWindow(hwndEdit, 0, 40, width / 2 - 5, height - 40, TRUE); 
        MoveWindow(hwndView, width / 2, 40, width / 2, height / 2, TRUE);
        MoveWindow(objectSelector, width/2+10, height/2+100, 100, 100, TRUE);
        MoveWindow(checkBox, width / 2 + 120, height / 2 + 100, 120, 20, TRUE);
        MoveWindow(deleteButton, width / 2 + 245, height / 2 + 100, 40, 40, TRUE);

        MoveWindow(controlButtons[0], width / 2 + 450, height / 2 + 180, 40, 40, TRUE);
        MoveWindow(controlButtons[1], width / 2 + 350, height / 2 + 180, 40, 40, TRUE);
        MoveWindow(controlButtons[2], width / 2 + 400, height / 2 + 120, 40, 40, TRUE);
        MoveWindow(controlButtons[3], width / 2 + 400, height / 2 + 240, 40, 40, TRUE);

        MoveWindow(controlButtons[4], width / 2 + 450, height / 2 + 300, 40, 40, TRUE);
        MoveWindow(controlButtons[5], width / 2 + 350, height / 2 + 300, 40, 40, TRUE);
        reSizeGLScene(width / 2, height / 2);
        DrawGLScene();
        break; 
    }
    case WM_LBUTTONDOWN:{
        SetFocus(mainWindow);
        break;
    }
    case WM_MOUSEWHEEL:
        if ((short)HIWORD(wParam) > 0)
        {
            objCamera.Move_Camera(CAMERASPEED);
            DrawGLScene();
        }
        if ((short)HIWORD(wParam) < 0)
        {
            objCamera.Move_Camera(-CAMERASPEED);
            DrawGLScene();
        }
        break;
    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);   
        if (HIWORD(wParam) == CBN_SELCHANGE)
            // If the user makes a selection from the list:
            //   Send CB_GETCURSEL message to get the index of the selected list item.
            //   Send CB_GETLBTEXT message to get the item.
        { 
            int ItemIndex = SendMessage((HWND)lParam, (UINT)CB_GETCURSEL,
                (WPARAM)0, (LPARAM)0);
            if (ItemIndex != CB_ERR){
                EnableWindow(deleteButton, TRUE);  
                LPCSTR nameStr = objNames[ItemIndex].c_str();
                fileToEdit(nameStr); 
                int hid = BST_CHECKED; 
                selected = objects[ItemIndex];
                currentObjIndex = ItemIndex;
                if (objects[ItemIndex]->hidden == true){
                    hid = BST_UNCHECKED;
                }
                else{
                    hid = BST_CHECKED;
                }
                CheckDlgButton(hWnd, ID_CHECK_DISP_OBJ, hid);
            }
            else{
                CheckDlgButton(hWnd, ID_CHECK_DISP_OBJ, BST_INDETERMINATE);
            }
        }
        switch (wmId)
        {
        case ID_CHECK_DISP_OBJ:
            if (wmEvent == BN_CLICKED)
            {
                dwPos = SendMessage(checkBox, BM_GETCHECK, 0, 0);
                if (dwPos == BST_CHECKED)
                {
                    CheckDlgButton(hWnd, ID_CHECK_DISP_OBJ, BST_UNCHECKED);
                    selected->hidden = true;
                    DrawGLScene();

                }
                else if (dwPos == BST_UNCHECKED) {
                    CheckDlgButton(hWnd, ID_CHECK_DISP_OBJ, BST_CHECKED);
                    selected->hidden = false;
                    DrawGLScene();
                }
                dwPos = SendMessage(checkBox, BM_GETCHECK, 0, 0);
            }
            break;
        case ID_BUTTON_DEL_OBJ:
            if (wmEvent == BN_CLICKED)
            {
                int ItemIndex = SendMessage(objectSelector, (UINT)CB_GETCURSEL,
                    (WPARAM)0, (LPARAM)0);
                if (ItemIndex != CB_ERR){
                    objects.erase(objects.begin() + ItemIndex);
                    objNames.erase(objNames.begin() + ItemIndex);
                    SendMessage(objectSelector, (UINT)CB_DELETESTRING,
                        (WPARAM)ItemIndex, (LPARAM)0);
                }
                int top = SendMessage(objectSelector, (UINT)CB_GETCOUNT, (WPARAM)0, (LPARAM)0);
                if (top != 0){
                    SendMessage(objectSelector, (UINT)CB_SETCURSEL, (WPARAM)top - 1, (LPARAM)0);
                    selected = objects[top - 1];
                    LPCSTR nameStr = objNames[top - 1].c_str();
                    fileToEdit(nameStr);
                }
                else{
                    SendMessage(objectSelector, (UINT)CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
                    selected = NULL;
                    SetDlgItemText(hWnd, ID_EDITOR, TEXT(""));
                    SendMessage(toolBar, TB_ENABLEBUTTON, IDM_SAVE, FALSE);
                }

                ItemIndex = SendMessage(objectSelector, (UINT)CB_GETCURSEL,
                    (WPARAM)0, (LPARAM)0);
                if (ItemIndex == CB_ERR){
                    EnableWindow(deleteButton, FALSE);
                    CheckDlgButton(hWnd, ID_CHECK_DISP_OBJ, BST_INDETERMINATE);
                }
                else{
                    int hid = BST_CHECKED;
                    if (objects[ItemIndex]->hidden == true){
                        hid = BST_UNCHECKED;
                    }
                    else{
                        hid = BST_CHECKED;
                    }
                    CheckDlgButton(hWnd, ID_CHECK_DISP_OBJ, hid);
                }
                DrawGLScene();
            }
            break; 
        case ID_BUTTON_RIGHT:
            if (selected){
                selected->t_x += 0.1f;
                DrawGLScene();
            }
            break;
        case ID_BUTTON_LEFT:
            if (selected){
                selected->t_x -= 0.1f;
                DrawGLScene();
            }
            break;
        case ID_BUTTON_DOWN:
            if (selected){
                selected->t_y -= 0.1f;
                DrawGLScene();
            }
            break;
        case ID_BUTTON_UP:
            if (selected){
                selected->t_y += 0.1f;
                DrawGLScene();
            }
            break;
        case ID_BUTTON_ROTATE_RIGHT:
            if (selected){
                selected->rotation -= 1.0f;
                if (selected->rotation > 359.0f)
                    selected->rotation = 0.0f;
                if (selected->rotation < -1.0f)
                    selected->rotation = 359.0f;
                DrawGLScene();
            }
            break;
        case ID_BUTTON_ROTATE_LEFT:
            if (selected){
                selected->rotation += 1.0f;
                if (selected->rotation > 359.0f)
                    selected->rotation = 0.0f;
                if (selected->rotation < -1.0f)
                    selected->rotation = 359.0f;
                DrawGLScene();
            }
            break;
        case ID_EDITOR:
            switch (wmEvent)
            {
            case EN_MAXTEXT:
                MessageBeep(0);
            default:
                break;
            }
            break;
        case IDM_SAVE:{
            BOOL res = saveObjFile(hWnd, ID_EDITOR);
            if (!res){
                MessageBox(NULL, TEXT("Writting error"),
                    TEXT("Error"), MB_ICONERROR);
            }
            break;
        }
        case IDM_RUN:{
            objects.clear();
            for (std::vector<std::string>::iterator it = objNames.begin(); it != objNames.end(); ++it){
                objects.push_back(new MifObject(*it));
            }
            int ItemIndex = SendMessage(objectSelector, (UINT)CB_GETCOUNT,
                (WPARAM)0, (LPARAM)0);
            if (ItemIndex != 0){
                selected = objects[currentObjIndex];
            }
            else{
                selected = NULL;
            }
            DrawGLScene();
            break;
        }
        case IDM_OPEN:{
            BOOL loaded = openFileIntoEditor(hwndEdit, ID_EDIT);
            SendMessage(toolBar, TB_ENABLEBUTTON, IDM_SAVE, loaded); 
            DrawGLScene();
            break;
        }
        case IDM_about: 
            DialogBox(hInst, MAKEINTRESOURCE(IDD_aboutBOX), mainWindow, about);
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
        }
        break;
    case WM_KEYDOWN:
        switch (wParam)
        {
        case VK_UP:
            objCamera.Move_Camera(CAMERASPEED);
            break;
        case VK_DOWN:
            objCamera.Move_Camera(-CAMERASPEED);
            break;
        case VK_LEFT:
            objCamera.Strafe_Camera(-CAMERASPEED);
            break;
        case VK_RIGHT:
            objCamera.Strafe_Camera(CAMERASPEED);
            break;
        case VK_HOME:
            openFileIntoEditor(hwndEdit, ID_EDIT);
            break; 
        case VK_F1:
            {
                primitive = GL_LINE_LOOP;
                DrawGLScene();
            }
            break;
        case VK_F2:
            {
                primitive = GL_POLYGON;
                DrawGLScene();
                  }
            break;
        case VK_ESCAPE:{
            SetWindowTextA(hwndEdit, "");
            PostQuitMessage(0);
            break;
        }
        default:
            return 0;
        }
        DrawGLScene();
        break;
    case WM_PAINT:
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}