Figure 2 Windows Functions for Sending Messages

Function
Purpose
When to Use
Windows Version
SendMessage
Sends a message immediately to another window by calling the window's message proc. Returns when the message has been processed. Think of it as a function call. SendMessage will block if the target thread is different from your own.
Use to send messages to your own windows to perform some action that must be done immediately because the subsequent lines of code depend on the result. SendMessage is typically used to communicate between parent/child windows. Be careful when sending messages to windows in other threads, since this function blocks.
All versions
PostMessage
Sends a message to another window by posting (adding) an MSG struct to the message queue of the thread or process that owns the window. Returns immediately, without waiting for the message to be processed. Can be used with a NULL HWND to communicate without using a window.
Use for messages that are not urgent or are merely informational in nature (such as a notification). This function can also be used to simulate commands or input; to send messages to other threads to avoid blocking; and with HWND_TOPMOST to broadcast messages to all top-level windows.
All versions
SendNotifyMessage
If the window you send the message to belongs to (was created by) the same thread, it calls the window's message proc and waits for it to process the message; if the window belongs to a different thread, this function returns immediately without waiting.
Use to avoid blocking when sending messages to windows in other threads and processes. Use with HWND_TOPMOST to broadcast messages to all top-level windows.
Win32
SendMessageTimeout
If the window belongs to the same thread, this function calls the window's message proc and waits for it to process the message; if the window belongs to a different thread, SendMessageTimeout sends the message and waits for the message to be processed, up to a specified amount of time. If the message is not processed within the specified time, this function returns.
Use to avoid blocking when sending messages to windows in other threads and processes. Use with HWND_TOPMOST to broadcast messages to all top-level windows.
Win32
SendMessageCallback
Sends a message to a window and returns immediately. When the message has been processed, Windows calls your callback function with information about the result.
Use this function when you would use PostMessage, but you want to know when the message was processed.
Win32

Figure 4 FileType2.cpp

  ////////////////////////////////////////////////////////////////
// MSDN — December 2000
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 6.0, runs on Windows 98, and probably Windows 
// NT too.
//
// FileType2 implements the functionality of FileType from the November 
// 2000 issue of MSDN Magazine, and adds hotkey activation using
// RegisterHotKey and WM_HOTKEY.
//
// This file is edited to show only the parts relevant to hot keys. For
// full source, go to https://msdn.microsoft.com/msdnmag

#include "stdafx.h"

•••

//////////////////
// Standard dialog has edit control and static icon
//
class CMyDialog : public CDialog {
public:
   CMyDialog(CWnd* pParent = NULL);     // standard constructor

   •••

protected:
   UINT m_nIDHotKey;                    // hot key identifier

   virtual BOOL OnInitDialog();
   afx_msg LRESULT OnHotKey(WPARAM wp, LPARAM lp);
   afx_msg void OnHideDialog();
   afx_msg void OnDestroy();
   DECLARE_MESSAGE_MAP()
};

//////////////////
// Generic app object
//
class CMyApp : public CWinApp {
public:
   CMyApp();
   virtual BOOL InitInstance();
   DECLARE_MESSAGE_MAP()
} theApp;

BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
END_MESSAGE_MAP()

CMyApp::CMyApp()
{
}

BOOL CMyApp::InitInstance()
{
   CMyDialog dlg;
   m_pMainWnd = &dlg;
   dlg.DoModal();
   return FALSE;
}

////////////////////////////////////////////////////////////////
// Dialog class

CMyDialog::CMyDialog(CWnd* pParent /*=NULL*/)
   : CDialog(IDD_MYDIALOG, pParent)
{
   m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
   ON_COMMAND(IDC_HIDE_DIALOG, OnHideDialog)
   ON_MESSAGE(WM_HOTKEY, OnHotKey)
   ON_WM_DESTROY()
END_MESSAGE_MAP()

//////////////////
// Dialog just created: initialize it
//
BOOL CMyDialog::OnInitDialog()
{

   •••

   // Register "Windows-A" as my hot key (Windows key + A)
   m_nIDHotKey = GlobalAddAtom("FileType2App");
   TRACE("m_nIDHotKey = %d\n", m_nIDHotKey);
   RegisterHotKey(m_hWnd, m_nIDHotKey, MOD_WIN, 'A');

   return FALSE;  // return TRUE  unless you set the focus to a control
}

//////////////////
// Dialog destroyed: unregister hot key
//
void CMyDialog::OnDestroy()
{
   UnregisterHotKey(m_hWnd, m_nIDHotKey);
}

//////////////////
// User pressed hot key: show myself if not already.
//
LRESULT CMyDialog::OnHotKey(WPARAM wp, LPARAM lp)
{
   TRACE(_T("CMyDialog::OnHotKey\n"));
   if (wp==m_nIDHotKey && !IsWindowVisible()) {
      ShowWindow(SW_SHOWNORMAL);
   }
   return 0;
}

//////////////////
// User pressed Hide button: hide myself
//
void CMyDialog::OnHideDialog()
{
   ShowWindow(SW_HIDE);
}