John...
Thanks for the code sample... the comment at the end of your response confirms what I gathered from Semen's code sample as well. The DrawText and TextOut commands (and WM_PAINT message) are much clearer to me now. Thanks for offering your assistance.
Timm
Announcement
Collapse
No announcement yet.
Drawtext output to screen is lost on minimize
Collapse
X
-
This may help.
The following function is like the dos
Locate nn:nn
Color n
print n$
all rolled into one.
FUNCTION SPRINT(BYVAL hDlg AS LONG,BYVAL Row AS LONG,BYVAL Col AS LONG,BYVAL Ink AS LONG,PrintStr AS ASCIIZ) AS LONG
LOCAL hDC AS LONG
LOCAL Trect AS Rect
LOCAL DiUnit AS DWORD
LOCAL HZDBU AS LONG
LOCAL VTDBU AS LONG
LOCAL ch AS LONG
LOCAL cv AS LONG
LOCAL hBkCol AS LONG
LOCAL STRINGPTR AS ASCIIZ PTR
LOCAL STRINGLEN AS LONG
GetDC hDlg TO hDC
SelectObject hDc,hFont
GetClientRect hDlg,Trect
GetDialogBaseUnits TO DiUnit
HZDBU = LOWRD(DiUnit)
VTDBU = HIWRD(DiUnit)
ch = (Col * HZDBU)+2
cv = (Row * VTDBU)+2
SetBkMode hDC, %OPAQUE'%TRANSPARENT
SetTextColor hDC,Ink
APGREY&=GetSysColor(%COLOR_ACTIVEBORDER)
SETBKCOLOR hDC,APGREY&
STRINGPTR = VARPTR(PrintStr)
STRINGLEN = LEN(PrintStr)
TextOut hDC,ch,cv,@STRINGPTR,STRINGLEN
ReleaseDC hDlg,hDC
FUNCTION = %TRUE
END FUNCTION
Use hFont = GetStockObject(%OEM_FIXED_FONT) to select a fixed
pitch font and you will not have problems with formatted text.
In order to repaint the text when the window is moved you must
maintain a buffer of the text you are writing to the window.
Write the buffer contents to the window on a WM_MOVE or WM_PAINT.
------------------
Leave a comment:
-
Semen...
Thanks for responding and "cleaning up" my code. Your changes helped me to understand that my WM_PAINT handler needs to redisplay all of the strings displayed with DrawText and TextOut commands... they are not automatically redrawn when a WM_PAINT message is processed. Please excuse my lack of understanding... I'm just now migrating from DOS programming to Windows and I'm slowly discovering the differences between the two. Semen, I watch for your postings here every day. Your code examples have taught me a great deal and I thank you!
Michael...
Thanks for the suggestion on using static controls. That's a definite option, but I was really trying to find out more about using DrawText and TextOut. I guess my initial posting wasn't very clear in that respect. I wasn't really trying to find a solution to a programming problem as much as I was trying to understand the use of those two commands. Thanks for responding though!
Timm
[This message has been edited by Timm Motl (edited September 27, 2000).]
Leave a comment:
-
Not tested, but I would think you could add a STATIC control to the dialog, and use CONTROL SET TEXT at the appropriate time(s)....
MCM
Leave a comment:
-
Timm --
In %WM_PAINT you should draw whole text from the beginning.
I reconstructed your code a little.
Code:#Compile Exe #Dim All #Register None #Include "Win32Api.Inc" CallBack Function DlgProc Select Case CbMsg Case %WM_INITDIALOG Static StringVar As String StringVar = "Type some text and press Enter..." Case %WM_COMMAND Select Case CbCtl Case 200 Local Tmp As String Control Get Text CbHndl, 100 To Tmp If Len(Tmp) Then StringVar = StringVar + $CRLF + Tmp InvalidateRect CbHndl, ByVal 0, %FALSE UpdateWindow CbHndl Control Set Text CbHndl, 100, "" End If Control Set Focus CbHndl, 100 End Select Case %WM_PAINT Dim tRect As RECT GetClientRect CbHndl, tRect tRect.nLeft = 0.05 * tRect.nRight tRect.nRight = 0.95 * tRect.nRight tRect.nTop = 0.05 * tRect.nBottom tRect.nBottom = 0.80 * tRect.nBottom Local ps As PAINTSTRUCT BeginPaint CbHndl, ps Setbkmode ps.hDC, %TRANSPARENT SetTextColor ps.hDC, Rgb(0, 0, 200) DrawText ps.hDC, ByCopy StringVar, Len(StringVar), tRect, 0 EndPaint CbHndl, ps End Select End Function Function PbMain Local hDlg As Long Dialog New 0, "Test",,, 300, 200, %WS_CAPTION Or %WS_MINIMIZEBOX Or %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
E-MAIL: [email protected]
Leave a comment:
-
Drawtext output to screen is lost on minimize
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?
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).]Tags: None
Leave a comment: