1 Programmatic controlling
snowie2000 edited this page 2023-05-31 15:23:05 +08:00

Works with mactype 2023.5.31 and later

When mactype is running in tray mode (both user mode and admin mode), it can be controlled by posting predefined messages. And it can be easily achieved.

How it works

MacType will expose a top-level messenger window with the classname MacTypeMSGWnd. Certain controlling messages can be sent to this window to manipulate the action of mactype.

Currently, the following messages are defined:

  • MacType-SIG-STOP, stop mactype and exit
  • MacType-SIG-RESTART, reload the current profile without interruption
  • MacType-SIG-ENABLE, enable mactype
  • MacType-SIG-DISABLE, disable mactype

Example

bool StopMacType() {
  ULONG SigStop = ::RegisterWindowMessage("MacType-SIG-STOP");
  HWND MsgWnd = ::FindWindow("MacTypeMSGWnd", NULL);
  if (SigStop && MsgWnd) {
    ::PostMessage(MsgWnd, SigStop, 0, 0);
    return true;
  }
  return false;
}