We need to unscale the passed coordinates. Also some adjustments because of the change of window style. Looks fine at 192 DPI; check it in your system.
Function frmTemplates_Show (ByVal hParent As HWnd, ByVal x As Long, ByVal y As Long) As Long
Dim pWindow As CWindow Ptr = New CWindow
pWindow->DPI = AfxCWindowPtr(hParent)->DPI
pWindow->Create(hParent, "Templates", @frmTemplates_WndProc, pWindow->UnScaleX(x) + 5, pWindow->UnscaleY(y) + 5, 420, 405, _
WS_VISIBLE Or WS_CAPTION Or WS_POPUPWINDOW, WS_EX_WINDOWEDGE)
pWindow->SetClientSize(415, 380)
' Set the small and large icon for the main window (must be set after main window is created)
pWindow->BigIcon = LoadImage( pWindow->InstanceHandle, "IMAGE_MAINICON", IMAGE_ICON, 32, 32, LR_SHARED)
pWindow->SmallIcon = LoadImage( pWindow->InstanceHandle, "IMAGE_MAINICON", IMAGE_ICON, 16, 16, LR_SHARED)
' Add a listbox
Dim hListBox As HWnd = pWindow->AddControl("ListBox", , IDC_FRMTEMPLATES_LISTBOX, "", _
WS_CHILD Or WS_VISIBLE Or WS_HSCROLL Or WS_VSCROLL Or WS_BORDER Or WS_TABSTOP Or _
LBS_STANDARD Or LBS_HASSTRINGS Or LBS_SORT Or LBS_NOTIFY Or LBS_NOINTEGRALHEIGHT, WS_EX_CLIENTEDGE)
pWindow->SetWindowPos hListBox, Null, 8, 8, 399, 335, SWP_NOZORDER
SendMessageW hListBox, LB_SETHORIZONTALEXTENT, Cast(WPARAM, 600 * pWindow->rxRatio), 0
' Add the buttons
pWindow->AddControl("Button", , IDOK, "&OK", 245, 343, 74, 28, _
WS_CHILD Or WS_VISIBLE Or WS_TABSTOP Or BS_FLAT Or BS_DEFPUSHBUTTON, WS_EX_NOPARENTNOTIFY)
pWindow->AddControl("Button", , IDCANCEL, "&Cancel", 333, 343, 74, 28, _
WS_CHILD Or WS_VISIBLE Or WS_TABSTOP Or BS_FLAT, WS_EX_NOPARENTNOTIFY)
this.FindReplace( "|", "" ) fails because FB strings are asciiz strings and it passes a null pointer instead of a pointer to an empty string. We could ulse a BSTR, but as your workaround works, it isn't needed.
What I can't find is why the view is not scrolled to the position of the caret. We are using SciMsg( m_pSci, SCI_GOTOPOS, newPos, 0) and SCI_GOTOPOS sets the caret at pos and scrolls the view to make the caret visible, if necessary. The purpose of "|" is to set a position where the view will be scrolled; otherwise, does not make sense.