I created Scintilla Popup for textbox to show autocomplete :
this.hWnd = CreateWindowEx(
0, "Scintilla", "",
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPCHILDREN | 0x00002000,
x, y, textbox1.ClientSize.Width, textbox1.ClientSize.Height, textbox1.Handle, (IntPtr)0, (IntPtr)0, (IntPtr)0);
and in custom textbox, i overriden WndProc :
protected override void WndProc(ref Message m)
{
}
I build project in x86, and each time i call "SendMessage", the autocomplete showed on textbox and WndProc called. But when i build project in x64, only autocomplete showed and WndProc not called. Please, help me ??
Thanks.
EDIT: Added code below, previously posted by OP as an answer
@o_weisman, this is my custom textbox :
public partial class ScintillaControl : TextBox
{
ScintillaWrapper sw = null;
public ScintillaWrapper Scintilla
{
get { return this.sw; }
}
LanguageType languageType = LanguageType.CS;
public LanguageType LanguageType
{
get { return languageType; }
set { languageType = value; }
}
bool useBuiltInPopupMenu = true;
public bool UseBuiltInPopupMenu
{
get { return useBuiltInPopupMenu; }
set { useBuiltInPopupMenu = value; }
}
bool _notModified = false;
public bool NotModified
{
get { return _notModified; }
set { _notModified = value; }
}
public ScintillaControl()
{
this.Multiline = true;
this.AcceptsTab = true;
// this.ShortcutsEnabled = true;
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
const int WM_KEYDOWN = 0x100;
var keyCode = (Keys)(msg.WParam.ToInt32() &
Convert.ToInt32(Keys.KeyCode));
if ((msg.Msg == WM_KEYDOWN && keyCode == Keys.A)
&& (ModifierKeys == Keys.Control)
)
{
this.SelectAll();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
public new bool Enabled
{
get { return base.Enabled; }
set
{
base.Enabled = value;
Color bkColor = (value ? Color.White : System.Drawing.SystemColors.ControlLight);
if (this.sw != null)
this.sw.SetWindowBackground(bkColor);
}
}
//[DllImport("User32.dll")]
//private static extern int GetAsyncKeyState(int vKey);
private bool DetectCtrlPressed()
{
Keyboard kb = new Keyboard();
return kb.CtrlKeyDown;
//int detectCtrlPressed = GetAsyncKeyState(0x11);
//return (detectCtrlPressed == 32768 || detectCtrlPressed == -32767);
}
private bool DetectCtrlShiftPressed()
{
Keyboard kb = new Keyboard();
return kb.CtrlKeyDown && kb.ShiftKeyDown;
}
private bool DetectShiftPressed()
{
Keyboard kb = new Keyboard();
return kb.ShiftKeyDown;
}
protected override void OnCreateControl()
{
base.OnCreateControl();
CreateScintillaControl();
}
public void CreateScintillaControl()
{
if (this.sw != null)
return;
try
{
this.sw = new ScintillaWrapper();
this.sw.MapForm = this.mapForm;
this.sw.ParentControl = this;
this.sw._CreateWindow(0, 0, this.ClientSize.Width, this.ClientSize.Height, this, languageType);
this.sw._DisableBuiltInPopupMenu(this.useBuiltInPopupMenu);
//Trace.Listeners.Add(new TextWriterTraceListener("C:\\trace.txt"));
}
catch (Exception ex)
{
MessageBox.Show("error while creating scintilla wrapper, ex: " + ex.ToString());
}
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
if (this.sw != null)
this.sw._ChangeSize(new Point(0, 0), new Size(this.ClientSize.Width, this.ClientSize.Height));
}
public delegate void ScintillaDoubleClick(int lineNumber, string content);
public event ScintillaDoubleClick OnScintillaDoubleClick = null;
private void DoOnScintillaDoubleClick(int lineNumber, string content)
{
if (this.OnScintillaDoubleClick != null)
this.OnScintillaDoubleClick(lineNumber, content);
}
public delegate void TrackPopupMenu(Point p);
public event TrackPopupMenu OnTrackPopupMenu = null;
private void DoOnTrackPopupMenu(Point p)
{
if (this.OnTrackPopupMenu != null)
this.OnTrackPopupMenu(p);
}
public delegate void CodeChanged(ScintillaControl control);
public event CodeChanged OnCodeChanged = null;
private void DoOnCodeChanged(ScintillaControl control)
{
if (this.OnCodeChanged != null)
this.OnCodeChanged(control);
}
public delegate void SelectionChanged(bool isChanged);
public event SelectionChanged OnSelectionChanged = null;
private void DoOnSelectionChanged(bool isChanged)
{
if (this.OnSelectionChanged != null)
this.OnSelectionChanged(isChanged);
}
public delegate void ModifyCode();
public event ModifyCode OnModifyCode = null;
private void DoOnModifyCode()
{
this.sw.ReDrawLineNumberPanel();
if (this.OnModifyCode != null)
this.OnModifyCode();
}
public delegate void UIChangedDelegate();
public event UIChangedDelegate OnUIChanged = null;
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
this.sw._SetFocus();
}
private const int WM_PASTE = 0x0302;
protected override void WndProc(ref Message m)
{
if (m.Msg == ScintillaWrapper.SCK_DELETE)
{
this.DoOnCodeChanged(this);
}
else if (m.Msg == 0x0111 /*WM_COMMAND*/ && this.sw != null)
{
if (m.LParam == this.sw._HWnd)
{
int value = m.WParam.ToInt32();
if ((value >> 16) == 512)
{
this.Select();
//this.sw._SetFocus();
}
}
}
else if (m.Msg == 0x007B /*WM_CONTEXTMENU*/ && this.useBuiltInPopupMenu == false)
{
int value = m.LParam.ToInt32();
// tach value lam low word va high word
int lowWord = value & 0x0000FFFF;
int highWord = value >> 16;
Point p = new Point(lowWord, highWord);
this.Select();
//this.sw._SetFocus();
this.DoOnTrackPopupMenu(p);
return;
}
else if (m.Msg == 0x004E /*WM_NOTIFY*/ && this.sw != null)
{
this.ProcessNotify(m);
}
base.WndProc(ref m);
}
CalltipInfo _currentCallTip = null;
bool _hasSelect = false;
bool _hasSelect2 = false;
SCNotification tmpNotify;
private void ProcessNotify(Message m)
{
bool is64bit = Util.Utility.OtherFunction.IsOS64bit;
SCNotification notify;
uint code = 0;
if (is64bit)
{
IntPtr pDevicePathName = new IntPtr(m.LParam.ToInt64() + IntPtr.Size);
notify = (SCNotification)Marshal.PtrToStructure(pDevicePathName, typeof(SCNotification));
code = notify.idFrom;
}
else
{
notify = (SCNotification)Marshal.PtrToStructure(m.LParam, typeof(SCNotification));
code = notify.code;
}
//if (notify.hwndFrom != this.sw._HWnd)
// return;
switch (code)//(notify.code)
{
case ScintillaWrapper.SCN_MARGINCLICK:
if (notify.margin == ScintillaWrapper.MARGIN_SCRIPT_FOLD_INDEX) this.Scintilla._Fold(notify.position);
else if (notify.margin == 2)
{
this.Scintilla._ToggleBreakPoint(notify.position);
}
break;
case ScintillaWrapper.SCN_CHARADDED:
if (this.sw.GetReadOnly()) break;
if (this.sw._CharAdd(notify.ch, this.DetectCtrlPressed(), this.DetectShiftPressed()))
break;
this.DoOnModifyCode();
this.OnTextChanged(new EventArgs());
break;
case ScintillaWrapper.SCN_AUTOCSELECTION:
_hasSelect = true;
// string s = Marshal.PtrToStringAnsi(notify.text);
// this.Scintilla._AutoCompleteSelected(notify.lParam.ToInt32(), s);
break;
case ScintillaWrapper.SCN_CALLTIPCLICK:
this.Scintilla._CalltipClicked(notify.position);
break;
case ScintillaWrapper.SCN_DOUBLECLICK:
int lineNumber = this.sw.GetCurrentLine();
string content = this.sw.GetLineContent(lineNumber);
this.DoOnScintillaDoubleClick(lineNumber, content);
break;
case ScintillaWrapper.SCN_SAVEPOINTLEFT:
this.DoOnCodeChanged(this);
break;
case ScintillaWrapper.SCN_DWELLSTART:
this.sw._MouseOver(notify.position);
break;
case ScintillaWrapper.SCN_DWELLEND:
this.sw._MouseOut();
break;
case ScintillaWrapper.SCN_UPDATEUI:
this.sw._CursorChanged();
if (this.sw.GetText() != "")
{
this.getCurrentColPos();
}
if (this.OnUIChanged != null)
OnUIChanged();
//this.DoOnModifyCode();
break;
case ScintillaWrapper.SCN_MODIFIED:
if (notify.modificationType == 2064 && notify.length == 1 && _notModified == false)
{
this.DoOnModifyCode();
this.OnTextChanged(new EventArgs());
}
else if ((notify.modificationType == 1040 || notify.modificationType == 2064) && !_notModified)
{
this.DoOnModifyCode();
}
//DVC 2/4/10
if (!ReferencesHolder.IsSearching)
{
if (this.Scintilla._GetBit(1, notify.modificationType))//Delete text event
{
this.Scintilla._CheckBreakPoint(notify.position);
}
}
//End
if (_hasSelect && ((notify.modificationType & ScintillaWrapper.SC_MOD_INSERTTEXT) != 0))
{
_hasSelect2 = true;
_hasSelect = false;
}
break;
case ScintillaWrapper.SCN_SELECT_AC_ITEM:
string s = Marshal.PtrToStringAnsi(notify.text);
_currentCallTip = this.sw.ShowToolTip(new Point(notify.x, notify.y), notify.position, notify.margin, notify.message, s);
tmpNotify = notify;
break;
case ScintillaWrapper.SCN_CLOSE_AC_LIST:
this.sw.HideToolTip();
break;
//case ScintillaWrapper.SCN_PAINTED:
// break;
case ScintillaWrapper.SCK_DELETE:
this.DoOnModifyCode();
break;
default:
if (_hasSelect2)
{
AddParenthesisIfNeeded();
_hasSelect2 = false;
sw.InsertText(" ");
sw.AutoCompleteProcess.InitAutoComplete(32, sw.GetCurrentPos(), sw.GetText(), false, true);
//string s1 = Marshal.PtrToStringAnsi(tmpNotify.text);
//this.sw.ShowToolTip(new Point(tmpNotify.x, tmpNotify.y), tmpNotify.position, tmpNotify.margin, tmpNotify.message, s1);
}
bool isChanged = this.sw.HasSelection();
this.DoOnSelectionChanged(isChanged);
//this.DoOnModifyCode();
break;
}
}
public void getCurrentColPos()
{
Control parent = this.Parent;
while (!(parent == null) && !(parent.Name == "Check Output"))
{
parent = parent.Parent;
}
if (parent != null)
{
var lengthOfAlllineBefore = 0;
var currentPos = 0;
if (this.sw.GetCurrentLine() > 0)
{
for (int i = 0; i < this.sw.GetCurrentLine(); i++)
{
lengthOfAlllineBefore += this.sw.GetLineContent(i).Length;
}
currentPos = this.sw.GetCurrentPos() - lengthOfAlllineBefore;
}
else
{
currentPos = this.sw.GetCurrentPos();
}
if (parent.Controls["panel2"] != null)
{
parent.Controls["panel2"].Controls["lblCurrentColumnPosition"].Text =
string.Format("Col:{0}", currentPos);
}
}
// this.sw.get
}
private void AddParenthesisIfNeeded()
{
try
{
string text = sw.GetText();
sw.AutoCompleteProcess.DocumentString = text;
_currentCallTip = sw.AutoCompleteProcess.FindCalltipVariable(sw.GetCurrentPos() - 1, text, 0);
if (_currentCallTip == null || _currentCallTip.IsProperty)
{
return;
}
sw.InsertText("()");
sw.SetCurrentPos(sw.GetCurrentPos() - 1);
sw.ClearSelection();
_currentCallTip = null;
}
catch { }
}
public void SetSavePoint()
{
if (this.sw != null)
this.sw._SetSavePoint();
}
public void SetReadOnly(bool readOnly)
{
this.Scintilla.SetReadOnly(readOnly);
}
public void ToggleBreakPoint()
{
this.Scintilla._ToggleBreakPoint();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (this.sw != null)
this.sw.Dispose();
this.OnTrackPopupMenu = null;
this.OnCodeChanged = null;
this.OnSelectionChanged = null;
this.OnTrackPopupMenu = null;
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// ScintillaControl
//
this.Multiline = true;
this.ResumeLayout(false);
}
}
User contributions licensed under CC BY-SA 3.0