Restored from previous forum. Originally posted by Don.
I'm very new to PureBasic but I'm really impressed with what I've seen so far. I have one particular problem though ...
I've been using the richedit32.dll and all seems to work fine with SendMessage except anything which involves far pointers to structures. For example, the CHARFORMAT structure used when sending the EM_SETCHARFORMAT or EM_GETCHARFORMAT message never seems to work - SendMessage always fails with a return of zero.
Am I doing something stupid here, or is there a problem with the use of far pointers in PureBasic? Any help would be really appreciated.
Here's some code which demonstrates my problem:
#RICHEDIT = #WS_CHILD | #WS_VISIBLE |#WS_VSCROLL |#ES_MULTILINE |#ES_AUTOVSCROLL
#WINDOW_PARAMETERS = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
#WindowHeight = 400
#WindowWidth = 470
cf.CHARFORMAT
cf\cbSize=27
cf\dwMask=#CFM_COLOR
cf\crTextColor=$000000ff
If CreateMenu(0)
MenuTitle("Test")
MenuItem(1,"&Try it!")
EndIf
hwmain=OpenWindow(0,100,100, #WindowWidth, #WindowHeight, #WINDOW_PARAMETERS ,"RichEdit Test")
If hwmain
AttachMenu(0, WindowID())
module = LoadLibrary_("RICHED32.DLL")
cs.CREATESTRUCT
hwn = CreateWindowEx_(#WS_EX_CLIENTEDGE ,"RichEdit","Some sample text",#RICHEDIT,1,4,#WindowWidth-10, #WindowHeight-50,hwmain,1,module,cs)
SetFocus_(hwn)
EndIf
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_EventMenu
If EventMenuID() = 1
ret=SendMessage_(hwn, #EM_SETCHARFORMAT, #SCF_SELECTION, cf) ;
MessageRequester ("Result", "SendMessage returned "+str(ret), 0)
EndIf
EndIf
Until EventID=#PB_EventCloseWindow
End
RichEdit and far pointer structures
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Mr.Skunk.
Hi,
I'm not a RichEdit specialist, but your structure cf.CHARFORMAT only contains :
cf\cbSize=27
cf\dwMask=#CFM_COLOR
cf\crTextColor=$000000ff
and it should contain :
typedef struct _charformat {
UINT cbSize;
_WPAD _wPad1;
DWORD dwMask;
DWORD dwEffects;
LONG yHeight;
LONG yOffset;
COLORREF crTextColor;
BYTE bCharSet;
BYTE bPitchAndFamily;
TCHAR szFaceName[LF_FACESIZE];
_WPAD _wPad2;
} CHARFORMAT;
Perhaps the error is here...
But have tou tried the RichEdit Library from Wavemaker ?
If not, you can download it here : http://www.reelmediaproductions.com/pb/
Hope it helps...
Mr Skunk
Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
Hi,
I'm not a RichEdit specialist, but your structure cf.CHARFORMAT only contains :
cf\cbSize=27
cf\dwMask=#CFM_COLOR
cf\crTextColor=$000000ff
and it should contain :
typedef struct _charformat {
UINT cbSize;
_WPAD _wPad1;
DWORD dwMask;
DWORD dwEffects;
LONG yHeight;
LONG yOffset;
COLORREF crTextColor;
BYTE bCharSet;
BYTE bPitchAndFamily;
TCHAR szFaceName[LF_FACESIZE];
_WPAD _wPad2;
} CHARFORMAT;
Perhaps the error is here...
But have tou tried the RichEdit Library from Wavemaker ?
If not, you can download it here : http://www.reelmediaproductions.com/pb/
Hope it helps...
Mr Skunk
Mr Skunk's PureBasic Web Page
http://www.skunknet.fr.st
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by wavemaker.
I'm no API specialist either, and your code should probably work. Maybe there's something wrong in the CreateWindowEx thing, I don't know. If you want to test my library (source code available), use this code after installing the library. It may indicate you where the problem is.
By the way, there's a third version of the RichEdit library on it's way, with a RichEdit font requester (underlines, color, and that stuff), and some more stupid functions. Also an update for the CGI library which will allow to call a child process (i.e, Php, Perl) and send data to it. I know this thread doesn't relate to that, I just wanted someone to know XD
Regards,
Juan Calderón Alonso
Registered user
Edited by - wavemaker on 21 October 2001 05:19:46
I'm no API specialist either, and your code should probably work. Maybe there's something wrong in the CreateWindowEx thing, I don't know. If you want to test my library (source code available), use this code after installing the library. It may indicate you where the problem is.
Code: Select all
;
; TEST (Sorry, you must use my RichEdit library available from
; [url]http://www.reelmediaproductions.com/pb[/url] or the Purebasic example using win32 APIs
; posted somewhere in the forum last month)
;
; This is not other that the CHARFORMAT structure, but can't use that name because
; PureBasic recognizes it, and you should probably use it,
; but I don't know if it uses the same variable names I do
Structure CHARACTER
cbSize.l
dwMask.l
dwEffects.l
yHeight.l
yOffset.l
crTextColor.l
bCharSet.b
bPitchAndFamily.b
szFaceName.s
EndStructure
cf.CHARACTER
FaceName.s = "Times New Roman"
; Some constants not recognized by PB
#CFM_BACKCOLOR = $04000000
#CFM_WEIGHT = $400000
#SCF_ALL = 4
; Our CHARACTER (CHARFORMAT) instance
cf\cbSize = 26 + 34;Len(FaceName)
cf\dwMask = #CFM_COLOR|#CFM_BOLD|#CFM_ITALIC|#CFM_BACKCOLOR|#CFM_SIZE|#CFM_FACE|#CFM_WEIGHT
cf\dwEffects = #CFE_BOLD|#CFE_ITALIC
cf\yHeight = 200
cf\yOffset = 0
cf\crTextColor = $00FF0080
cf\bCharSet = #DEFAULT_CHARSET
cf\bPitchAndFamily = 0;#FIXED_PITCH|#FF_MODERN
cf\szFaceName = FaceName
InitRichEdit();
InitGadget(2);
If OpenWindow(0,200,200,400,400,#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget, "Charformat test")
If CreateGadgetList(WindowID())
ButtonGadget(1,10,10,100,25,"C'mon!")
rehwn=RichEditGadget(2, 10, 45, 380, 315, "Hey, I'm" + chr(13) + chr(10) + "multilined, editable and scrollable",#WS_CHILD|#WS_VISIBLE|#WS_VSCROLL|#ES_MULTILINE|#ES_AUTOVSCROLL)
EndIf
EndIf
done=1
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_EventGadget
EventGadID.l = EventGadgetID()
Select EventGadID
Case 1
If done
SendMessage_(rehwn,#EM_SETCHARFORMAT,#SCF_ALL,@cf)
EndIf
done=0
;
; In the next library version, you will be able to code this (I'm just finishing with font dialog and set RTF text)
;
; SetRichEditFont(1, "Arial", #CFE_BOLD|#CFE_ITALIC|#CFE_UNDERLINE, 220, 0, $C4C4C4, #DEFAULT_CHARSET, #VARIABLE_PITCH|#FF_SWISS);
;
Default
; Hi
EndSelect
Default
; Hi
EndSelect
Until EventID=#PB_EventCloseWindow
End
Regards,
Juan Calderón Alonso
Registered user
Edited by - wavemaker on 21 October 2001 05:19:46
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fred.
In fact, it was the CHARFORMAT structure which was bad ! The first pad is wrong (Thanx goes to MS doc...). It will be corrected in the next release, but for now you can use the following fixed one. Note the SizeOf() keyword, useful when coding Win32 API.
Fred - AlphaSND
In fact, it was the CHARFORMAT structure which was bad ! The first pad is wrong (Thanx goes to MS doc...). It will be corrected in the next release, but for now you can use the following fixed one. Note the SizeOf() keyword, useful when coding Win32 API.
Code: Select all
#RICHEDIT = #WS_CHILD | #WS_VISIBLE |#WS_VSCROLL |#ES_MULTILINE |#ES_AUTOVSCROLL
#WINDOW_PARAMETERS = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget
#WindowHeight = 400
#WindowWidth = 470
Structure CHARFORMAT_FIXED
cbSize.l;
;_wPad1.w; <- Not needed.. Crap Win32.hlp !
dwMask.l;
dwEffects.l;
yHeight.l;
yOffset.l;
crTextColor.l;
bCharSet.b;
bPitchAndFamily.b;
szFaceName.b[#LF_FACESIZE];
_wPad2.w;
EndStructure
cf.CHARFORMAT_FIXED
cf\cbSize=sizeof(CHARFORMAT_FIXED)
cf\dwMask=#CFM_COLOR
cf\crTextColor=$000000ff
If CreateMenu(0)
MenuTitle("Test")
MenuItem(1,"&Try it!")
EndIf
hwmain=OpenWindow(0,100,100, #WindowWidth, #WindowHeight, #WINDOW_PARAMETERS ,"RichEdit Test")
If hwmain
AttachMenu(0, WindowID())
module = LoadLibrary_("RICHED32.DLL")
cs.CREATESTRUCT
hwn = CreateWindowEx_(#WS_EX_CLIENTEDGE ,"RichEdit","Some sample text",#RICHEDIT,1,4,#WindowWidth-10, #WindowHeight-50,hwmain,1,module,cs)
SetFocus_(hwn)
EndIf
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_EventMenu
If EventMenuID() = 1
SendMessage_(hwn, #EM_SETCHARFORMAT, #SCF_SELECTION, cf) ; <<--- This always fails with return of zero
EndIf
EndIf
Until EventID=#PB_EventCloseWindow
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Don.
Many thanks to all of you who have replied to this (Wavemaker - I look forward to your new Richedit library!).
Fred - you're exactly right. The CHARFORMAT structure is wrong in the Win32 help file. It's interesting that the M$ API RichEdit header file defines _WPAD like this:
/*
* To make some structures which can be passed between 16 and 32 bit windows
* almost compatible, padding is introduced to the 16 bit versions of the
* structure.
*/
#ifdef _WIN32
# define _WPAD /##/
#else
# define _WPAD WORD
#endif
They're right when they say almost compatible!
WIN32N.inc and Purebasic itself should use this structure for CHARFORMAT:
STRUC CHARFORMAT
.cbSize RESD 1
.dwMask RESD 1
.dwEffects RESD 1
.yHeight RESD 1
.yOffset RESD 1
.crTextColor RESD 1
.bCharSet RESB 1
.bPitchAndFamily RESB 1
.szFaceName RESB LF_FACESIZE
._wPad2 RESW 1
ENDSTRUC
Anyway, in the meantime, the CHARFORMAT_FIXED structure you've provided is great. I would never have known to leave out _wPad1 but to keep _wPad2!!
So now I can get RICHED32.DLL to do everything I want to. It all works fine. eg.:
.
.
cf.CHARFORMAT_FIXED
cf\cbSize=SizeOf(CHARFORMAT_FIXED)
cf\dwMask=#CFM_COLOR | #CFM_FACE | #CFM_SIZE
cf\crTextColor=$000000ff
cf\yHeight=280
font.s="Comic Sans MS"
*p.l=@cf\szFaceName[0]
pokeS(*p, font)
.
.
Thanks a lot all of you for your help.
Don
Many thanks to all of you who have replied to this (Wavemaker - I look forward to your new Richedit library!).
Fred - you're exactly right. The CHARFORMAT structure is wrong in the Win32 help file. It's interesting that the M$ API RichEdit header file defines _WPAD like this:
/*
* To make some structures which can be passed between 16 and 32 bit windows
* almost compatible, padding is introduced to the 16 bit versions of the
* structure.
*/
#ifdef _WIN32
# define _WPAD /##/
#else
# define _WPAD WORD
#endif
They're right when they say almost compatible!
WIN32N.inc and Purebasic itself should use this structure for CHARFORMAT:
STRUC CHARFORMAT
.cbSize RESD 1
.dwMask RESD 1
.dwEffects RESD 1
.yHeight RESD 1
.yOffset RESD 1
.crTextColor RESD 1
.bCharSet RESB 1
.bPitchAndFamily RESB 1
.szFaceName RESB LF_FACESIZE
._wPad2 RESW 1
ENDSTRUC
Anyway, in the meantime, the CHARFORMAT_FIXED structure you've provided is great. I would never have known to leave out _wPad1 but to keep _wPad2!!
So now I can get RICHED32.DLL to do everything I want to. It all works fine. eg.:
.
.
cf.CHARFORMAT_FIXED
cf\cbSize=SizeOf(CHARFORMAT_FIXED)
cf\dwMask=#CFM_COLOR | #CFM_FACE | #CFM_SIZE
cf\crTextColor=$000000ff
cf\yHeight=280
font.s="Comic Sans MS"
*p.l=@cf\szFaceName[0]
pokeS(*p, font)
.
.
Thanks a lot all of you for your help.
Don
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm