2012-02-07 15 views
1

平原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); 
} 
+0

難道是應用主題化? Windows 7中的按鈕(至少)在其窗口矩形內有一個像素「縫隙」。 – Deanna 2012-02-07 20:02:04

回答

1

刪除WS_BORDER從編輯控件樣式。

+0

謝謝你,僅此而已。 – AlexTei 2012-02-08 18:59:58