Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!mcnc!rti!bcw From: bcw@rti.rti.org (Bruce Wright) Newsgroups: comp.windows.ms Subject: Re: Getting simple debug output Summary: Debug messages Message-ID: <4003@rtifs1.UUCP> Date: 4 Aug 90 23:27:02 GMT References: <1990Aug3.184951.5599@cs.umn.edu> Organization: Research Triangle Institute, RTP, NC Lines: 60 In article <1990Aug3.184951.5599@cs.umn.edu>, wytten@cs.umn.edu (Dale Wyttenbach) writes: > I'm a experienced X11 programmer trying to write my first MSW > program, and having a difficult time getting simple debug > output from my program. (I'm trying to avoid learning yet > another debugger) > > Right now I'm just opening a file called debug.txt and writing > stuff into that, but I'd like to have a quickie function that > pops up a dialog box with a message, sort of like this: > > sprintf(buf,"a= %d, b=%d",a,b); > debugwin(buf); > > I would like to do this with a dialog box, but I don't know if you can > pass the buf in since dialog boxes are defined in the .rc file. The simplest way to get an error message into a dialog box is with the MessageBox function - this puts up a small dialog box and a message without requiring that you define the dialog box in the .rc file. Typical syntax is: MessageBox (hWnd, szBuffer, szAppName, MB_OK | MB_ICONEXCLAMATION); (for example). Note that you can get more pushbuttons by using somewhat different flags: for example, MB_OKCANCEL has both an OK and a Cancel pushbutton, and the function returns which button was pushed. One simple but useful function in many cases is one to check the range of a value and pop up a message box if it's out of range: BOOL CheckRange (hWnd, iValue, iLow, iHigh, szMessage) HWND hWnd; short iValue, iLow, iHigh; char *szMessage; { char szBuffer [80]; if ((iValue < iLow) || (iValue > iHigh)) { wsprintf (szBuffer, szMessage, iValue); MessageBox (hWnd, szBuffer, szAppName, MB_OK | MB_ICONEXCLAMATION); return TRUE; } return FALSE; } (This will only work on Windows 3.0 because wsprintf doesn't exist in Windows 2.0, but you should be able to substitute sprintf - it just takes more space. szAppName is just a string with the name of the application and is put in the message box caption). The main problem with this technique is that if you need a lot of information (like writing out a lot of values in the message box or you want to see previous error messages as well), it gets sort of cumbersome. Bruce C. Wright