There is a reason the I want to do this, I need to debug how the other program is formatting the text. I found this post here, and took the sample at post #7 as a base to build on; (thank you ian mcallister):
But it causes the target application to crash. So I'm thinking this is because I'm stepping outside the box and doing something not according to specs. I can interrogate the control:
And the control returns a non-zero value (&h1A), so that works, but attempting to stream from the control fails. With a crash of the target richedit control containing application.
But it causes the target application to crash. So I'm thinking this is because I'm stepping outside the box and doing something not according to specs. I can interrogate the control:
Code:
msgTextMode = SendMessage(hRichEdit, %EM_GETTEXTMODE, 0, 0) #DEBUG PRINT "msgTextMode="& BIN$(msgTextMode)
Code:
#PBFORMS CREATED V1.51 '------------------------------------------------------------------------------ ' The first line in this file is a PB/Forms metastatement. ' It should ALWAYS be the first line of the file. Other ' PB/Forms metastatements are placed at the beginning and ' end of "Named Blocks" of code that should be edited ' with PBForms only. Do not manually edit or delete these ' metastatements or PB/Forms will not be able to reread ' the file correctly. See the PB/Forms documentation for ' more information. ' Named blocks begin like this: #PBFORMS BEGIN ... ' Named blocks end like this: #PBFORMS END ... ' Other PB/Forms metastatements such as: ' #PBFORMS DECLARATIONS ' are used by PB/Forms to insert additional code. ' Feel free to make changes anywhere else in the file. '------------------------------------------------------------------------------ #COMPILE EXE #DIM ALL '------------------------------------------------------------------------------ ' ** Includes ** '------------------------------------------------------------------------------ #PBFORMS BEGIN INCLUDES #RESOURCE "readrich.pbr" #INCLUDE "WIN32API.INC" #INCLUDE "RichEdit.inc" #PBFORMS END INCLUDES '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Constants ** '------------------------------------------------------------------------------ #PBFORMS BEGIN CONSTANTS %IDB_GETTEXT = 1002 %IDD_READRICHEDIT = 101 %IDL_hRichEdit = 1003 %IDM_EDIT_COPY = 1008 %IDM_EDIT_CUT = 1009 %IDM_EDIT_SELECTALL = 1007 %IDM_FILE_EXIT = 1006 %IDR_ACCELERATOR1 = 103 %IDR_IMGFILE1 = 104 %IDR_MENU1 = 102 %IDSB_STATUS = 1005 %IDT_hRichEdit = 1001 %IDT_RESULTS = 1004 #PBFORMS END CONSTANTS '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Declarations ** '------------------------------------------------------------------------------ DECLARE CALLBACK FUNCTION ShowREADRICHEDITProc() DECLARE FUNCTION ShowREADRICHEDIT(BYVAL hParent AS DWORD) AS LONG DECLARE FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD DECLARE FUNCTION AttachACCELERATOR1(BYVAL hDlg AS DWORD) AS DWORD DECLARE FUNCTION ASSIGNACCEL(tAccel AS ACCELAPI, BYVAL wKey AS WORD, BYVAL _ wCmd AS WORD, BYVAL byFVirt AS BYTE) AS LONG #PBFORMS DECLARATIONS '------------------------------------------------------------------------------ GLOBAL gRichEdit AS STRING FUNCTION RichEditStreamGetCallback(BYVAL dwCookie AS DWORD, BYVAL pbBuffer AS BYTE PTR, _ BYVAL cb AS LONG, pcb AS LONG) AS DWORD gRichEdit = gRichEdit + PEEK$(pbBuffer, cb) END FUNCTION '------------------------------------------------------------------------------ ' ** Main Application Entry Point ** '------------------------------------------------------------------------------ FUNCTION PBMAIN() ShowREADRICHEDIT %HWND_DESKTOP END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** CallBacks ** '------------------------------------------------------------------------------ CALLBACK FUNCTION ShowREADRICHEDITProc() SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG ' Initialization handler CASE %WM_SIZE ' Dialog has been resized LOCAL FormX, FormY, StatusY, ButtonX, ButtonY AS LONG CONTROL SEND CBHNDL, %IDSB_STATUS, CBMSG, CBWPARAM, CBLPARAM CONTROL GET SIZE CB.HNDL, %IDSB_STATUS TO FormX, StatusY DIALOG GET CLIENT CB.HNDL TO FormX, FormY CONTROL GET SIZE CB.HNDL, %IDL_hRichEdit TO ButtonX, ButtonY CONTROL SET LOC CB.HNDL, %IDT_RESULTS, 0, ButtonY FormY = FormY - StatusY - ButtonY CONTROL SET SIZE CB.HNDL, %IDT_RESULTS, FormX, FormY CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN ' Save control focus hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_COMMAND ' Process control notifications SELECT CASE AS LONG CBCTL CASE %IDB_GETTEXT LOCAL hRichEdit, msgTextMode AS DWORD LOCAL tRichedit AS STRING LOCAL eStream AS EDITSTREAM CONTROL GET TEXT CB.HNDL, %IDT_hRichEdit TO tRichedit hRichEdit = VAL("&h"& tRichedit) #DEBUG PRINT "Richedit="& HEX$(hRichEdit, 8) msgTextMode = SendMessage(hRichEdit, %EM_GETTEXTMODE, 0, 0) #DEBUG PRINT "msgTextMode="& BIN$(msgTextMode) eStream.dwCookie = 0 eStream.dwError = 0 eStream.pfnCallback = CODEPTR(RichEditStreamGetCallback) SendMessage hRichEdit, %EM_STREAMOUT, %SF_RTF, VARPTR(eStream) #DEBUG PRINT "eStream.dwError="& HEX$(eStream.dwError, 8) CASE %IDM_EDIT_COPY CONTROL SEND CB.HNDL, %IDT_RESULTS, %WM_COPY, 0, 0 FUNCTION = 1 CASE %IDM_EDIT_CUT CONTROL SEND CB.HNDL, %IDT_RESULTS, %WM_CUT, 0, 0 FUNCTION = 1 CASE %IDM_EDIT_SELECTALL CONTROL SEND CB.HNDL, %IDT_RESULTS, %EM_SETSEL, 0, -1 FUNCTION = 1 CASE %IDM_FILE_EXIT DIALOG END CB.HNDL END SELECT END SELECT END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ ' ** Dialogs ** '------------------------------------------------------------------------------ FUNCTION ShowREADRICHEDIT(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG #PBFORMS BEGIN DIALOG %IDD_READRICHEDIT->%IDR_MENU1->%IDR_ACCELERATOR1 LOCAL hDlg AS DWORD DIALOG NEW PIXELS, hParent, "Read Rich Edit", 260, 325, 300, 319, _ %WS_POPUP OR %WS_BORDER OR %WS_THICKFRAME OR %WS_CAPTION OR _ %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR _ %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN OR %WS_VISIBLE OR _ %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR %DS_SETFONT, _ %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _ %WS_EX_RIGHTSCROLLBAR, TO hDlg DIALOG SET ICON hDlg, "#" + FORMAT$(%IDR_IMGFILE1) CONTROL ADD LABEL, hDlg, %IDL_hRichEdit, "hRichEdit", 0, 0, 50, 16 CONTROL ADD TEXTBOX, hDlg, %IDT_hRichEdit, "hRichEdit", 52, 0, 100, 16 CONTROL ADD BUTTON, hDlg, %IDB_GETTEXT, "Get Text", 154, 0, 48, 16, _ %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %BS_TEXT OR _ %BS_PUSHBUTTON OR %BS_FLAT OR %BS_CENTER OR %BS_VCENTER, %WS_EX_LEFT _ OR %WS_EX_LTRREADING CONTROL ADD TEXTBOX, hDlg, %IDT_RESULTS, "Results", 24, 32, 124, 48, _ %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR %ES_LEFT OR %ES_MULTILINE _ OR %ES_WANTRETURN OR %WS_VSCROLL, %WS_EX_LEFT OR %WS_EX_LTRREADING _ OR %WS_EX_RIGHTSCROLLBAR CONTROL ADD STATUSBAR, hDlg, %IDSB_STATUS, "Status", 18, 247, 201, 11, %WS_CHILD _ OR %WS_VISIBLE, %WS_EX_TRANSPARENT OR %WS_EX_LEFT OR _ %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR AttachMENU1 hDlg AttachACCELERATOR1 hDlg #PBFORMS END DIALOG DIALOG SHOW MODAL hDlg, CALL ShowREADRICHEDITProc TO lRslt #PBFORMS BEGIN CLEANUP %IDD_READRICHEDIT #PBFORMS END CLEANUP FUNCTION = lRslt END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ FUNCTION AttachMENU1(BYVAL hDlg AS DWORD) AS DWORD #PBFORMS BEGIN MENU %IDR_MENU1->%IDD_READRICHEDIT LOCAL hMenu AS DWORD LOCAL hPopUp1 AS DWORD MENU NEW BAR TO hMenu MENU NEW POPUP TO hPopUp1 MENU ADD POPUP, hMenu, "File", hPopUp1, %MF_ENABLED MENU ADD STRING, hPopUp1, "Exit" + $TAB + "Alt+F4", %IDM_FILE_EXIT, _ %MF_ENABLED MENU NEW POPUP TO hPopUp1 MENU ADD POPUP, hMenu, "Edit", hPopUp1, %MF_ENABLED MENU ADD STRING, hPopUp1, "Select All" + $TAB + "Ctrl+A", _ %IDM_EDIT_SELECTALL, %MF_ENABLED MENU ADD STRING, hPopUp1, "Copy" + $TAB + "Ctrl+X", %IDM_EDIT_COPY, _ %MF_ENABLED MENU ADD STRING, hPopUp1, "Cut" + $TAB + "Ctrl+X", %IDM_EDIT_CUT, _ %MF_ENABLED MENU ATTACH hMenu, hDlg #PBFORMS END MENU FUNCTION = hMenu END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ FUNCTION AttachACCELERATOR1(BYVAL hDlg AS DWORD) AS DWORD #PBFORMS BEGIN ACCEL %IDR_ACCELERATOR1->%IDD_READRICHEDIT LOCAL hAccel AS DWORD LOCAL tAccel() AS ACCELAPI DIM tAccel(1 TO 4) AS ACCELAPI ASSIGNACCEL tAccel(1), %VK_F4, %IDM_FILE_EXIT, %FVIRTKEY OR %FALT OR _ %FNOINVERT ASSIGNACCEL tAccel(2), ASC("A"), %IDM_EDIT_SELECTALL, %FVIRTKEY OR _ %FCONTROL OR %FNOINVERT ASSIGNACCEL tAccel(3), ASC("X"), %IDM_EDIT_COPY, %FVIRTKEY OR %FCONTROL _ OR %FNOINVERT ASSIGNACCEL tAccel(4), ASC("X"), %IDM_EDIT_CUT, %FVIRTKEY OR %FCONTROL OR _ %FNOINVERT ACCEL ATTACH hDlg, tAccel() TO hAccel #PBFORMS END ACCEL FUNCTION = hAccel END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ #PBFORMS BEGIN ASSIGNACCEL FUNCTION ASSIGNACCEL(tAccel AS ACCELAPI, BYVAL wKey AS WORD, BYVAL wCmd AS _ WORD, BYVAL byFVirt AS BYTE) AS LONG tAccel.fVirt = byFVirt tAccel.key = wKey tAccel.cmd = wCmd END FUNCTION #PBFORMS END ASSIGNACCEL '------------------------------------------------------------------------------
Comment