Paul, here's the debug output and my instrumented code for the first part of CreateCodeWindow().
The m_pSci() elements are = 0 when we get to the SciMsg() calls.
But the m_pSci() elements are never set at the beginning of CreateCodeWindow(). We never get inside the "if IsWindow(this.hWindow(i)) then" to set them.
[11012] BEH says: ONCOMMAND_FILEOPEN :: Before: pDoc = frmMain_OpenFileSafely(HWnd, _
[11012] BEH says: FRMMAIN_OPENFILESAFELY :: Before: pDoc = gApp.AddNewDocument()
[11012] BEH says: FRMMAIN_OPENFILESAFELY :: After: pDoc = gApp.AddNewDocument()
[11012] BEH says: FRMMAIN_OPENFILESAFELY :: Before: wszName = OnCommand_FileAutoSaveFileCheck( wszName )
[11012] BEH says: FRMMAIN_OPENFILESAFELY :: After: wszName = OnCommand_FileAutoSaveFileCheck( wszName )
[11012] BEH says: CLSDOCUMENT.CREATECODEWINDOW :: 1
[11012] BEH says: CLSDOCUMENT.CREATECODEWINDOW :: 2
[11012] BEH says: CLSDOCUMENT.CREATECODEWINDOW :: 3
[11012] BEH says: CLSDOCUMENT.CREATECODEWINDOW :: 4
[11012] BEH says: CLSDOCUMENT.CREATECODEWINDOW :: 2
[11012] BEH says: CLSDOCUMENT.CREATECODEWINDOW :: 3
[11012] BEH says: CLSDOCUMENT.CREATECODEWINDOW :: 4
[11012] BEH says: CLSDOCUMENT.CREATECODEWINDOW :: 12
[11012] BEH says: CLSDOCUMENT.CREATECODEWINDOW :: m_pSci(0) = 0
[11012] BEH says: CLSDOCUMENT.CREATECODEWINDOW :: m_pSci(1) = 0
function clsDocument.CreateCodeWindow( _
byval hWndParent as HWnd, _
byval IsNewFile as boolean, _
byval IsTemplate as boolean = false, _
byref wszFile as wstring = "" _
) as HWnd
dim ibeh as integer = 0
beh(__function__ + " :: " + str(1))
' Creates a Scintilla editing window (initially not visible). Optionally, load a diskfile
' into the window and apply properties to it.
for i as long = lbound(this.hWindow) to ubound(this.hWindow)
beh(__function__ + " :: " + str(2))
this.hWindow(i) = CreateWindowEx( 0, "Scintilla", "", _
WS_CHILD or WS_TABSTOP or WS_CLIPCHILDREN, _
0,0,0,0,hWndParent, _
cast(HMENU, IDC_SCINTILLA+i), GetModuleHandle(null), null)
beh(__function__ + " :: " + str(3))
SendMessage( this.hWindow(i), SCI_SETMODEVENTMASK, _
SC_MOD_INSERTTEXT or SC_MOD_DELETETEXT, 0 )
beh(__function__ + " :: " + str(4))
' Initialize our direct access to the Scintilla code windows. This is much faster than
' using SendMessage to the window. Only need to initialize once no matter how many
' code windows that are eventually opened.
if IsWindow(this.hWindow(i)) then
beh(__function__ + " :: " + "INSIDE 'if IsWindow(this.hWindow(i))' and i = " + str(i)) '' <<=== NEVER GET HERE
' NOTE: In my testing, need to only set the Scintilla lexer to the base editing
' window only and NOT both split windows. Also need to do this immediately after
' the window is created and do not send the message again afterwards.
' Also, every window must have a separate new call to CreateLexer. We can not
' just get one lexer and then try to share it amongst multiple new windows. When
' a window is destroyed then the pointer would be as well causing other existing
' windows to GPF.
if i = 0 then
' Load the FB lexer from Lexilla and feed it into Scintilla
beh(__function__ + " :: " + str(5))
dim as any ptr pLexer = gApp.pfnCreateLexerfn( "winfbe" )
beh(__function__ + " :: " + str(6))
SendMessage( this.hWindow(i), SCI_SETILEXER, 0, cast(LPARAM, pLexer) )
beh(__function__ + " :: " + str(7))
end if
if SciMsg = 0 then
beh(__function__ + " :: " + str(8))
SciMsg = cast( Scintilla_Directfunction, SendMessage( this.hWindow(0), SCI_GETDIRECTFUNCTION, 0, 0 ) )
beh(__function__ + " :: " + str(9))
end if
' Call the direct function for speed purposes rather than relying on the traditional SendMessage method.
beh(__function__ + " :: " + str(10))
m_pSci(i) = cast(any ptr, SendMessage( this.hWindow(i), SCI_GETDIRECTPOINTER, 0, 0 )) '' <<=== SO THESE DON'T GET SET
beh(__function__ + " :: " + str(11))
end if
next
ibeh = 11
' Disable scintilla vertical scroll bar (wParam = 1 to enable)
' SciMsg( m_pSci(0), SCI_SETVSCROLLBAR, 0, 0 )
' SciMsg( m_pSci(0), SCI_SETHSCROLLBAR, 0, 0 )
' SciMsg( m_pSci(1), SCI_SETVSCROLLBAR, 0, 0 )
' SciMsg( m_pSci(1), SCI_SETHSCROLLBAR, 0, 0 )
' Get the document pointer from our main control and assign it to the other split windows
' dim as any ptr pDoc = cast(any ptr, SciMsg(m_pSci(0), SCI_GETDOCPOINTER, 0, 0))
' if pDoc then SciMsg( m_pSci(1), SCI_SETDOCPOINTER, 0, cast(LPARAM, pDoc))
' Disable scintilla vertical scroll bar (wParam = 1 to enable)
SciExec( this.hWindow(0), SCI_SETVSCROLLBAR, 0, 0 )
SciExec( this.hWindow(0), SCI_SETHSCROLLBAR, 0, 0 )
SciExec( this.hWindow(1), SCI_SETVSCROLLBAR, 0, 0 )
SciExec( this.hWindow(1), SCI_SETHSCROLLBAR, 0, 0 )
' Get the document pointer from our main control and assign it to the other split windows
ibeh += 1 : beh(__function__ + " :: " + str(ibeh)) '' <<=== # 12
beh(__function__ + " :: " + "m_pSci(0) = " + str(m_pSci(0)))
beh(__function__ + " :: " + "m_pSci(1) = " + str(m_pSci(1)))
dim as any ptr pDoc = cast(any ptr, SciMsg(m_pSci(0), SCI_GETDOCPOINTER, 0, 0))
ibeh += 1 : beh(__function__ + " :: " + str(ibeh))
if pDoc then SciMsg( m_pSci(1), SCI_SETDOCPOINTER, 0, cast(LPARAM, pDoc))
ibeh += 1 : beh(__function__ + " :: " + str(ibeh))
NOTE: beh() is just a wrapper for OutputDebugString()...
' ------------------------------------------------------------
' ------------------------------------------------------------
declare sub beh(sstr as string)
' ------------------------------------------------------------
' BEH()
' ------------------------------------------------------------
#include once "windows.bi"
sub beh(sstr as string)
sstr = "BEH says: " + sstr + chr(13) + chr(10)
OutputDebugString(sstr)
end sub