Dialog Editbox Version 1.00 2003:09:30 - Editbox with horizontal and vertical scrollbars in WinBatch dialog window. View: Screenshot |
Version History
|
If you have questions about WinBatch, you are encouraged to use online WebBoard BBS at http://webboard.windowware.com |
;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction EdCreate (x, y, w, h, style, hWnd) user32=StrCat(DirWindows(1),"user32.dll") hinst=DllHinst("") EdStyle=1073741824|268435456|style Return DllCall(user32,long:"CreateWindowExA",long:512,lpstr:"Edit",lpstr:"",long:EdStyle,long:x,long:y,long:w,long:h,long:hWnd,long:0,long:hinst,long:0) ;.......................................................................................................................................... ; EdCreate : Creates an Edit control. ; by IFICantBYTE September 2003 ;.......................................................................................................................................... ; x : pixels from left ; y : pixels from top ; w : width in pixels ; h : height in pixels ; style : style flags , see API constants ; handle : dialog handle returned by the dialog procedure ;.......................................................................................................................................... ; Returns: Edit handle if succesful , 0 otherwise ;.......................................................................................................................................... ; API EXStyle : WS_EX_CLIENTEDGE = 512 ; Style : WS_CHILD|WS_VISIBLE = 1073741824|268435456 ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction EdSetText (hEd, sText) user32=StrCat(DirWindows(1),"user32.dll") WM_SETTEXT=12 Return DllCall(user32,long:"SendMessageA",long:hEd,long:WM_SETTEXT,long:0,lpstr:sText) ;.......................................................................................................................................... ; EdSetText : Sets Text in an Edit control ; by IFICantBYTE September 2003 ;.......................................................................................................................................... ; hEd : Edit control handle ; Text : Text to insert in the Edit control ;.......................................................................................................................................... ; Returns : The return value is TRUE if the text is set. ; It is FALSE if insufficient space is available to set the text. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineFunction EdGetText (hEd) user32=StrCat(DirWindows(1),"user32.dll") WM_GETTEXT=13 WM_GETTEXTLENGTH=14 ; Return the length of the text in TCHARs, not including the terminating null character. iLen=DllCall(user32,long:"SendMessageA",long:hEd,long:WM_GETTEXTLENGTH,long:0,long:0) If !iLen Then Return "" iLen=iLen+1 ; Respect terminating null character. hBB=BinaryAlloc(iLen) BinaryEodSet(hBB,iLen) iLen=DllCall(user32,long:"SendMessageA",long:hEd,long:WM_GETTEXT,long:iLen,lpbinary:hBB) sText=BinaryPeekStr(hBB,0,iLen) BinaryFree(hBB) Return sText ;.......................................................................................................................................... ; EdGetText : Returns the Text in an Edit control ; by IFICantBYTE September 2003 ; Modified by Detlev Dalitz.20030930 ;.......................................................................................................................................... ; hEd : Edit control handle ;.......................................................................................................................................... ; Returns : The text from the Edit control. ;.......................................................................................................................................... #EndFunction ;------------------------------------------------------------------------------------------------------------------------------------------ ;========================================================================================================================================== ; TEST DIALOG for EdControl ;========================================================================================================================================== ;------------------------------------------------------------------------------------------------------------------------------------------ #DefineSubRoutine udsMyDialogCallbackProc(MyDialog_Handle,MyDialog_Message,MyDialog_ID,rsvd1,rsvd2) Switch MyDialog_Message Case MSG_INIT DialogProcOptions(MyDialog_Handle,MSG_BUTTONPUSHED,@TRUE) hEd=EdCreate(10,10,400,232,WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_WANTRETURN,MyDialog_Handle) iResult=EdSetText(hEd,sText) Return -1 Case MSG_BUTTONPUSHED Switch MyDialog_ID Case 001 Message("Returned Edit Box Text",EdGetText(hEd)) Return -2 Case 002 Return -1 EndSwitch Return -1 EndSwitch Return -1 #EndSubRoutine ;------------------------------------------------------------------------------------------------------------------------------------------ ; --- main --- ;.......................................................................................................................................... ; Define some DialogprocOptions Constants MSG_INIT = 0 ; The one-time initilization MSG_TIMER = 1 ; Timer event MSG_BUTTONPUSHED = 2 ; Pushbutton or Picturebutton ;.......................................................................................................................................... ; Define some Edit Control constants ; WS (General Window Styles constants) WS_SIZEBOX = 262144 ; Use if you want to be able to resize a window with the mouse after it is created WS_CAPTION = 12582912 ; Use if you want the Window to have a Caption (this could be used as a drag handle and/or to display text) WS_HSCROLL = 1048576 ; Use if you want to give the window a Horizontal Scroll Control WS_VSCROLL = 2097152 ; Use if you want to give the window a Vertical Scroll Control ; ES (Edit Control Style Constants) ES_MULTILINE = 4 ; Defines the Edit Control as having more than one line. ES_AUTOVSCROLL = 64 ; Automatically scrolls the text vertically into view based on the current cursor position ES_AUTOHSCROLL = 128 ; Automatically scrolls the text horizontally into view based on the current cursor position ES_READONLY = 2048 ; Use this style if you don't want people to be able to edit the displayed text (this style can also be toggled later by an explicit Message function) ES_WANTRETURN = 4096 ; Edit control expects a 'Return' or 'Enter' at the end of each line and so it does not treat the return key as an 'OK' signal. ;.......................................................................................................................................... ; Create string to display. sText="" sText=StrCat(sText,"Hello there.",@CRLF) sText=StrCat(sText,"This is an Edit Control with scroll bars.",@CRLF) sText=StrCat(sText,"This is a new line that is longer than the visible area, so we should then get an active horizontal scroll bar to read it!",@CRLF) sText=StrCat(sText,"And below are more lines that mean we should have an active Vertical scroll bar too.") For ii=1 To 20 sText=StrCat(sText,@CRLF,"Line ",ii) Next ;.......................................................................................................................................... ; Invoke dialog. MyDialogFormat=`WWWDLGED,6.1` MyDialogCaption=`WIL Dialog 1` MyDialogX=-1 MyDialogY=-1 MyDialogWidth=212 MyDialogHeight=151 MyDialogNumControls=002 MyDialogProcedure=`udsMyDialogCallbackProc` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,DEFAULT` MyDialogConfig=0 MyDialog001=`007,131,036,012,PUSHBUTTON,DEFAULT,"Return Text",1,1,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`167,131,036,012,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("MyDialog") ;.......................................................................................................................................... Exit ;========================================================================================================================================== ;*EOF*