Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: DllCall Rich Edit Control Dialog
;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditnotificationmessages/en_link.asp ;-----------------------------------------------------------------------------------------------------------------------------------------; ;REdCreate : Creates a Rich Edit control (RTF Edit Control). ; ;v1.0 by ....IFICantBYTE Nov 2004 ; ;-----------------------------------------------------------------------------------------------------------------------------------------; ;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: Control's handle if succesful , 0 otherwise ; ;-----------------------------------------------------------------------------------------------------------------------------------------; ;API EXStyle : WS_EX_CLIENTEDGE = 512 ; ; Style : WS_CHILD|WS_VISIBLE = 1073741824|268435456 ; ;-----------------------------------------------------------------------------------------------------------------------------------------; #DefineFunction REdCreate(x,y,w,h,style,handle) user32=StrCat(DirWindows(1),"user32.dll") riched32=StrCat(DirWindows(1),"riched20.dll") hinst=DllHinst("") Edstyle = 1073741824|268435456|style DllLoad(riched32) ; Load dll containing RichEdit Functions into memory (if not already) Return DllCall(user32,long:"CreateWindowExA",long:0,lpstr:"RichEdit20A",long:0,long:Edstyle,long:x,long:y,long:w,long:h,long:handle,long:311,long:hinst,long:0) #EndFunction ;-----------------------------------------------------------------------------------------------------------------------------------------; ;REdSetAutoURL : Enables or Disables automatic detection of URLs in a Rich Edit control. ; ; eg: will detect strings beginning with: www. http: file: mailto: ftp: https: gopher: nntp: telnet: news: \\ and more. ; ;v1.0 by ....IFICantBYTE Nov 2004 ; ;-----------------------------------------------------------------------------------------------------------------------------------------; ;hREd : RichEdit control handle ; ;OffOn : TRUE (1) to enable automatic URL detection or FALSE (0) to disable it. ; ;-----------------------------------------------------------------------------------------------------------------------------------------; ;Returns : FALSE (0) if the setting was SUCCESSFUL ; ; If it returns a NON-ZERO value then it FAILED for some reason. ; ; ; ; NOTE : When it detects a URL, the control sets the CFE_LINK effect bit for all characters in the URL string. The control highlights ; ; the URL string by underlining it and setting the text color. (The cursor or mouse pointer changes too) ; ; A Rich Edit control sends the EN_LINK notification when it receives various messages while the mouse pointer is over text that ; ; has the CFE_LINK effect. Unfortunatly WinBatch (at this time) can't natively process this notification - perhaps Extender DLL? ; ;-----------------------------------------------------------------------------------------------------------------------------------------; #DefineFunction REdSetAutoURL(hREd,OffOn) user32=StrCat(DirWindows(1),"user32.dll") WM_USER = 1024 EM_AUTOURLDETECT = WM_USER + 91 Return DllCall(user32,long:"SendMessageA",long:hREd,long:EM_AUTOURLDETECT,long:OffOn,long:0) #EndFunction ;-----------------------------------------------------------------------------------------------------------------------------------------; ;REdGetOLEInterface : Retrieves an IRichEditOle object to access a Rch Edit control's Component Object Model (COM) functionality. ; ;v1.0 by ....IFICantBYTE Nov 2004 ; ;-----------------------------------------------------------------------------------------------------------------------------------------; ;hREd : RichEdit control handle ; ;OffOn : TRUE (1) to enable automatic URL detection or FALSE (0) to disable it. ; ;-----------------------------------------------------------------------------------------------------------------------------------------; ;Returns : A NONZERO value if successful - use this as the OLE (COM) top object. OR if it fails, it will return FALSE (0) ; ; ; ; NOTE : When it detects a URL, the control sets the CFE_LINK effect bit for all characters in the URL string. The control highlights ; ; the URL string by underlining it and setting the text color. (The cursor or mouse pointer changes too) ; ; A Rich Edit control sends the EN_LINK notification when it receives various messages while the mouse pointer is over text that ; ; has the CFE_LINK effect. Unfortunatly WinBatch (at this time) can't natively process this notification - perhaps Extender DLL? ; ;-----------------------------------------------------------------------------------------------------------------------------------------; #DefineFunction REdGetOLEInterface(hREd) user32=StrCat(DirWindows(1),"user32.dll") WM_USER = 1024 EM_GETOLEINTERFACE = WM_USER + 60 OLEpointer = BinaryAlloc(32) BinaryOleType(OLEpointer,304,0,0,0) Message("non zero?",DllCall(user32,long:"SendMessageA",long:hREd,long:EM_GETOLEINTERFACE,long:0,lpbinary:OLEpointer)) Ret = BinaryPeek4(OLEpointer,0) AddExtender("wilx44i.dll") ; Mon = xBaseConvert(Ret, 10, 16) ; ; ;Mon = BinaryPeekHex(hRed,0,BinaryEODGet(hRed)) Message("OLE? How!!!!",ObjectGet(Ret)) ;perhaps need an existing ole/com interface to connect to? ;ItextDocumet - TOM model - look at objects in doc ;Retint = IntControl (42, OLEpointer, 0, 0, 0) ;Message("GetLinkCount",Retint.GetLinkCount()) BinaryFree(OLEpointer) Return Ret #EndFunction ;-----------------------------------------------------------------------------------------------------------------------------------------; ;REdSetBKGNDColor : Sets the background colour in a Rich Edit control. ; ;v1.0 by ....IFICantBYTE Nov 2004 ; ;-----------------------------------------------------------------------------------------------------------------------------------------; ;hREd : RichEdit control handle ; ;RGB : "RED|GREEN|BLUE" value (use 0 to 255 for each seperated by | as a text string - ie: in quotes) eg: "255|0|128" ; ; To use the same colour as the background of your WinBatch dynamic dialog, call this UDF in the following way: ; ; REdSetBKGNDColor(hREd,DialogProcOptions(handle,1001,-1)) ; ; Or use "SYSTEM" to use the window background system colour (usually white on most systems). ; ; ;-----------------------------------------------------------------------------------------------------------------------------------------; ;Returns : The original background color. ; ;-----------------------------------------------------------------------------------------------------------------------------------------; #DefineFunction REdSetBKGNDColor(hREd,RGB) user32=StrCat(DirWindows(1),"user32.dll") WM_USER = 1024 EM_SETBKGNDCOLOR = WM_USER + 67 If StrUpper(RGB) == "SYSTEM" SysColFlag = 1 ; Use the window background system colour. ; (This is the Default System colour on your PC for Edit controls, NOT the WinBatch Dialog Colour). Colour = 0 Else SysColFlag = 0 If ItemCount(RGB,"|") == 3 r = ItemExtract(1,RGB,"|") g = ItemExtract(2,RGB,"|") b = ItemExtract(3,RGB,"|") Colour = b*256*256 + g*256 + r Else Colour = DllCall(user32,long:"GetSysColor",long:15) ; Gets the system colour used by the dialog when "DEFAULT" is used as the colour EndIf EndIf Return DllCall(user32,long:"SendMessageA",long:hREd,long:EM_SETBKGNDCOLOR,long:SysColFlag,long:Colour) #EndFunction ;-----------------------------------------------------------------------------------------------------------------------------------------; ;REdSetEventMask : Sets the event mask for a rich edit control. ; ; The event mask specifies which notification messages the control sends to its parent window. ; ;v1.0 by ....IFICantBYTE Nov 2004 ; ;-----------------------------------------------------------------------------------------------------------------------------------------; ;hREd : RichEdit control handle ; ;EventMask : New event mask for the rich edit control. OR values together for multiple eg: ENM_LINK|ENM_CHANGE ; ; NOTE : The default event mask (before any is set) is ENM_NONE = 0 ie: no notification messages sent. ; ; Some common values in decimal are: ; ; ENM_CHANGE As Long = 1 ; ; ENM_CORRECTTEXT As Long = 4194304 ; ; ENM_DRAGDROPDONE As Long = 16 ; ; ENM_DROPFILES As Long = 1048576 ; ; ENM_KEYEVENTS As Long = 65536 ; ; ENM_LINK As Long = 67108864 ; ; ENM_MOUSEEVENTS As Long = 131072 ; ; ENM_NONE As Long = 0 ; ; ENM_OBJECTPOSITIONS As Long = 33554432 ; ; ENM_PROTECTED As Long = 2097152 ; ; ENM_REQUESTRESIZE As Long = 262144 ; ; ENM_SCROLL As Long = 4 ; ; ENM_SCROLLEVENTS As Long = 8 ; ; ENM_SELCHANGE As Long = 524288 ; ;-----------------------------------------------------------------------------------------------------------------------------------------; ;Returns : The previous event mask. ; ; If it returns a NON-ZERO value then it FAILED for some reason. ; ; NOTE : The default event mask (before any is set) is ENM_NONE. ; ; Unfortunatly WinBatch (at this time) can't natively process the notifications sent by the RichEdit control, but perhaps an ; ; Extender DLL or a later version of WinBatch might be able to? ; ;-----------------------------------------------------------------------------------------------------------------------------------------; #DefineFunction REdSetEventMask(hREd,EventMask) user32=StrCat(DirWindows(1),"user32.dll") WM_USER = 1024 EM_SETEVENTMASK = WM_USER + 69 Return DllCall(user32,long:"SendMessageA",long:hREd,long:EM_SETEVENTMASK,long:0,long:EventMask) #EndFunction ;-----------------------------------------------------------------------------------------------------------------------------------------; ;EdCreate : Creates a 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 ; ;-----------------------------------------------------------------------------------------------------------------------------------------; #DefineFunction EdCreate(x,y,w,h,style,handle) 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:handle,long:0,long:hinst,long:0) #EndFunction ;---------------------------------------------------------------------------; ;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. ; ;---------------------------------------------------------------------------; #DefineFunction EdSetText(hEd,Text) user32=StrCat(DirWindows(1),"user32.dll") WM_SETTEXT = 12 ret = DllCall(user32,long:"SendMessageA",long:hEd,long:WM_SETTEXT,long:0,lpstr:Text) Return ret #EndFunction ;---------------------------------------------------------------------------; ;EdGetText : Returns the Text in an Edit control ; ;by IFICantBYTE September 2003 ; ;---------------------------------------------------------------------------; ;hEd : Edit control handle ; ;---------------------------------------------------------------------------; ;Returns : The text from the Edit control. ; ;---------------------------------------------------------------------------; #DefineFunction EdGetText(hEd) user32=StrCat(DirWindows(1),"user32.dll") WM_GETTEXT = 13 bufsize = 10000 ; you can make this value bigger if your text is very long. TextBuf=BinaryAlloc(bufsize + 1) TextStrLen = DllCall(user32,long:"SendMessageA",long:hEd,long:WM_GETTEXT,long:bufsize,lpbinary:TextBuf) ; this fills the TextBuffer we made and returns the string length (though not actually used by us here) BinaryEodSet(TextBuf,bufsize + 1) EdText=BinaryPeekStr(TextBuf,0,bufsize) BinaryFree(TextBuf) Return EdText #EndFunction ;------------------------------------------------------------------------------; ;TEST DIALOG for EdControl ; ;------------------------------------------------------------------------------; #DefineSubRoutine dlgproc(handle,msg,id,p4,p5) Select msg Case 0 ;Initialize Winbatch dialog, enable various call-back events, then create our Edit Control DialogProcOptions(handle,2,1) ;enable BUTTONS ;========= Create Rich Edit Control ========== ;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) - There are many more and some are applicable to both standard Edit and Rich Edit controls - some are for Rich Edit only 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. hREd = REdCreate(10,10,640,480,WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_WANTRETURN,handle) REdSetBKGNDColor(hREd,DialogProcOptions(handle,1001,-1)) REdSetAutoURL(hREd,1) REdSetEventMask(hREd,1|67108864) Text2Add = StrCat("Hello there.",@CRLF,"This is a Rich Edit Control with scroll bars.",@CRLF,"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!") Text2Add = StrCat(Text2Add,@CRLF,"This is a URL link that should be detected automatically:") Text2Add = StrCat(Text2Add,@CRLF,"http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditnotificationmessages/en_link.asp") For NewLine = 1 To 20 Text2Add = StrCat(Text2Add,@CRLF,"Another Line ",NewLine) Next NewLine EnteredText = EdSetText(hREd,Text2Add) Case 2 ;Button pushed Select id Case 1 Message("Returned Edit Box Text",EdGetText(hREd)) Message("Returned OLE interface Pointer - How to use???!!!",REdGetOLEInterface(hREd)) Return -2 EndSelect Return -1 #EndSubRoutine MyDialogFormat=`WWWDLGED,6.1` MyDialogCaption=`WIL Dialog 1` MyDialogX=539 MyDialogY=-30 MyDialogWidth=334 MyDialogHeight=269 MyDialogNumControls=002 MyDialogProcedure=`dlgproc` MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT,176|160|192` MyDialogConfig=0 MyDialog001=`005,249,054,012,PUSHBUTTON,DEFAULT,"Return Test Stuff",1,1,32,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`271,249,054,012,PUSHBUTTON,DEFAULT,"Cancel",0,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT` ButtonPushed=Dialog("MyDialog") Exit
Article ID: W17779
Filename: DllCall Rich Edit Control.txt
File Created: 2009:09:22:08:04:58
Last Updated: 2009:09:22:08:04:58