Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Низкоуровневое программирование > Win Api
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 09.09.2016, 10:15   #1
BLACK_RAIN
Форумчанин
 
Регистрация: 13.02.2012
Сообщений: 867
По умолчанию двигать окно static мышкой

Здравствуйте. Нужно перетаскивать static мышкой.
Код:
var
  cll : array of ttestClass;
  cl : ttestClass;
  
type
  ttestClass = class(TObject)
  public
    w : HWND;
    x : SmallInt;
    y : SmallInt;
    OldX : SmallInt;
    OldY : SmallInt;
    drag : Boolean;
    constructor Create(x,y : SmallInt; prt : HWND);
    destructor Destroy; override;
  end;

implementation

constructor ttestClass.Create(x,y: SmallInt; prt : HWND);
begin
  Self.x := x;
  Self.y := y;
        w := CreateWindowEx(WS_EX_CLIENTEDGE,'static','', WS_CHILD or WS_VISIBLE or SS_NOTIFY,
                     x,y, 100,100, prt, 0,HInstance,nil);

end;

destructor ttestClass.Destroy;
begin
  DestroyWindow(w);
  inherited;
end;

function FindClass(w : HWND): ttestClass;
var
  i :Byte;
begin
  for I := 0 to Length(cll)-1 do
  begin
    if w=cll[i].w then
    begin
      Result := cll[i];
      Exit;
    end;
  end;

end;

function AddClass(x,y : SmallInt; prt : HWND): ttestClass;
var
  n : Byte;
begin
  n := Length(cll);
  SetLength(cll,n+1);
  cll[n] := ttestClass.Create(x,y, prt);
  OldProc := SetWindowLong(cll[n].w, GWL_WNDPROC, LongInt(@proc1));
  Result := cll[n];
end;

procedure SetWindowText(w: HWND; t : string);
begin
  SendMessage(w,WM_SETTEXT,0,LongInt(PChar(t)));
end;

function Proc1(wnd:HWND; Msg : uint; Wpar:Wparam; Lpar:LPARAM):Lresult; stdcall;
var
  x,y : SmallInt;
  r :  TRect;
  p : ppoints;
  tp : TPoint;
Begin
  Result := 0;
  case msg of

    WM_NCHITTEST:
    begin
      Result  := callWindowProc(Pointer(OldProc),wnd,Msg,Wpar,Lpar);
      if Result = HTCLIENT then
      Result := HTCAPTION;
      Exit;
    end;

    WM_NCLBUTTONDOWN:
    begin
      cl := FindClass(wnd);
      P := ppoints(@Lpar);
      tp.X := p.x;
      tp.Y := p.y;
      ScreenToClient(wnd,tp);
      cl.Oldx := tp.X;
      cl.Oldy := tp.Y;
      SetWindowText(form1,IntToStr(tp.x)+', '+ IntToStr(tp.y));
//      SetCapture(cl.w);
      cl.drag := True;
      uuu := 0;
    end;

    WM_NCLBUTTONUP:
    begin
      if Assigned(cl) then
      cl.drag := False;
//      ReleaseCapture;
    end;

    WM_NCRBUTTONDOWN:
    begin
      SetWindowText(form1,'r button down');
    end;

    WM_NCMOUSEMOVE:
    if (Assigned(cl)) and (cl.drag) then
    begin
      P := ppoints(@Lpar);
      tp.X := p.x;
      tp.Y := p.y;
      ScreenToClient(wnd,tp);
      x := tp.X;
      y := tp.Y;
      cl.x := cl.x + x - cl.Oldx;
      cl.y := cl.y + y - cl.Oldy;
      SetWindowPos(cl.w,0,cl.x,cl.y,0,0, SWP_NOSIZE or SWP_NOZORDER);
      inc(uuu);
      SetWindowText(form1,IntToStr(uuu));
    end;

   else Result:=callWindowProc(Pointer(OldProc),wnd,msg,wpar,lpar);
  end;
End;

    WM_CREATE:
    begin
      j := 0;
      for I := 0 to 4 do
      begin
        j := i*100;
        AddClass(j,90,wnd);
      end;
    end;
Вроде работает. Но если делать ему SetCapture()/ReleaseCapture(), то перестают приходить сообщения WM_NCLBUTTONDOWN
WM_NCLBUTTONUP WM_NCMOUSEMOVE WM_NCRBUTTONDOWN и главное окно перестает реагировать на кнопки свернуть/развернуть/закрыть пока не снять фокус с главного окна.
Как же всё-таки двигать статик?

Последний раз редактировалось BLACK_RAIN; 09.09.2016 в 10:24.
BLACK_RAIN вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
таскать static по окну мышкой BLACK_RAIN Win Api 6 13.03.2016 16:31
C# Баг окно нельзя двигать при быстром рисовании bibiw_one C# (си шарп) 4 29.10.2015 11:54
static и non-static context kos1nus Общие вопросы по Java, Java SE, Kotlin 1 17.07.2013 00:10
Рисование STATIC мышкой Sylvos Win Api 1 23.02.2012 06:27
хочу мышкой двигать картинку на форме PaulRom Microsoft Office Access 8 25.11.2011 11:54