procedure WMNCHitTest(var M: TWMNCHITTEST); message wm_nchittest;
procedure tform1.WMNCHitTest(var M: TWMNCHITTEST);
begin
inherited;
IF M.Result =HTCLIENT THEN
M.RESULT:=HTCAPTION;
end;
我仿照上面的程序实现在窗休上按下鼠标来最大化、最小化和关闭窗口。都失败了。
procedure WMNCHitTest(var M: TWMNCHITTEST); message wm_nchittest;
procedure tform1.WMNCHitTest(var M: TWMNCHITTEST);
begin
inherited;
IF M.Result =HTCLIENT THEN
M.RESULT:=HTMAXBUTTON; //HTMINBUTTON,最大化 HTCLOSE 关闭
end;
help me!!!!!!!!!!!!!!!!!!!!!
11 个解决方案
#1
最大化
showwindow(form1.Handle,SW_SHOWMAXIMIZED);
最小化
showwindow(form1.Handle,SW_SHOWMAXIMIZED);
showwindow(form1.Handle,SW_SHOWMAXIMIZED);
最小化
showwindow(form1.Handle,SW_SHOWMAXIMIZED);
#2
错了
最小化是
showwindow(form1.Handle,SW_SHOWMINIMIZED);
最小化是
showwindow(form1.Handle,SW_SHOWMINIMIZED);
#3
buttonClick事件加上;
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
#4
WM_SYSCOMMAND
A window receives this message when the user chooses a command from the window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.
A window receives this message through its WindowProc function.
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_SYSCOMMAND
WPARAM wParam, // system command type
LPARAM lParam // horizontal and vertical position
);
Parameters
wParam
Specifies the type of system command requested. This parameter can be one of the following values. Value Meaning
SC_CLOSE Closes the window. //////这里,关闭的消息!!!!
SC_CONTEXTHELP Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message.
SC_DEFAULT Selects the default item; the user double-clicked the window menu.
SC_HOTKEY Activates the window associated with the application-specified hot key. The lParam parameter identifies the window to activate.
SC_HSCROLL Scrolls horizontally.
SC_KEYMENU Retrieves the window menu as a result of a keystroke. For more information, see the Remarks section.
SC_MAXIMIZE Maximizes the window. //////这里,最大化的消息
SC_MINIMIZE Minimizes the window. //////这里,最小化的消息
SC_MONITORPOWER Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
The lParam parameter can have the following values:
1 - the display is going to low power
2 - the display is being shut off
SC_MOUSEMENU Retrieves the window menu as a result of a mouse click.
SC_MOVE Moves the window.
SC_NEXTWINDOW Moves to the next window.
SC_PREVWINDOW Moves to the previous window.
SC_RESTORE Restores the window to its normal position and size.
SC_SCREENSAVE Executes the screen saver application specified in the [boot] section of the System.ini file.
SC_SIZE Sizes the window.
SC_TASKLIST Activates the Start menu.
SC_VSCROLL Scrolls vertically.
lParam
The low-order word specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, this parameter is not used.
The high-order word specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. This parameter is –1 if the command is chosen using a system accelerator, or zero if using a mnemonic.
Return Values
An application should return zero if it processes this message.
Remarks
To obtain the position coordinates in screen coordinates, use the following code:
xPos = GET_X_LPARAM(lParam); // horizontal position
yPos = GET_Y_LPARAM(lParam); // vertical position
The DefWindowProc function carries out the window menu request for the predefined actions specified in the previous table.
In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are used internally by the system. To obtain the correct result when testing the value of wParam, an application must combine the value 0xFFF0 with the wParam value by using the bitwise AND operator.
The menu items in a window menu can be modified by using the GetSystemMenu, AppendMenu, InsertMenu, ModifyMenu, InsertMenuItem, and SetMenuItem functions. Applications that modify the window menu must process WM_SYSCOMMAND messages.
An application can carry out any system command at any time by passing a WM_SYSCOMMAND message to DefWindowProc. Any WM_SYSCOMMAND messages not handled by the application must be passed to DefWindowProc. Any command values added by an application must be processed by the application and cannot be passed to DefWindowProc.
Accelerator keys that are defined to choose items from the window menu are translated into WM_SYSCOMMAND messages; all other accelerator keystrokes are translated into WM_COMMAND messages.
If the wParam is SC_KEYMENU, lParam contains the character code of the key that is used with the ALT key to display the popup menu. For example, pressing ALT+F to display the File popup will cause a WM_SYSCOMMAND with wParam equal to SC_KEYMENU and lParam equal to 'f'.
Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winuser.h; include Windows.h.
A window receives this message when the user chooses a command from the window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.
A window receives this message through its WindowProc function.
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_SYSCOMMAND
WPARAM wParam, // system command type
LPARAM lParam // horizontal and vertical position
);
Parameters
wParam
Specifies the type of system command requested. This parameter can be one of the following values. Value Meaning
SC_CLOSE Closes the window. //////这里,关闭的消息!!!!
SC_CONTEXTHELP Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message.
SC_DEFAULT Selects the default item; the user double-clicked the window menu.
SC_HOTKEY Activates the window associated with the application-specified hot key. The lParam parameter identifies the window to activate.
SC_HSCROLL Scrolls horizontally.
SC_KEYMENU Retrieves the window menu as a result of a keystroke. For more information, see the Remarks section.
SC_MAXIMIZE Maximizes the window. //////这里,最大化的消息
SC_MINIMIZE Minimizes the window. //////这里,最小化的消息
SC_MONITORPOWER Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
The lParam parameter can have the following values:
1 - the display is going to low power
2 - the display is being shut off
SC_MOUSEMENU Retrieves the window menu as a result of a mouse click.
SC_MOVE Moves the window.
SC_NEXTWINDOW Moves to the next window.
SC_PREVWINDOW Moves to the previous window.
SC_RESTORE Restores the window to its normal position and size.
SC_SCREENSAVE Executes the screen saver application specified in the [boot] section of the System.ini file.
SC_SIZE Sizes the window.
SC_TASKLIST Activates the Start menu.
SC_VSCROLL Scrolls vertically.
lParam
The low-order word specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, this parameter is not used.
The high-order word specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. This parameter is –1 if the command is chosen using a system accelerator, or zero if using a mnemonic.
Return Values
An application should return zero if it processes this message.
Remarks
To obtain the position coordinates in screen coordinates, use the following code:
xPos = GET_X_LPARAM(lParam); // horizontal position
yPos = GET_Y_LPARAM(lParam); // vertical position
The DefWindowProc function carries out the window menu request for the predefined actions specified in the previous table.
In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are used internally by the system. To obtain the correct result when testing the value of wParam, an application must combine the value 0xFFF0 with the wParam value by using the bitwise AND operator.
The menu items in a window menu can be modified by using the GetSystemMenu, AppendMenu, InsertMenu, ModifyMenu, InsertMenuItem, and SetMenuItem functions. Applications that modify the window menu must process WM_SYSCOMMAND messages.
An application can carry out any system command at any time by passing a WM_SYSCOMMAND message to DefWindowProc. Any WM_SYSCOMMAND messages not handled by the application must be passed to DefWindowProc. Any command values added by an application must be processed by the application and cannot be passed to DefWindowProc.
Accelerator keys that are defined to choose items from the window menu are translated into WM_SYSCOMMAND messages; all other accelerator keystrokes are translated into WM_COMMAND messages.
If the wParam is SC_KEYMENU, lParam contains the character code of the key that is used with the ALT key to display the popup menu. For example, pressing ALT+F to display the File popup will cause a WM_SYSCOMMAND with wParam equal to SC_KEYMENU and lParam equal to 'f'.
Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winuser.h; include Windows.h.
#5
同意菠菜!!
buttonClick事件加上;
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
buttonClick事件加上;
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
buttonClick事件加上;
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
buttonClick事件加上;
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
#6
关闭: SendMessage(Form1.Handle,Wm_syscommand,SC_CLOSE,0);
最大化: SendMessage(Form1.Handle,Wm_syscommand,SC_MAXIMIZE,0);
最小化: SendMessage(Form1.Handle,Wm_syscommand,SC_MINIMIZE,0);
最大化: SendMessage(Form1.Handle,Wm_syscommand,SC_MAXIMIZE,0);
最小化: SendMessage(Form1.Handle,Wm_syscommand,SC_MINIMIZE,0);
#7
我的意思是用拦截消息的方法。
就是 你在窗休上按下鼠标左键并释放,就相当于按了一下窗休上的关闭按钮 或 最小化按钮 或 最大化按钮
就是 你在窗休上按下鼠标左键并释放,就相当于按了一下窗休上的关闭按钮 或 最小化按钮 或 最大化按钮
#8
大家都到齊了啊
#9
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
Parameters
uCmdType
Specifies the type of system command requested. This can be one of these values:
Value Meaning
SC_CLOSE Closes the window.
SC_CONTEXTHELP Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message.
SC_DEFAULT Selects the default item; the user double-clicked the window menu.
SC_HOTKEY Activates the window associated with the application-specified hot key. The low-order word of lParam identifies the window to activate.
SC_HSCROLL Scrolls horizontally.
SC_KEYMENU Retrieves the window menu as a result of a keystroke.
SC_MAXIMIZE (or SC_ZOOM) Maximizes the window.
SC_MINIMIZE (or SC_ICON) Minimizes the window.
SC_MONITORPOWER Windows 95 only: Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
SC_MOUSEMENU Retrieves the window menu as a result of a mouse click.
SC_MOVE Moves the window.
SC_NEXTWINDOW Moves to the next window.
SC_PREVWINDOW Moves to the previous window.
SC_RESTORE Restores the window to its normal position and size.
SC_SCREENSAVE Executes the screen saver application specified in the [boot] section of the SYSTEM.INI file.
SC_SIZE Sizes the window.
SC_TASKLIST Executes or activates Windows Task Manager.
SC_VSCROLL Scrolls vertically.
xPos
Specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, the xPos parameter is not used.
yPos
Specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. This parameter is -1 if the command is chosen using a system accelerator, or zero if using a mnenomic.
Return Values
An application should return zero if it processes this message.
Remarks
The DefWindowProc function carries out the window menu request for the predefined actions specified in the previous table.
In WM_SYSCOMMAND messages, the four low-order bits of the uCmdType parameter are used internally by Windows. To obtain the correct result when testing the value of uCmdType, an application must combine the value 0xFFF0 with the uCmdType value by using the bitwise AND operator.
The menu items in a window menu can be modified by using the GetSystemMenu, AppendMenu, InsertMenu, ModifyMenu, InsertMenuItem, and SetMenuItem functions. Applications that modify the window menu must process WM_SYSCOMMAND messages.
An application can carry out any system command at any time by passing a WM_SYSCOMMAND message to DefWindowProc. Any WM_SYSCOMMAND messages not handled by the application must be passed to DefWindowProc. Any command values added by an application must be processed by the application and cannot be passed to DefWindowProc.
Accelerator keys that are defined to choose items from the window menu are translated into WM_SYSCOMMAND messages; all other accelerator keystrokes are translated into WM_COMMAND messages.
See Also
AppendMenu, DefWindowProc, GetSystemMenu, InsertMenu, ModifyMenu, WM_COMMAND
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
Parameters
uCmdType
Specifies the type of system command requested. This can be one of these values:
Value Meaning
SC_CLOSE Closes the window.
SC_CONTEXTHELP Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message.
SC_DEFAULT Selects the default item; the user double-clicked the window menu.
SC_HOTKEY Activates the window associated with the application-specified hot key. The low-order word of lParam identifies the window to activate.
SC_HSCROLL Scrolls horizontally.
SC_KEYMENU Retrieves the window menu as a result of a keystroke.
SC_MAXIMIZE (or SC_ZOOM) Maximizes the window.
SC_MINIMIZE (or SC_ICON) Minimizes the window.
SC_MONITORPOWER Windows 95 only: Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
SC_MOUSEMENU Retrieves the window menu as a result of a mouse click.
SC_MOVE Moves the window.
SC_NEXTWINDOW Moves to the next window.
SC_PREVWINDOW Moves to the previous window.
SC_RESTORE Restores the window to its normal position and size.
SC_SCREENSAVE Executes the screen saver application specified in the [boot] section of the SYSTEM.INI file.
SC_SIZE Sizes the window.
SC_TASKLIST Executes or activates Windows Task Manager.
SC_VSCROLL Scrolls vertically.
xPos
Specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, the xPos parameter is not used.
yPos
Specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. This parameter is -1 if the command is chosen using a system accelerator, or zero if using a mnenomic.
Return Values
An application should return zero if it processes this message.
Remarks
The DefWindowProc function carries out the window menu request for the predefined actions specified in the previous table.
In WM_SYSCOMMAND messages, the four low-order bits of the uCmdType parameter are used internally by Windows. To obtain the correct result when testing the value of uCmdType, an application must combine the value 0xFFF0 with the uCmdType value by using the bitwise AND operator.
The menu items in a window menu can be modified by using the GetSystemMenu, AppendMenu, InsertMenu, ModifyMenu, InsertMenuItem, and SetMenuItem functions. Applications that modify the window menu must process WM_SYSCOMMAND messages.
An application can carry out any system command at any time by passing a WM_SYSCOMMAND message to DefWindowProc. Any WM_SYSCOMMAND messages not handled by the application must be passed to DefWindowProc. Any command values added by an application must be processed by the application and cannot be passed to DefWindowProc.
Accelerator keys that are defined to choose items from the window menu are translated into WM_SYSCOMMAND messages; all other accelerator keystrokes are translated into WM_COMMAND messages.
See Also
AppendMenu, DefWindowProc, GetSystemMenu, InsertMenu, ModifyMenu, WM_COMMAND
#10
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure WndProc(var aMessage : TMessage); override;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
procedure TForm1.WndProc(var aMessage: TMessage);
begin
inherited;
if aMessage.Msg = WM_LBUTTONDOWN then
begin
SendMessage(Handle,WM_CLOSE, 0, 0); //关闭窗口
end;
end;
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure WndProc(var aMessage : TMessage); override;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
procedure TForm1.WndProc(var aMessage: TMessage);
begin
inherited;
if aMessage.Msg = WM_LBUTTONDOWN then
begin
SendMessage(Handle,WM_CLOSE, 0, 0); //关闭窗口
end;
end;
#11
^Z
#1
最大化
showwindow(form1.Handle,SW_SHOWMAXIMIZED);
最小化
showwindow(form1.Handle,SW_SHOWMAXIMIZED);
showwindow(form1.Handle,SW_SHOWMAXIMIZED);
最小化
showwindow(form1.Handle,SW_SHOWMAXIMIZED);
#2
错了
最小化是
showwindow(form1.Handle,SW_SHOWMINIMIZED);
最小化是
showwindow(form1.Handle,SW_SHOWMINIMIZED);
#3
buttonClick事件加上;
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
#4
WM_SYSCOMMAND
A window receives this message when the user chooses a command from the window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.
A window receives this message through its WindowProc function.
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_SYSCOMMAND
WPARAM wParam, // system command type
LPARAM lParam // horizontal and vertical position
);
Parameters
wParam
Specifies the type of system command requested. This parameter can be one of the following values. Value Meaning
SC_CLOSE Closes the window. //////这里,关闭的消息!!!!
SC_CONTEXTHELP Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message.
SC_DEFAULT Selects the default item; the user double-clicked the window menu.
SC_HOTKEY Activates the window associated with the application-specified hot key. The lParam parameter identifies the window to activate.
SC_HSCROLL Scrolls horizontally.
SC_KEYMENU Retrieves the window menu as a result of a keystroke. For more information, see the Remarks section.
SC_MAXIMIZE Maximizes the window. //////这里,最大化的消息
SC_MINIMIZE Minimizes the window. //////这里,最小化的消息
SC_MONITORPOWER Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
The lParam parameter can have the following values:
1 - the display is going to low power
2 - the display is being shut off
SC_MOUSEMENU Retrieves the window menu as a result of a mouse click.
SC_MOVE Moves the window.
SC_NEXTWINDOW Moves to the next window.
SC_PREVWINDOW Moves to the previous window.
SC_RESTORE Restores the window to its normal position and size.
SC_SCREENSAVE Executes the screen saver application specified in the [boot] section of the System.ini file.
SC_SIZE Sizes the window.
SC_TASKLIST Activates the Start menu.
SC_VSCROLL Scrolls vertically.
lParam
The low-order word specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, this parameter is not used.
The high-order word specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. This parameter is –1 if the command is chosen using a system accelerator, or zero if using a mnemonic.
Return Values
An application should return zero if it processes this message.
Remarks
To obtain the position coordinates in screen coordinates, use the following code:
xPos = GET_X_LPARAM(lParam); // horizontal position
yPos = GET_Y_LPARAM(lParam); // vertical position
The DefWindowProc function carries out the window menu request for the predefined actions specified in the previous table.
In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are used internally by the system. To obtain the correct result when testing the value of wParam, an application must combine the value 0xFFF0 with the wParam value by using the bitwise AND operator.
The menu items in a window menu can be modified by using the GetSystemMenu, AppendMenu, InsertMenu, ModifyMenu, InsertMenuItem, and SetMenuItem functions. Applications that modify the window menu must process WM_SYSCOMMAND messages.
An application can carry out any system command at any time by passing a WM_SYSCOMMAND message to DefWindowProc. Any WM_SYSCOMMAND messages not handled by the application must be passed to DefWindowProc. Any command values added by an application must be processed by the application and cannot be passed to DefWindowProc.
Accelerator keys that are defined to choose items from the window menu are translated into WM_SYSCOMMAND messages; all other accelerator keystrokes are translated into WM_COMMAND messages.
If the wParam is SC_KEYMENU, lParam contains the character code of the key that is used with the ALT key to display the popup menu. For example, pressing ALT+F to display the File popup will cause a WM_SYSCOMMAND with wParam equal to SC_KEYMENU and lParam equal to 'f'.
Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winuser.h; include Windows.h.
A window receives this message when the user chooses a command from the window menu (formerly known as the system or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.
A window receives this message through its WindowProc function.
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_SYSCOMMAND
WPARAM wParam, // system command type
LPARAM lParam // horizontal and vertical position
);
Parameters
wParam
Specifies the type of system command requested. This parameter can be one of the following values. Value Meaning
SC_CLOSE Closes the window. //////这里,关闭的消息!!!!
SC_CONTEXTHELP Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message.
SC_DEFAULT Selects the default item; the user double-clicked the window menu.
SC_HOTKEY Activates the window associated with the application-specified hot key. The lParam parameter identifies the window to activate.
SC_HSCROLL Scrolls horizontally.
SC_KEYMENU Retrieves the window menu as a result of a keystroke. For more information, see the Remarks section.
SC_MAXIMIZE Maximizes the window. //////这里,最大化的消息
SC_MINIMIZE Minimizes the window. //////这里,最小化的消息
SC_MONITORPOWER Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
The lParam parameter can have the following values:
1 - the display is going to low power
2 - the display is being shut off
SC_MOUSEMENU Retrieves the window menu as a result of a mouse click.
SC_MOVE Moves the window.
SC_NEXTWINDOW Moves to the next window.
SC_PREVWINDOW Moves to the previous window.
SC_RESTORE Restores the window to its normal position and size.
SC_SCREENSAVE Executes the screen saver application specified in the [boot] section of the System.ini file.
SC_SIZE Sizes the window.
SC_TASKLIST Activates the Start menu.
SC_VSCROLL Scrolls vertically.
lParam
The low-order word specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, this parameter is not used.
The high-order word specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. This parameter is –1 if the command is chosen using a system accelerator, or zero if using a mnemonic.
Return Values
An application should return zero if it processes this message.
Remarks
To obtain the position coordinates in screen coordinates, use the following code:
xPos = GET_X_LPARAM(lParam); // horizontal position
yPos = GET_Y_LPARAM(lParam); // vertical position
The DefWindowProc function carries out the window menu request for the predefined actions specified in the previous table.
In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are used internally by the system. To obtain the correct result when testing the value of wParam, an application must combine the value 0xFFF0 with the wParam value by using the bitwise AND operator.
The menu items in a window menu can be modified by using the GetSystemMenu, AppendMenu, InsertMenu, ModifyMenu, InsertMenuItem, and SetMenuItem functions. Applications that modify the window menu must process WM_SYSCOMMAND messages.
An application can carry out any system command at any time by passing a WM_SYSCOMMAND message to DefWindowProc. Any WM_SYSCOMMAND messages not handled by the application must be passed to DefWindowProc. Any command values added by an application must be processed by the application and cannot be passed to DefWindowProc.
Accelerator keys that are defined to choose items from the window menu are translated into WM_SYSCOMMAND messages; all other accelerator keystrokes are translated into WM_COMMAND messages.
If the wParam is SC_KEYMENU, lParam contains the character code of the key that is used with the ALT key to display the popup menu. For example, pressing ALT+F to display the File popup will cause a WM_SYSCOMMAND with wParam equal to SC_KEYMENU and lParam equal to 'f'.
Requirements
Windows NT/2000/XP: Included in Windows NT 3.1 and later.
Windows 95/98/Me: Included in Windows 95 and later.
Header: Declared in Winuser.h; include Windows.h.
#5
同意菠菜!!
buttonClick事件加上;
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
buttonClick事件加上;
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
buttonClick事件加上;
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
buttonClick事件加上;
PostMessgae(handle, WM_SYSCOMMAND, SC_MINIMIZED, 0);//最小化
PostMessgae(handle, WM_SYSCOMMAND, SC_MAXMIZED, 0);//最大化
PostMessgae(handle, WM_SYSCOMMAND, SC_CLOSE, 0);//关闭
{但愿没把SC_MINIMIZED, SC_MAXMIZED,SC_CLOSE写错 }
#6
关闭: SendMessage(Form1.Handle,Wm_syscommand,SC_CLOSE,0);
最大化: SendMessage(Form1.Handle,Wm_syscommand,SC_MAXIMIZE,0);
最小化: SendMessage(Form1.Handle,Wm_syscommand,SC_MINIMIZE,0);
最大化: SendMessage(Form1.Handle,Wm_syscommand,SC_MAXIMIZE,0);
最小化: SendMessage(Form1.Handle,Wm_syscommand,SC_MINIMIZE,0);
#7
我的意思是用拦截消息的方法。
就是 你在窗休上按下鼠标左键并释放,就相当于按了一下窗休上的关闭按钮 或 最小化按钮 或 最大化按钮
就是 你在窗休上按下鼠标左键并释放,就相当于按了一下窗休上的关闭按钮 或 最小化按钮 或 最大化按钮
#8
大家都到齊了啊
#9
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
Parameters
uCmdType
Specifies the type of system command requested. This can be one of these values:
Value Meaning
SC_CLOSE Closes the window.
SC_CONTEXTHELP Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message.
SC_DEFAULT Selects the default item; the user double-clicked the window menu.
SC_HOTKEY Activates the window associated with the application-specified hot key. The low-order word of lParam identifies the window to activate.
SC_HSCROLL Scrolls horizontally.
SC_KEYMENU Retrieves the window menu as a result of a keystroke.
SC_MAXIMIZE (or SC_ZOOM) Maximizes the window.
SC_MINIMIZE (or SC_ICON) Minimizes the window.
SC_MONITORPOWER Windows 95 only: Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
SC_MOUSEMENU Retrieves the window menu as a result of a mouse click.
SC_MOVE Moves the window.
SC_NEXTWINDOW Moves to the next window.
SC_PREVWINDOW Moves to the previous window.
SC_RESTORE Restores the window to its normal position and size.
SC_SCREENSAVE Executes the screen saver application specified in the [boot] section of the SYSTEM.INI file.
SC_SIZE Sizes the window.
SC_TASKLIST Executes or activates Windows Task Manager.
SC_VSCROLL Scrolls vertically.
xPos
Specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, the xPos parameter is not used.
yPos
Specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. This parameter is -1 if the command is chosen using a system accelerator, or zero if using a mnenomic.
Return Values
An application should return zero if it processes this message.
Remarks
The DefWindowProc function carries out the window menu request for the predefined actions specified in the previous table.
In WM_SYSCOMMAND messages, the four low-order bits of the uCmdType parameter are used internally by Windows. To obtain the correct result when testing the value of uCmdType, an application must combine the value 0xFFF0 with the uCmdType value by using the bitwise AND operator.
The menu items in a window menu can be modified by using the GetSystemMenu, AppendMenu, InsertMenu, ModifyMenu, InsertMenuItem, and SetMenuItem functions. Applications that modify the window menu must process WM_SYSCOMMAND messages.
An application can carry out any system command at any time by passing a WM_SYSCOMMAND message to DefWindowProc. Any WM_SYSCOMMAND messages not handled by the application must be passed to DefWindowProc. Any command values added by an application must be processed by the application and cannot be passed to DefWindowProc.
Accelerator keys that are defined to choose items from the window menu are translated into WM_SYSCOMMAND messages; all other accelerator keystrokes are translated into WM_COMMAND messages.
See Also
AppendMenu, DefWindowProc, GetSystemMenu, InsertMenu, ModifyMenu, WM_COMMAND
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
Parameters
uCmdType
Specifies the type of system command requested. This can be one of these values:
Value Meaning
SC_CLOSE Closes the window.
SC_CONTEXTHELP Changes the cursor to a question mark with a pointer. If the user then clicks a control in the dialog box, the control receives a WM_HELP message.
SC_DEFAULT Selects the default item; the user double-clicked the window menu.
SC_HOTKEY Activates the window associated with the application-specified hot key. The low-order word of lParam identifies the window to activate.
SC_HSCROLL Scrolls horizontally.
SC_KEYMENU Retrieves the window menu as a result of a keystroke.
SC_MAXIMIZE (or SC_ZOOM) Maximizes the window.
SC_MINIMIZE (or SC_ICON) Minimizes the window.
SC_MONITORPOWER Windows 95 only: Sets the state of the display. This command supports devices that have power-saving features, such as a battery-powered personal computer.
SC_MOUSEMENU Retrieves the window menu as a result of a mouse click.
SC_MOVE Moves the window.
SC_NEXTWINDOW Moves to the next window.
SC_PREVWINDOW Moves to the previous window.
SC_RESTORE Restores the window to its normal position and size.
SC_SCREENSAVE Executes the screen saver application specified in the [boot] section of the SYSTEM.INI file.
SC_SIZE Sizes the window.
SC_TASKLIST Executes or activates Windows Task Manager.
SC_VSCROLL Scrolls vertically.
xPos
Specifies the horizontal position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. Otherwise, the xPos parameter is not used.
yPos
Specifies the vertical position of the cursor, in screen coordinates, if a window menu command is chosen with the mouse. This parameter is -1 if the command is chosen using a system accelerator, or zero if using a mnenomic.
Return Values
An application should return zero if it processes this message.
Remarks
The DefWindowProc function carries out the window menu request for the predefined actions specified in the previous table.
In WM_SYSCOMMAND messages, the four low-order bits of the uCmdType parameter are used internally by Windows. To obtain the correct result when testing the value of uCmdType, an application must combine the value 0xFFF0 with the uCmdType value by using the bitwise AND operator.
The menu items in a window menu can be modified by using the GetSystemMenu, AppendMenu, InsertMenu, ModifyMenu, InsertMenuItem, and SetMenuItem functions. Applications that modify the window menu must process WM_SYSCOMMAND messages.
An application can carry out any system command at any time by passing a WM_SYSCOMMAND message to DefWindowProc. Any WM_SYSCOMMAND messages not handled by the application must be passed to DefWindowProc. Any command values added by an application must be processed by the application and cannot be passed to DefWindowProc.
Accelerator keys that are defined to choose items from the window menu are translated into WM_SYSCOMMAND messages; all other accelerator keystrokes are translated into WM_COMMAND messages.
See Also
AppendMenu, DefWindowProc, GetSystemMenu, InsertMenu, ModifyMenu, WM_COMMAND
#10
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure WndProc(var aMessage : TMessage); override;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
procedure TForm1.WndProc(var aMessage: TMessage);
begin
inherited;
if aMessage.Msg = WM_LBUTTONDOWN then
begin
SendMessage(Handle,WM_CLOSE, 0, 0); //关闭窗口
end;
end;
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure WndProc(var aMessage : TMessage); override;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
procedure TForm1.WndProc(var aMessage: TMessage);
begin
inherited;
if aMessage.Msg = WM_LBUTTONDOWN then
begin
SendMessage(Handle,WM_CLOSE, 0, 0); //关闭窗口
end;
end;
#11
^Z