2012-01-23 5 views
4

나는 프레디 벨 (Freddie Bell)이 What is the best way to make a Delphi Application completely full screen? 질문에 게시 한 코드를 시도해 보았습니다.workarea에서 폼 플로트를 만드는 방법 (move, size, maximize, minimize)?

또한 최소 크기를 원래 크기로 설정합니다.

with msg.MinMaxInfo^.ptMinTrackSize do 
    begin 
     // maximum size when maximised 
     x := original_width; 
     y := original_height; 
    end; 

그리고 양식에서 onShow 이벤트

가 :

original_width := Width; 
    original_height := Height; 

하지만 난이 문제를 가지고 : - Mainform 두 개의 패널, 그 중 하나가 좋아, alLeft 같은 다른으로 정렬되어있다; 그래서 working_area는 패널 사이의 공간입니다. Mainform는 국경이없고 그것은 완전히 내가 양식을 이동할 때, 패널 사이의 working_area 내부에 유지

SystemParametersInfo(SPI_GETWORKAREA, 0, @working_desktop, 0); 
  • 와 함께 작업 영역에 maximizad된다.
  • 양식의 크기를 조정하면 해당 작업 영역 내에 유지됩니다.
  • 그러나 working_area의 가장자리를 지나가는 방식으로 (왼쪽 또는 오른쪽으로) 양식의 크기를 조정하면 양식의 크기가 다른쪽에 커집니다. 즉, 양식이 왼쪽 가장자리에 있고 크기를 선택하여 왼쪽으로 (가장자리쪽으로) 이동하면 양식의 너비가 오른쪽으로 증가합니다 (단, 오른쪽 가장자리에서 멈춤).

일부 코드 (WMSIZE 또는 WMSIZING)를 시도하지만 그 동작을 방지 할 수 있습니까? 미리 감사드립니다.

EDIT (David Heffernan) : 키 코드가이 장치에있는 것으로 보입니다.

unit uFormularios; 

interface 

uses Windows, Messages, Forms, DBGrids, StdCtrls, Menus, Graphics, ComCtrls; 

