如何得知FORM是否已最小化,最大化(100分)

  • 主题发起人 主题发起人 fanciex
  • 开始时间 开始时间
F

fanciex

Unregistered / Unconfirmed
GUEST, unregistred user!
最好还顺便告诉我如何让FORM最小化,恢复大小,最大化!thanks!
好像可发消息WM_ERASEBKGND 但不知如何用!
 
procedure TForm1.Button1Click(Sender: TObject);
begin
case form2.WindowState of
wsnormal: showmessage('normal');
wsmaximized:showmessage('max');
wsminimized:showmessage('min');
end;
end;
 
谢谢扳手!
如何恢复大小,最大化?
 
form2.WindowState:=wsnormal 原大小
form2.WindowState:=wsmaximized 最大化
form2.WindowState:=wsminimized 最小化
 
wsMinimize :form1.WindowState:=wsnormal;
这条不执行,下条很正常:
wsmaximized :form1.WindowState:=wsnormal;
奇怪!
 
全部源码,贴上来看看。
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, NMUDP, IdUDPServer, IdBaseComponent, IdComponent,
IdUDPBase, IdUDPClient, IdAntiFreezeBase, IdAntiFreeze, IDSOCKETHANDLE,
Grids, Menus,shellapi, ComCtrls, ImgList, xmldom, XMLIntf, msxmldom,
XMLDoc, Buttons;
const MY_MESSAGE = WM_USER + 100;

type
TForm1 = class(TForm)
Sendword: TEdit;
NMUDP1: TNMUDP;
Label1: TLabel;
name: TEdit;
Label2: TLabel;
remotehost: TEdit;
speaklist: TStringGrid;
sendto: TEdit;
MainMenu1: TMainMenu;
F1: TMenuItem;
Save1: TMenuItem;
Exit1: TMenuItem;
Help1: TMenuItem;
About1: TMenuItem;
SendStatic: TLabel;
PopupMenu1: TPopupMenu;
Saveasfile1: TMenuItem;
Sendtothem1: TMenuItem;
EXIT2: TMenuItem;
ListView1: TListView;
ImageList1: TImageList;
SendXML: TXMLDocument;
ReceivedXML: TXMLDocument;
Sendbutton: TSpeedButton;
Config1: TMenuItem;
Setup1: TMenuItem;
procedure sendbtClick(Sender: TObject);
procedure NMUDP1DataReceived(Sender: TComponent; NumberBytes: Integer;
FromIP: String; Port: Integer);
procedure FormCreate(Sender: TObject);
procedure speaklistDblClick(Sender: TObject);
procedure speaklistRowMoved(Sender: TObject; FromIndex,
ToIndex: Integer);
procedure Saveasfile1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure About1Click(Sender: TObject);
procedure EXIT2Click(Sender: TObject);
procedure Sendtothem1Click(Sender: TObject);
private
procedure OnIconNotify(var Message: TMessage);
message MY_MESSAGE;

