2012-05-14 127 views

回答

3

你有幾個選項: -

  1. 創建一個父控件,並有一個孩子無邊界的文本編輯控件裏面
  2. 子類文本編輯控制和超負荷NC_PAINT繪製邊框

UPDATE

與樣本程序亂搞後,逐漸明白對我來說,子分類編輯控件並沒有真正的工作,並檢查在線確認(謝謝你MS是如此一致!)。

使剛剛離開方案1和方案3(只想到這一點):

  1. 創建自己的編輯控件

這裏的方法1的例子:

#include <windows.h> 

LRESULT __stdcall EditboxProc (HWND window, unsigned message, WPARAM w_param, LPARAM l_param) 
{ 
    bool 
    use_default = true; 

    LRESULT 
    result = 0; 

    switch (message) 
    { 
    case WM_CREATE: 
    { 
     RECT 
     client; 

     GetClientRect (window, &client); 

     HWND 
     edit = CreateWindowEx (0, 
           TEXT ("Edit"), 
           0, 
           WS_VISIBLE | WS_CHILD, 
           10, 
           10, 
           client.right - 20, 
           client.bottom - 20, 
           window, 
           0, 
           GetModuleHandle (0), 
           0); 

     SetWindowLongPtr (window, GWLP_USERDATA, static_cast <LONG> (reinterpret_cast <LONG_PTR> (edit))); 
    } 
    break; 

    case WM_SIZE: 
    { 
     RECT 
     client; 

     GetClientRect (window, &client); 
     SetWindowPos (reinterpret_cast <HWND> (static_cast <LONG_PTR> (GetWindowLongPtr (window, GWLP_USERDATA))), 0, 10, 10, client.right - 20, client.bottom - 20, SWP_NOZORDER | SWP_NOOWNERZORDER); 

     use_default = false; 
    } 
    break; 
    } 

    return use_default ? DefWindowProc (window, message, w_param, l_param) : result; 
} 

LRESULT __stdcall WindowProc (HWND window, unsigned message, WPARAM w_param, LPARAM l_param) 
{ 
    bool 
    use_default = true; 

    LRESULT 
    result = 0; 

    switch (message) 
    { 
    case WM_CREATE: 
    { 
     RECT 
     client; 

     GetClientRect (window, &client); 

     CreateWindowEx (0, 
         TEXT ("EditboxClass"), 
         0, 
         WS_VISIBLE | WS_CHILD, 
         client.right/4, 
         client.bottom/2 - 20, 
         client.right/2, 
         40, 
         window, 
         0, 
         GetModuleHandle (0), 
         0); 
    } 
    break; 
    } 

    return use_default ? DefWindowProc (window, message, w_param, l_param) : result; 
} 

int __stdcall WinMain (HINSTANCE instance, HINSTANCE prev_instance, LPSTR command_line, int show) 
{ 
    WNDCLASSEX 
    window_class = 
    { 
     sizeof window_class, 
     0, 
     WindowProc, 
     0, 
     0, 
     instance, 
     0, 
     0, 
     reinterpret_cast <HBRUSH> (static_cast <int> (COLOR_WINDOW) + 1), 
     0, 
     TEXT ("WindowClass"), 
     0 
    }, 
    editbox_class = 
    { 
     sizeof editbox_class, 
     0, 
     EditboxProc, 
     0, 
     0, 
     instance, 
     0, 
     0, 
     reinterpret_cast <HBRUSH> (static_cast <int> (COLOR_BTNFACE) + 1), 
     0, 
     TEXT ("EditboxClass"), 
     0 
    }; 

    if (RegisterClassEx (&window_class) && RegisterClassEx (&editbox_class)) 
    { 
    HWND 
     window = CreateWindowEx (0, 
           TEXT ("WindowClass"), 
           TEXT ("Demo"), 
           WS_OVERLAPPEDWINDOW | WS_VISIBLE, 
           CW_USEDEFAULT, 
           CW_USEDEFAULT, 
           CW_USEDEFAULT, 
           CW_USEDEFAULT, 
           0, 
           0, 
           instance, 
           0); 

    if (window) 
    { 
     MSG 
     message; 

     bool 
     quit = false; 

     while (!quit) 
     { 
     switch (GetMessage (&message, window, 0, 0)) 
     { 
     case -1: 
     case 0: 
      quit = true; 
      break; 

     default: 
      TranslateMessage (&message); 
      DispatchMessage (&message); 
      break; 
     } 
     } 
    } 
    } 

    return 0; 
} 

這是一個簡單的骨頭,但應該給你一些關於如何做你想要的想法。它不適用於使用資源腳本定義的對話框(我認爲,自從我手動編碼資源以來,已經有一段時間了),因爲它使用編輯框(呈現框架的內容)的父級的自定義控件。您可能需要添加處理程序到EditboxProc來處理編輯控件(如WM_NOTIFY,WM_COMMAND,WM_GETTEXT等)的傳遞消息並呈現圓角(WM_PAINT,WM_ERASEBKGND)。

+0

是否有可能,如果你可以指出一些例子或一些很好的資源 – anand

+0

@ Alien01:我沒有什麼東西要證明這一點,我無法在互聯網上找到任何東西。我會看看我是否可以把東西撞在一起。 – Skizz

+0

@ Alien01:東西在一起.... – Skizz