type 
    TForm_en_ventana = class(TForm) 
    private 
    ancho_original, alto_original: integer; 
    procedure WMShowWindow(var Message: TWMShowWindow); message WM_SHOWWINDOW; 
    procedure WMWindowPosChanging(Var Msg: TWMWindowPosChanging); Message WM_WINDOWPOSCHANGING; 
    procedure WMGetMinMaxInfo(Var msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO; 
    procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND; 
    end; 

    TForm_en_ventana_centrado = class(TForm_en_ventana) 
    private 
    ancho_original, alto_original: integer; 
    procedure WMShowWindow(var Message: TWMShowWindow); message WM_SHOWWINDOW; 
    end; 

procedure MaximizarFormulario(var F; MaximaAltura: integer = 0; MaximoAncho: integer = 0; Centrado: boolean = TRUE); 
procedure InicializarVentanaTrabajo(const izq, der, arr, aba: integer); 

var ESPACIO_DE_TRABAJO, 
    VENTANA_DE_TRABAJO  : TRect; 

implementation 


procedure MaximizarFormulario(var F; MaximaAltura: integer = 0; MaximoAncho: integer = 0; Centrado: boolean = TRUE); 
begin 
    LockWindowUpdate(TForm(F).Handle); 
    TForm(F).Left := ESPACIO_DE_TRABAJO.Left; 
    if MaximoAncho = 0 then 
    TForm(F).Width := ESPACIO_DE_TRABAJO.Right 
    else 
    begin 
     if ESPACIO_DE_TRABAJO.Right < MaximoAncho then 
     TForm(F).Width := ESPACIO_DE_TRABAJO.Right 
     else 
     TForm(F).Width := MaximoAncho; 
    end; 
    TForm(F).Top := ESPACIO_DE_TRABAJO.Top; 
    if MaximaAltura = 0 then 
    TForm(F).Height := ESPACIO_DE_TRABAJO.Bottom 
    else 
    begin 
     if ESPACIO_DE_TRABAJO.Bottom < MaximaAltura then 
     TForm(F).Height := ESPACIO_DE_TRABAJO.Bottom 
     else 
     TForm(F).Height := MaximaAltura; 
    end; 
    if ((MaximoAncho <> 0) or (MaximaAltura <> 0)) and (Centrado) then 
    begin 
     TForm(F).Left := (ESPACIO_DE_TRABAJO.Right - TForm(F).Width) div 2; 
     TForm(F).Top := (ESPACIO_DE_TRABAJO.Bottom - TForm(F).Height) div 2; 
    end; 
    LockWindowUpdate(0); 
end; 

procedure InicializarVentanaTrabajo(const izq, der, arr, aba: integer); 
begin 
    VENTANA_DE_TRABAJO.Left := izq; 
    VENTANA_DE_TRABAJO.Right := der; 
    VENTANA_DE_TRABAJO.Top := arr; 
    VENTANA_DE_TRABAJO.Bottom := aba; 
end; 

procedure TForm_en_ventana.WMWindowPosChanging(var Msg: TWMWINDOWPOSCHANGING); 
begin 
    with Msg.WindowPos^ do 
    { 
    x: int; The position of the left edge of the window. 
    y: int; The position of the top edge of the window. 
    cx: int; The window width, in pixels. 
    cy: int; The window height, in pixels. 
    } 
    begin 
    if x <= VENTANA_DE_TRABAJO.Left then 
     x := VENTANA_DE_TRABAJO.Left; 
    if x + cx >= VENTANA_DE_TRABAJO.Right then 
     x := (VENTANA_DE_TRABAJO.Right) - cx; 
    if y <= VENTANA_DE_TRABAJO.Top then 
     y := VENTANA_DE_TRABAJO.Top; 
    if y + cy >= VENTANA_DE_TRABAJO.Bottom then 
     y := (VENTANA_DE_TRABAJO.Bottom) - cy; 
    end; 
end; 

Procedure TForm_en_ventana.WMGetMinMaxInfo(Var msg: TWMGetMinMaxInfo); 
begin 
    inherited; 
    with msg.MinMaxInfo^.ptMaxPosition do 
    begin 
     // position of top when maximised 
     x := VENTANA_DE_TRABAJO.Left; 
     y := VENTANA_DE_TRABAJO.Top; 
    end; 
    with msg.MinMaxInfo^.ptMaxSize do 
    begin 
     // width and height when maximized 
     x := VENTANA_DE_TRABAJO.Right - VENTANA_DE_TRABAJO.Left; 
     y := VENTANA_DE_TRABAJO.Bottom - VENTANA_DE_TRABAJO.Top; 
    end; 
    with msg.MinMaxInfo^.ptMaxTrackSize do 
    begin 
     // maximum size when maximised 
     x := VENTANA_DE_TRABAJO.Right - VENTANA_DE_TRABAJO.Left; 
     y := VENTANA_DE_TRABAJO.Bottom - VENTANA_DE_TRABAJO.Top; 
    end; 
    with msg.MinMaxInfo^.ptMinTrackSize do 
    begin 
     // maximum size when maximised 
     x := ancho_original; 
     y := alto_original; 
    end; 
end; 

procedure TForm_en_ventana.WMSysCommand(var Msg: TWMSysCommand); 
begin 
    if Msg.CmdType and $FFF0 = SC_MINIMIZE then 
    Application.Minimize 
    else 
    inherited; 
end; 

procedure TForm_en_ventana.WMShowWindow(var Message: TWMShowWindow); 
begin 
    ancho_original := Width; 
    alto_original := Height; 
end; 

procedure TForm_en_ventana_centrado.WMShowWindow(var Message: TWMShowWindow); 
begin 
    ancho_original := Width; 
    alto_original := Height; 
    Left := (((VENTANA_DE_TRABAJO.Right - VENTANA_DE_TRABAJO.Left) - Width) div 2) + VENTANA_DE_TRABAJO.Left; 
    Top := (((VENTANA_DE_TRABAJO.Bottom - VENTANA_DE_TRABAJO.Top) - Height) div 2) + VENTANA_DE_TRABAJO.Top; 
end; 

initialization 
    SystemParametersInfo(SPI_GETWORKAREA, 0, @ESPACIO_DE_TRABAJO, 0); 
    VENTANA_DE_TRABAJO := ESPACIO_DE_TRABAJO; 

end. 
+0

나는 그 질문을 이해할 수 없다. –

+0

죄송합니다 게시물에 관련이 있습니다. 나는 코드를 게시 할 수있다 (나는 방법을 모른다). 당신이 그것을 볼 수 있다면 정말 간단합니다, 아마도 설명하기가 어려울 것입니다. 제 영어는 너무 많이 "me tarzan, you jane"입니다. :). 문제는 왼쪽 가장자리에서 양식의 크기를 조정하고 왼쪽 패널의 테두리 (작업 영역의 왼쪽 한계 설정)에 도달했을 때 마우스 단추를 놓지 않고 양식을 계속 크기 조정하지만 크기를 조절할 때 맞는 치수. – Speaker

