bewegen???



  • wie kann ich mein window bewegen????



  • MoveWindow
    SetWindowPos

    steht alles in der MSDN.



  • Ich hab da mal ein paar nette Funktionen geschrieben, die das ganze etwas vereinfachen sollen:

    int GetWindowHeight(HWND hwnd)
    {
       RECT rc;
       GetWindowRect(hwnd, &rc);
       return rc.bottom - rc.top;
    }
    //---------------------------------------------------------------------------
    
    int GetWindowWidth(HWND hwnd)
    {
       RECT rc;
       GetWindowRect(hwnd, &rc);
       return rc.right - rc.left;
    }
    //---------------------------------------------------------------------------
    
    int GetWindowLeft(HWND hwnd)
    {
       RECT rc;
       HWND hParent = GetParent(hwnd);
    
       GetWindowRect(hwnd, &rc);
    
       if( IsChildWindow(hwnd) && hParent )
          ScreenToClient(hParent, (LPPOINT)&rc);
    
       return rc.left;
    }
    //---------------------------------------------------------------------------
    
    int GetWindowTop(HWND hwnd)
    {
       RECT rc;
       HWND hParent = GetParent(hwnd);
    
       GetWindowRect(hwnd, &rc);
    
       if( IsChildWindow(hwnd) && hParent )
          ScreenToClient(hParent, (LPPOINT)&rc);
    
       return rc.top;
    }
    //---------------------------------------------------------------------------
    
    VOID SetWindowHeight(HWND hwnd, int height)
    {
       RECT rc;
    
       GetWindowRect(hwnd, &rc);
       SetWindowPos(hwnd, NULL, 0, 0, rc.right - rc.left, height, SWP_NOMOVE | SWP_NOZORDER);
    }
    //---------------------------------------------------------------------------
    
    VOID SetWindowWidth(HWND hwnd, int width)
    {
       RECT rc;
    
       GetWindowRect(hwnd, &rc);
       SetWindowPos(hwnd, NULL, 0, 0, width, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER);
    }
    //---------------------------------------------------------------------------
    
    VOID SetWindowLeft(HWND hwnd, int left)
    {
       RECT rc;
       LPPOINT ppt;
       HWND hParent = GetParent(hwnd);
    
       GetWindowRect(hwnd, &rc);
    
       if( IsChildWindow(hwnd) && hParent )
       {
          ppt = (LPPOINT)&rc;
          ScreenToClient(hParent, ppt);
          ScreenToClient(hParent, ppt+1);
       }
    
       MoveWindow(hwnd, left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE);
    }
    //---------------------------------------------------------------------------
    
    VOID SetWindowTop(HWND hwnd, int top)
    {
       RECT rc;
       LPPOINT ppt;
       HWND hParent = GetParent(hwnd);
    
       GetWindowRect(hwnd, &rc);
    
       if( IsChildWindow(hwnd) && hParent )
       {
          ppt = (LPPOINT)&rc;
          ScreenToClient(hParent, ppt);
          ScreenToClient(hParent, ppt+1);
       }
    
       MoveWindow(hwnd, rc.left, top, rc.right - rc.left, rc.bottom - rc.top, TRUE);
    }
    //---------------------------------------------------------------------------
    
    VOID CenterWindow(HWND hwnd)
    {
       int screen_width  = GetSystemMetrics(SM_CXSCREEN);
       int screen_height = GetSystemMetrics(SM_CYSCREEN);
       int width = GetWindowWidth(hwnd);
       int height = GetWindowHeight(hwnd);
    
       MoveWindow(hwnd,
                  (screen_width - width) / 2,
                  (screen_height - height) / 2,
                  width,
                  height,
                  TRUE);
    }
    //---------------------------------------------------------------------------
    
    BOOL IsChildWindow(HWND hwnd)
    {
       return ( GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD );
    }
    


  • Ganz schön frech, zu behautpten, DU hättest diese Funktionen geschrieben!

    ABGESCHRIEBEN hast du sie, wie fast alles, was sich so auf deine HP findet. Sollen wir dir bei der Quellenfindung behilflich sein??



  • Ja bitte, WebFurzi. Gib mir die Quellen! 😃 Ist mir auch egal, was du denkst. Diese Funktionen sind von einer solchen Simplizität, dass sie jeder WinAPI-Anfänger nach der ersten Woche schreiben könnte. Sie sind nur recht hilfreich in einigen Situationen. Mir ist natürlich auch bewusst, dass du über das von mir oben genannte Niveau nie hinausgekommen bist.


Anmelden zum Antworten