{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
Busy: Boolean;
implementation

{$R *.dfm}
procedure TForm1.OnIconNotify(var Message: TMessage);

begin
if not Busy then
begin
Busy :=true;
if Message.LParam=WM_LBUTTONDOWN then
begin
form1.Show;
application.BringToFront;
sendmessage(form1.Handle,WM_ERASEBKGND,0,0);
end;
if Message.LParam=WM_RBUTTONDOWN then
begin
popupmenu1.Popup(mouse.CursorPos.X,mouse.CursorPos.Y);
end;
Busy := false;

end;

end;

procedure TForm1.sendbtClick(Sender: TObject);
var
MyStream: TMemoryStream;
// TmpStr: String;
tmpV:olevariant;
Begin
NMUDP1.ReportLevel := Status_Basic;
NMUDP1.RemoteHost := remotehost.Text;
sendxml.Active:=true;
tmpv:=sendword.Text;
sendxml.DocumentElement.NodeValue:=tmpv;

tmpv:=inttostr(sendword.Color);
sendxml.DocumentElement.Attributes['color']:=tmpv;
sendxml.DocumentElement.Attributes['to']:=sendto.Text;
sendxml.DocumentElement.Attributes['sendname']:=name.Text;
MyStream := TMemoryStream.Create;
sendxml.SaveToStream(mystream);

try
// MyStream.Write(TmpStr[1], Length(tmpstr));
NMUDP1.SendStream(MyStream);
sendstatic.Caption:='You sended To ['+sendto.Text+']:"'+sendword.Text+'" --Success!!';

finally
MyStream.Free;
end;
sendword.SetFocus;
end;

procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
MyStream: TMemoryStream;
// TmpStr: String;
fromname:string;
BeSend:string;
postword:string;
// s:integer;
// t:integer;
// w:integer;
begin
MyStream := TMemoryStream.Create;
try
NMUDP1.ReadStream(MyStream);
receivedxml.LoadFromStream(MyStream);
postword:=receivedxml.DocumentElement.NodeValue;
Fromname:=receivedxml.DocumentElement.Attributes['sendname'];
besend:=receivedxml.DocumentElement.Attributes['to'];
speaklist.RowCount:=speaklist.RowCount+1;
speaklist.Cells[0,speaklist.rowcount-2]:=fromip;
speaklist.cells[1,speaklist.RowCount-2]:=fromname;
speaklist.cells[2,speaklist.RowCount-2]:='['+fromname+'] To-['+besend+']: '+postword;
beep();
//sendmessage(speaklist.Handle,WM_VSCROLL,SB_BOTTOM,0);

finally
MyStream.Free;

end;

end;

procedure TForm1.FormCreate(Sender: TObject);
var
nid: TNotifyIconData;

begin
//hide taskbar 標題
//SetWindowLong(application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);
busy:=false;
nid.cbSize := sizeof(nid); // nid??????
nid.Wnd := Handle; // ?????
nid.uID:=4567;
nid.hIcon := Application.Icon.Handle; // ????????,?????
nid.szTip := 'LANICQ --- Design by DongPing.FAN;MiTAC LTD. JUN.2002'; // ?????
nid.uCallbackMessage := MY_MESSAGE; // ??????
nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // ????????

if not Shell_NotifyIcon(NIM_ADD,@nid) then begin
ShowMessage('Failed!');
Application.Terminate;
end;
{??????????TOOL??,??????????}
SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);

end;

procedure TForm1.speaklistDblClick(Sender: TObject);
var
i:integer;
//t:string;
begin
i:=speaklist.Selection.Top;
remotehost.Text:=speaklist.Cells[0,i];
sendto.Text:=speaklist.Cells[1,i];


end;

procedure TForm1.speaklistRowMoved(Sender: TObject; FromIndex,
ToIndex: Integer);
begin
speaklist.Canvas.Brush.Color:=234567;
end;

procedure TForm1.Saveasfile1Click(Sender: TObject);
var
//t:string;
i:integer;

begin


for i:=0 to speaklist.RowCount-1 do
begin

//t:=t+speaklist.Cols.Text;

end;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
nid: TNotifyIconData;
begin
nid.cbSize := sizeof(nid); // nid??????
nid.cbSize := sizeof(nid); // nid??????
nid.uID :=4567; //????,???????????
nid.Wnd := Handle; //?????
Shell_NotifyIcon(NIM_DELETE,@nid); //?????
Shell_NotifyIcon(NIM_DELETE,@nid); //?????
enD;

procedure TForm1.About1Click(Sender: TObject);
begin
SHOWMESSAGE('LANICQ--- Design by DongPing.Fan;MiTAC LTD. JUN.2002');
end;

procedure TForm1.EXIT2Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Sendtothem1Click(Sender: TObject);
begin
form1.SetFocus;
case form1.WindowState of
wsMinimized :form1.WindowState:=wsnormal;
// wsnormal :form1.WindowState:=wsnormal;
wsmaximized :form1.WindowState:=wsnormal;
//showmessage('minized')//
end;


end;

end.
代码:
 
To 扳手:你先去吃饭吧,thanks!
 
晕!这么长???
sendtothem1是个form1上菜单项,从这里看,你想在点击这个菜单项的时候
如果form1处于最大化状态,将它的窗口置为原大小。
那当他最小化的时候你怎么才能点击这个菜单呢?
没细读你的源码,太长了!可能是我不太明白你的意思。
 
呵呵,时差问题,我两点钟吃饭。 [:D]
 
这个菜单是在托盘区弹出来的,因我想当点击托盘图标便弹出form,像金山词霸。
但问题是最小化后弹不出form.
我在上海,你在国外还是北方?
 
我是在编一个自己用的局域网聊天程序
 
原来如此,那就只能用windows消息了。
我在北方。
 
我sendmessage()不会用啊!
 
找到现成的答案了, http://www.delphibbs.com/delphibbs/dispq.asp?lid=1209735
看看是否符合你的要求。
 
application.Restore
application.Minimize
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部