+0

양식이 왼쪽으로 크기 조정을 멈추지 만 (왼쪽 한계에 도달 함) 오른쪽으로 너비를 늘립니다. – Speaker

답변

2

WM_WINDOWPOSCHANGING에 대한 귀하의 핸들러가 작업을 이동 괜찮지 만 작업을 크기에 따라 다를 수 필요가있다. 해당 메시지 처리기 내에서 메시지를 감지 할 수 없으므로 대체 메시지가 필요합니다. 대신이 같은 WM_SIZINGWM_MOVING를 사용

procedure WMSizing(Var msg: TMessage); message WM_SIZING; 
procedure WMMoving(Var msg: TMessage); message WM_MOVING; 

.... 

procedure TForm_en_ventana.WMSizing(var msg: TMessage); 
var 
    R: PRect; 
begin 
    R := PRect(msg.LParam); 
    R.Left := Max(R.Left, VENTANA_DE_TRABAJO.Left); 
    R.Right := Min(R.Right, VENTANA_DE_TRABAJO.Right); 
    R.Top := Max(R.Top, VENTANA_DE_TRABAJO.Top); 
    R.Bottom := Min(R.Bottom, VENTANA_DE_TRABAJO.Bottom); 
end; 

procedure TForm_en_ventana.WMMoving(var msg: TMessage); 
var 
    R: PRect; 
    dx, dy: Integer; 
begin 
    R := PRect(msg.LParam); 
    dx := 0; 
    dy := 0; 
    if R.Left<VENTANA_DE_TRABAJO.Left then 
    dx := VENTANA_DE_TRABAJO.Left-R.Left; 
    if R.Right>VENTANA_DE_TRABAJO.Right then 
    dx := VENTANA_DE_TRABAJO.Right-R.Right; 
    if R.Top<VENTANA_DE_TRABAJO.Top then 
    dy := VENTANA_DE_TRABAJO.Top-R.Top; 
    if R.Bottom>VENTANA_DE_TRABAJO.Bottom then 
    dy := VENTANA_DE_TRABAJO.Bottom-R.Bottom; 
    OffsetRect(R^, dx, dy); 
end; 

당신은 전부 WM_WINDOWPOSCHANGING을 제거해야합니다.

+0

그게 좋습니다! 감사합니다 @ 데이비드! – Speaker

+0

난 단지이 코드를 WMSHOWWINDOW 메시지에 추가'procedure TForm_en_ventana.WMShowWindow (var Message : TWMShowWindow); begin ancho_original : = Self.Width; alto_original : = Self.Height; Constraints.MinHeight : = height; Constraints.MinWidth : = width; end; ' – Speaker

+0

나는 그 의견에 무슨 뜻인지 모르겠다. 다른 질문을 하시겠습니까? –

관련 문제