Friday, June 24, 2011

Inside baseball... well... inside MessageBox formatting, a story about a feature many/most/all WinDev's use...

The Old New Thing - Why doesn't my MessageBox wrap at the right location?

A customer reported that the MessageBox function was wrapping text "at the wrong location."

Our program displays a message with theMessageBox function, and we use the '\n' character to force line breaks at positions we choose. But we've found that starting in Windows Vista, the line breaks we placed are not working. The MessageBox function is inserting its own line breaks, which interferes with our custom text layout. It used to be that the width of the message box would expand to fit the longest line in the message.

The MessageBox function is one of those "leave the driving to us" type of functions. You give it a string to display, select which buttons you want, and sit back and relax while the MessageBox function does the work. The trade-off for the simplicity is that you also lose control over the experience. The MessageBox function decides where to place the dialog and how big to make it, which in turn determines where the line breaks go.

The algorithm used by MessageBox to determine the size of the message box has changed many times over the lifetime of Windows. ..."

I dig these kinds of "inside baseball" stories about Windows API/features we've all likely used, and been abused by, over the years.

No comments: