Skip to content

Commit

Permalink
RTB shadow test
Browse files Browse the repository at this point in the history
not working so far..
  • Loading branch information
StackerDEV committed Jul 11, 2018
1 parent 1f4b350 commit c67d13a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Client/Forms/FrmChat.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion Client/Forms/FrmChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public struct CHARFORMAT2
const int CFM_LCID = 0x2000000;
const int CFM_REVAUTHOR = 0x8000;
const int EM_SETCHARFORMAT = 0x444;

private const Int32 SCF_SELECTION2 = 0x0001;
private const UInt32 WM_USER = 0x0400;
private const UInt32 EM_GETCHARFORMAT = (WM_USER + 58);
const UInt32 CFE_BOLD = 0x0001;
const UInt32 CFM_BOLD = 0x00000001;
const UInt32 CFM_SHADOW = 0x0400;

const int SCF_SELECTION = 0x1;
const int SCF_WORD = 0x2;

Expand Down Expand Up @@ -277,7 +285,8 @@ private void AppendText(RichTextBox box, string text, Color color, bool bold = f
else
{
box.SelectionColor = color;
}
}

box.AppendText(text);
box.SelectionColor = box.ForeColor;
box.ScrollToCaret();
Expand Down Expand Up @@ -359,6 +368,29 @@ private void clickableUserName(string username, string fullmsg)
Marshal.StructureToPtr(myFormat, lParam, false);
SendMessage(ChatWindow.Handle, (UInt32)EM_SETCHARFORMAT, (IntPtr)(SCF_SELECTION + SCF_WORD), lParam);
}

private void SetEffectTest(UInt32 mask, UInt32 effect, bool valid)
{
CHARFORMAT2 fmt = new CHARFORMAT2();
fmt.cbSize = Marshal.SizeOf(fmt);
fmt.dwMask = (int)mask;
fmt.dwEffects = valid ? (int)effect : 0;
IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmt));
Marshal.StructureToPtr(fmt, lParam, false);
SendMessage(ChatWindow.Handle, EM_SETCHARFORMAT, (IntPtr)SCF_SELECTION2, lParam);
}

//did not got this working, but its a solution to the chatwindow color.
//https://stackoverflow.com/questions/1268009/reset-rtf-in-richtextbox
private void btnShadowTest_Click(object sender, EventArgs e)
{
CHARFORMAT2 _charFormat = new CHARFORMAT2();
_charFormat.cbSize = Marshal.SizeOf(_charFormat);
IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(_charFormat));
Marshal.StructureToPtr(_charFormat, lParam, false);
SendMessage(ChatWindow.Handle, EM_GETCHARFORMAT, (IntPtr)SCF_SELECTION, lParam);
SetEffectTest(CFM_SHADOW, CFM_SHADOW, true);
}

private void FrmChat_Load(object sender, EventArgs e)
{
Expand Down

4 comments on commit c67d13a

@StackerDEV
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MSDN:
CFE_SHADOW
Characters are displayed as shadowed characters. The value does not affect how the control displays the text.

@Cyclone47
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Application runs slow when clicking the button.

@StackerDEV
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cyclone47 please read the code;
//did not got this working, but its a solution to the chatwindow color.

I have no idea how to implement this. MSDN is not helpful enough..

@StackerDEV
Copy link
Collaborator Author

@StackerDEV StackerDEV commented on c67d13a Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too lazy to figure it out myself this time, I have worked with SendMessage and enum in the past with c++, but it was a lot easier to understand somehow.. It also was searching for class/handle and then simply do WM_GETTEXT/SETTEXT instead of messing with the complete struct for text styling.
https://stackoverflow.com/questions/51306510/sendmessage-charformat2-text-effect-cfe-shadow

Please sign in to comment.