给出Delhpi代码如下:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;type
  TForm1 = class(TForm)
    procedure WmNcHitTest(var msg:TWmNcHitTest);message wm_NcHitTest;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.WmNcHitTest(var msg:TWmNcHitTest);varpt:tpoint;begin     pt:=point(msg.xpos,msg.ypos);
     pt:=ScreentoClient(pt);
     if (pt.x>width-5) then
         msg.Result:=htright
     else
         inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
     BorderStyle := bsNone;
end;end.
求教高人,为什么在vc下ONHitTest函数下写类似功能的代码无效?
在VC下这样的功能又如何实现呢?

解决方案 »

  1.   

    void CMyDlg::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    if (!m_bInWindow)
    {
    //鼠标指针从窗口外进入窗口的时候,设定一个离开监控,并且将窗口类的鼠标指针设为空
    TRACKMOUSEEVENT TrackEvent;
    ZeroMemory(&TrackEvent, sizeof(TRACKMOUSEEVENT));
    TrackEvent.cbSize = sizeof (TRACKMOUSEEVENT);
    TrackEvent.dwFlags = TME_LEAVE;
    TrackEvent.hwndTrack = m_hWnd;
    _TrackMouseEvent(&TrackEvent);
    m_bInWindow = TRUE;
    if (GetClassLong(m_hWnd, GCL_HCURSOR))
    SetClassLong(m_hWnd, GCL_HCURSOR, NULL);
    }
    CDialog::OnMouseMove(nFlags, point);
    if (nFlags & MK_LBUTTON)
    {
    HandleSize(point);
    }
    else
    {
    HandleCursor(point);
    }
    //处理窗口改变时产生的刷新消息
    MSG msg;
    while(::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
    if (msg.hwnd != m_hWnd || msg.message != WM_MOUSEMOVE)
    DispatchMessage(&msg);
    }
    }
    int CMyDlg::HandleSize(CPoint point)
    {
    CPoint ptScreen = point;
    ClientToScreen(&ptScreen);
    CRect rc, rcWindow;
    //根据上一点坐标确定偏移的SIZE
    CSize size = ptScreen - m_ptLast;
    if (size.cx ==0 && size.cy== 0)
    return 0;
    rc = m_BackInfo.rc;
    int up = m_BackInfo.iUP;
    GetWindowRect(rcWindow);
    //改变位置和大小——rcWindow是指位置起作用的是左上角,rc是指窗口的大小
    switch (m_eSizeMode)
    {
    case SizeLeftTop:
    rcWindow.left += size.cx;
    rcWindow.top += size.cy;
    rc.right -= size.cx;
    rc.bottom -= size.cy;
    m_BackInfo.iUP -= size.cy;
    break;
    case SizeLeftBottom:
    rcWindow.left += size.cx;
    rc.right -= size.cx;
    rc.bottom += size.cy;
    m_BackInfo.iUP += size.cy;
    break;
    case SizeRightTop:
    rcWindow.top += size.cy;
    rc.right += size.cx;
    rc.bottom -= size.cy;
    m_BackInfo.iUP -= size.cy;
    break;
    case SizeRightBottom:
    rc.right += size.cx;
    rc.bottom += size.cy;
    m_BackInfo.iUP += size.cy;
    break;
    case SizeLeft:
    rcWindow.left += size.cx;
    rc.right -= size.cx;
    break;
    case SizeTop:
    rcWindow.top += size.cy;
    rc.bottom -= size.cy;
    m_BackInfo.iUP -= size.cy;
    break;
    case SizeRight:
    rc.right += size.cx;
    break;
    case SizeBottom:
    rc.bottom += size.cy;
    m_BackInfo.iUP += size.cy;
    break;
    case SizeMid:
    m_BackInfo.iUP += size.cy;
    break;
    default:
    return 0;
    }
    //边界检查
    if (rc.Width() < 300 || rc.Height() < 300 || rc.bottom - m_BackInfo.sizeTopLeft.cy - m_BackInfo.iUP - m_BackInfo.sizeMidLeft.cy - m_BackInfo.sizeBottomLeft.cy < 28)
    {
    m_BackInfo.iUP = up;
    return -1;
    }
    m_ptLast = ptScreen;
    //这两句好像可以去掉
    if (m_eSizeMode == SizeMid)
    ResetCtrlPos();
    //重新生成窗口
    CombineWindow(CPoint(rcWindow.left, rcWindow.top), rc);
    Invalidate(FALSE);
    UpdateWindow();
    return 0;
    }
    void CMyDlg::HandleCursor(CPoint point)
    {
    if (PtInRect(&m_BackInfo.rcLeftTopEdge, point))
    {
    m_eSizeMode = SizeLeftTop;
    SetCursor(LoadCursor(NULL,  MAKEINTRESOURCE(IDC_SIZENWSE)));
    }
    else if (PtInRect(&m_BackInfo.rcRightTopEdge, point))
    {
    m_eSizeMode = SizeRightTop;
    SetCursor(LoadCursor(NULL,  MAKEINTRESOURCE(IDC_SIZENESW)));
    }
    else if (PtInRect(&m_BackInfo.rcLeftBottomEdge, point))
    {
    m_eSizeMode = SizeLeftBottom;
    SetCursor(LoadCursor(NULL,  MAKEINTRESOURCE(IDC_SIZENESW)));
    }
    else if (PtInRect(&m_BackInfo.rcRightBottomEdge, point))
    {
    m_eSizeMode = SizeRightBottom;
    SetCursor(LoadCursor(NULL,  MAKEINTRESOURCE(IDC_SIZENWSE)));
    }
    else if (PtInRect(&m_BackInfo.rcLeftEdge, point))
    {
    m_eSizeMode = SizeLeft;
    SetCursor(LoadCursor(NULL,  MAKEINTRESOURCE(IDC_SIZEWE)));
    }
    else if (PtInRect(&m_BackInfo.rcTopEdge, point))
    {
    m_eSizeMode = SizeTop;
    SetCursor(LoadCursor(NULL,  MAKEINTRESOURCE(IDC_SIZENS)));
    }
    else if (PtInRect(&m_BackInfo.rcRightEdge, point))
    { m_eSizeMode = SizeRight;
    SetCursor(LoadCursor(NULL,  MAKEINTRESOURCE(IDC_SIZEWE)));
    }
    else if (PtInRect(&m_BackInfo.rcBottomEdge, point))
    {
    m_eSizeMode = SizeBottom;
    SetCursor(LoadCursor(NULL,  MAKEINTRESOURCE(IDC_SIZENS)));
    }
    else if (PtInRect(&m_BackInfo.rcMid, point))
    {
    m_eSizeMode = SizeMid;
    SetCursor(LoadCursor(NULL,  MAKEINTRESOURCE(IDC_SIZENS)));
    }
    else
    {
    m_eSizeMode = SizeNULL;
    SetCursor(LoadCursor(NULL,  MAKEINTRESOURCE(IDC_ARROW)));
    }
    }
      

  2.   

    LRESULT CMyDlg::OnMouseLeave(WPARAM wparam, LPARAM lparam)
    {
    //将窗口类指针设为原来的
    SetClassLong(m_hWnd, GCL_HCURSOR, (long)LoadCursor(NULL,  MAKEINTRESOURCE(IDC_ARROW)));
    m_bInWindow = FALSE;
    return 0;
    }
    void CMyDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    if (m_eSizeMode != SizeNULL)
    {
    SetCapture();
    POINT pt;
    GetCursorPos(&pt);
    m_ptLast = pt;
    }
    else
    PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x,point.y));
    //CDialog::OnLButtonDown(nFlags, point);
    }
    void CMyDlg::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    if (GetCapture() == this)
    ReleaseCapture();
    //在鼠标抬起的时候再改变一次大小
    HandleSize(point);
    CDialog::OnLButtonUp(nFlags, point);
    }