WM_SYSCOMMAND A window receives this message when the user chooses a command from the window menu (also known as the System menu or Control menu) or when the user chooses the Maximize button or Minimize button.WM_SYSCOMMAND uCmdType = wParam; // type of system command requested xPos = LOWORD(lParam); // horizontal postion, in screen coordinates yPos = HIWORD(lParam); // vertical postion, in screen coordinates
SC_MAXIMIZE
窗口最大化
SC_MINIMIZE
窗口最小化在Delphi中有很多其他种类消息,不一定能在MSDN中找到的!比如VCL自定义消息。
Windows, Messages, Forms;type
TForm1 = class(TForm)
private
{ Private declarations }
procedure wmsyscommand(var msg:Tmessage);message WM_syscommand; //最小化,最大化...等按钮单击消息
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.wmsyscommand(var msg:Tmessage);
begin
case msg.WParam of
SC_MAXIMIZE :
begin
ShowWindow(FindWindow('Shell_TrayWnd',nil),SW_SHOW);
Form1.Top := 0;
Form1.Left := 0;
Form1.Width := GetSystemMetrics(SM_CXSCREEN);
Form1.Height := GetSystemMetrics(SM_CYSCREEN);
end;
else
inherited; //响应其他消息 end;
end;
所有的程序,只要是Windows窗口类应用程序,都要有一个WinMain函数,它相当于标准C里面的main,希望能对你有所帮助。int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HACCEL hAccelTable; // 初始化全局字符串
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_FIRST, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance);//注册类 // 执行应用程序初始化:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
} hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_FIRST); // 主消息循环:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} return (int) msg.wParam;
}
A window receives this message when the user chooses a command from the window menu (also known as the System menu or Control menu) or when the user chooses the Maximize button or Minimize button.WM_SYSCOMMAND
uCmdType = wParam; // type of system command requested
xPos = LOWORD(lParam); // horizontal postion, in screen coordinates
yPos = HIWORD(lParam); // vertical postion, in screen coordinates