  | 
      
        
          2楼
          巨大八爪鱼
          2016-2-12 21:14
           
          
           
         
        https://social.msdn.microsoft.com/Forums/en-US/e5a9a559-fd77-421c-b076-284f83c1159c/resizing-windows-and-their-controls?forum=windowsgeneraldevelopmentissues 
       | 
    
    
        | 
      
        
          3楼
          巨大八爪鱼
          2016-2-13 21:59
          
          
           
         
        #include <Windows.h>
  #define SPLITTER_HEIGHT 4
  BOOL fDragMode = FALSE; int splitpos = 100, old_splitpos;
  void DrawXorBar(HDC hdc, int x1, int y1, int width, int height) {     static WORD dotPatternBmp[8] = {0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055};     HBITMAP hbmp = CreateBitmap(8, 8, 1, 1, dotPatternBmp);     HBRUSH hbr = CreatePatternBrush(hbmp);     SetBrushOrgEx(hdc, x1, y1, NULL);     HBRUSH hbrOld = (HBRUSH)SelectObject(hdc, hbr);     PatBlt(hdc, x1, y1, width, height, PATINVERT);     SelectObject(hdc, hbrOld);     DeleteObject(hbr);     DeleteObject(hbmp); }
  void DrawXorBar(HWND hWnd, HDC hdc, int pos) {     RECT rcClient;     GetClientRect(hWnd, &rcClient);     DrawXorBar(hdc, rcClient.left, pos, rcClient.right - rcClient.left, SPLITTER_HEIGHT); }
  LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {     HDC hdc;     switch (uMsg)     {     case WM_DESTROY:         PostQuitMessage(0);         break;     case WM_LBUTTONDOWN:         fDragMode = TRUE;         SetCapture(hWnd);                  hdc = GetDC(hWnd);         DrawXorBar(hWnd, hdc, splitpos);         ReleaseDC(hWnd, hdc);         DeleteDC(hdc);
          old_splitpos = splitpos;         break;     case WM_LBUTTONUP:         if (fDragMode == TRUE)         {             fDragMode = FALSE;             ReleaseCapture();
              hdc = GetDC(hWnd);             DrawXorBar(hWnd, hdc, old_splitpos);             ReleaseDC(hWnd, hdc);             DeleteDC(hdc);         }         break;     case WM_MOUSEMOVE:         if (fDragMode == TRUE)         {             POINT pos;             GetCursorPos(&pos);             ScreenToClient(hWnd, &pos);             splitpos = pos.y;             hdc = GetDC(hWnd);             DrawXorBar(hWnd, hdc, old_splitpos);             DrawXorBar(hWnd, hdc, splitpos);             ReleaseDC(hWnd, hdc);             DeleteDC(hdc);             old_splitpos = splitpos;         }         break;     default:         return DefWindowProc(hWnd, uMsg, wParam, lParam);     }     return FALSE; }
  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {     WNDCLASS wc;     wc.cbClsExtra = wc.cbWndExtra = 0;     wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);     wc.hCursor = LoadCursor(NULL, IDC_SIZENS);     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);     wc.hInstance = hInstance;     wc.lpfnWndProc = WndProc;     wc.lpszClassName = "Splitter Example";     wc.lpszMenuName = NULL;     wc.style = NULL;     RegisterClass(&wc);
      HWND hWnd = CreateWindow(wc.lpszClassName, "Splitter", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);     if (!hWnd)         return 1;     ShowWindow(hWnd, nCmdShow);     UpdateWindow(hWnd);
      MSG msg;     while (GetMessage(&msg, NULL, 0, 0))     {         TranslateMessage(&msg);         DispatchMessage(&msg);     }     return msg.wParam; } 
       | 
    
    
        | 
      
        
          5楼
          巨大八爪鱼
          2016-2-14 19:02
          
          
           
         
        【補充】 ReleaseDC(hWnd, hdc); 後面的DeleteDC(hdc);要去掉
  
       |