- 1 year ago
Delphi: custom window menu: Msg.CmdType and $FFF0 clarification needed
In Delphi, when creating a custom window menu for your application, you may encounter references to Msg.CmdType
and $FFF0
. These are related to handling messages sent to the window procedure of your application's main form. Let's clarify their meanings:
Msg.CmdType
:
In Delphi,Msg
is a variable of typeTMessage
, which is used to represent messages sent to a window procedure. TheTMessage
type has several fields, andMsg.CmdType
is one of them.The
Msg.CmdType
field is used to determine the type of a system command message. A system command message is sent to the window procedure when the user clicks on a system menu item (e.g., close, minimize, maximize) or performs a keyboard equivalent for a system command (e.g., Alt+F4 to close the window). TheCmdType
field of theTMessage
structure is used to identify the specific system command.For example,
Msg.CmdType
may have one of the following values:- SC_CLOSE (Command to close the window)
- SC_MINIMIZE (Command to minimize the window)
- SC_MAXIMIZE (Command to maximize the window)
- SC_RESTORE (Command to restore the window to its previous size)
- and others, depending on the specific system commands available.
$FFF0
:
$FFF0
is a hexadecimal constant used to identify system commands related to the custom window menu. When you handle a system command message in your application's main form, you may check ifMsg.CmdType
matches$FFF0
. If it does, it means that the command is related to a custom menu item that you have added to the system menu.When you add custom menu items to the system menu, they are assigned IDs in the range
$FFF0
to$FFFF
. This range is reserved for custom menu items to avoid conflicts with standard system command IDs.Here's an example of how you might handle a custom system menu command in your Delphi application:
delphiprocedure TForm1.WMCommand(var Msg: TWMCommand);
begin
if Msg.CmdType = $FFF0 then
begin
// Custom system menu command handling
case Msg.ItemID of
// Handle your custom menu item IDs here
end;
end
else
inherited;
end;
In this example, the
WMCommand
procedure is overridden to handle system command messages. WhenMsg.CmdType
equals$FFF0
, it indicates that the message is related to a custom system menu item. You can then check theMsg.ItemID
to determine which custom menu item was clicked and handle it accordingly.
By understanding Msg.CmdType
and $FFF0
, you can create and handle custom menu items in your Delphi application's system menu to provide additional functionality to your users.