纯C,winapi应用程序。
在从资源脚本创建的对话框中,它完全适合,但使用CreateWindowEx创建时,上下控件比好友窗口(编辑控件)两边高一个像素。
这没什么大不了的,但很烦人。我想尽了一切办法都没有修好,谢谢你的帮助。
代码如下:

#include <Windows.h>
#include <Commctrl.h>
#include <stdio.h>

#define print(...)  sprintf(dbg, __VA_ARGS__);\
                    WriteConsoleA(h_con_out, dbg, strlen(dbg), NULL, NULL)

TCHAR *app_name = TEXT("ud");
HANDLE h_con_out;
char dbg[80];

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

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){
    HWND hwnd;
    MSG msg;
    WNDCLASSEX wcx;
    INITCOMMONCONTROLSEX icx = {sizeof(icx), ICC_STANDARD_CLASSES | ICC_UPDOWN_CLASS};

    AllocConsole();
    h_con_out = GetStdHandle(STD_OUTPUT_HANDLE);

    memset(&wcx, 0, sizeof(wcx));
    wcx.cbSize = sizeof(wcx);
    wcx.lpfnWndProc = WndProc;
    wcx.hInstance = hInstance;
    wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcx.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
    wcx.lpszClassName = app_name;

    if(!RegisterClassEx(&wcx)){
        MessageBox(NULL, TEXT("This program requires Windows 2000!"), app_name, MB_ICONERROR);
        return 0;
    }
    InitCommonControlsEx(&icx);

    hwnd = CreateWindowEx(
        0, app_name, app_name,
        WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
        CW_USEDEFAULT, CW_USEDEFAULT, 200, 100,
        NULL, NULL, hInstance, NULL
    );
    ShowWindow(hwnd, iCmdShow);
    UpdateWindow(hwnd);

    while((GetMessage(&msg, NULL, 0, 0)) != 0){
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
    static HWND hEd, hUd;

    switch(msg){
        case WM_CREATE:
            hEd = CreateWindowEx(
                WS_EX_CLIENTEDGE, WC_EDIT, NULL,
                WS_VISIBLE | WS_CHILD | WS_BORDER |
                ES_RIGHT | ES_NUMBER,
                5, 5, 52, 23,
                hwnd, NULL, ((LPCREATESTRUCT) lParam)->hInstance, NULL
            );
            hUd = CreateWindowEx(
                0, UPDOWN_CLASS, NULL,
                WS_VISIBLE | WS_CHILD |
                UDS_ALIGNRIGHT | UDS_ARROWKEYS | UDS_NOTHOUSANDS | UDS_AUTOBUDDY | UDS_HOTTRACK | UDS_SETBUDDYINT | UDS_AUTOBUDDY,
                0, 0, 0, 0,
                hwnd, NULL, ((LPCREATESTRUCT) lParam)->hInstance, NULL
            );

            SendMessage(hUd, UDM_SETRANGE, 0, 10 | 1 << 16);
            return 0;

        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
    }

    return DefWindowProc(hwnd, msg, wParam, lParam);
}

最佳答案

从编辑控件样式中删除WS_BORDER

关于c - 上下控制比伙伴高,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9180335/

10-09 00:24