WinPrint and MessageBox

Have you ever tried popping up a message box at the end of a report to inform the user something? One problem might arise is that the message box pops up behind the print preview, and the user wouldn't see the message box. One solution is to make the print preview window as the parent window of the message box. The trick is to get the Window Handle of the preview window, and to pass that window handle to the MessageBox function.

	Handle hPreviewWindow
	Integer iResult
	Move (WP_GetViewerWindow()) to hPreviewWindow
	If (hPreviewWindow) Move (MessageBox(hPreviewWindow, "My Message", "My Title", MB_ICONINFORMATION)) to iResult
	Else Send Info_Box "My Message" "My Title"

Internally Info_Box would call the Windows API MessageBox. However Info_Box would pick up the foreground window of your application as the parent window. On the other hand, the WinPrint preview window actually belongs to another program called "WinPrintViewer.exe". In order to get the Window Handle of the preview window, WinPrint.dll exposes a handy function called "WP_GetViewerWindow" that will return the Window Handle of the preview window. At the end, we will bypass the Info_Box (which will surely pick the "wrong" parent window) and call MessageBox directly. Feel free to add all the "ToAnsi" calls around MessageBox if you are trying to display OEM strings...