I've been trying to implement the DrawText function to display text in a dialog... no problem getting it to display, but getting it to stay there is another thing. I've recreated the problem in the following code example... after text has been displayed in the dialog using DrawText (or TextOut, for that matter) the text is lost when you minimize and restore the dialog. Is there something wrong with the code or is this the way it's supposed to be?
Thanks for any help.
Timm
[This message has been edited by Timm Motl (edited September 26, 2000).]
Code:
#COMPILE EXE #REGISTER NONE #INCLUDE "Win32Api.Inc" GLOBAL PenColor AS LONG GLOBAL BackColor AS LONG GLOBAL StringVar AS ASCIIZ * 256 CALLBACK FUNCTION DlgProc SELECT CASE CBMSG CASE %WM_INITDIALOG DIM tRect AS GLOBAL RECT GetClientRect CBHNDL, tRect ' Set up initial position, colors and first text line to be displayed tRect.nLeft = tRect.nLeft + 10 tRect.nTop = tRect.nTop + 10 PenColor = RGB(0, 0, 200) BackColor = -1 ' This flag is used to force transparent background mode StringVar = "Type some text and press Enter..." CASE %WM_PAINT LOCAL hDC AS LONG LOCAL ps AS PAINTSTRUCT hDC = BeginPaint(CBHNDL, ps) IF BackColor < 0 THEN Setbkmode hDC, %TRANSPARENT ELSE Setbkmode hDC, %OPAQUE SetBkColor hDC, BackColor END IF SetTextColor hDC, PenColor DrawText hDC, StringVar, LEN(StringVar), tRect, 0 EndPaint CBHNDL, ps StringVar = "" FUNCTION = 0 END SELECT SELECT CASE CBCTL CASE 200 ' Display Text button was clicked (or Enter key was pressed) CONTROL GET TEXT CBHNDL, 100 TO StringVar IF LEN(StringVar) THEN tRect.nTop = tRect.nTop + 16 IF tRect.nTop <= 266 THEN ' Initiate a WM_PAINT message so StringVar is displayed InvalidateRect CBHNDL, BYVAL 0, %FALSE UpdateWindow CBHNDL END IF CONTROL SET TEXT CBHNDL, 100, "" END IF CONTROL SET FOCUS CBHNDL, 100 END SELECT END FUNCTION FUNCTION PBMAIN LOCAL hDlg AS LONG DIALOG NEW 0, "Minimizing & Restoring clears the text from this dialog... WHY?",,, 300, 200, _ %WS_CAPTION + %WS_MINIMIZEBOX + %WS_SYSMENU TO hDlg CONTROL ADD TEXTBOX, hDlg, 100, "", 6, 180, 225, 13 CONTROL ADD BUTTON, hDlg, 200, "Display Text", 236, 180, 58, 14, %BS_DEFAULT DIALOG SHOW MODAL hDlg CALL DlgProc END FUNCTION
Timm
[This message has been edited by Timm Motl (edited September 26, 2000).]
Comment