I've got problem converting these from VB to C++
Whidbey.
It was generate errors:
c:\chris\sample
test\synchronize_scrolling\Form1.h(204) : error C2061:
syntax error : identifier 'clsWindowSubClass'
The location:
Original VB code:
Public Sub SyncScrollBars(ByVal Handle As IntPtr, _
ByVal SubClass As
clsWindowSubClass, _
ByVal Window As Object,
_
ByRef WindowsMessage As
Message)
objParent.SyncScrollBars(MyBase.Handle, Me, _
objWindow,
WindowMessage)
It's Parameter 2 which become the problem, which are
Me in VB and this in C++.
My effort in C++:
void SyncScrollBars( IntPtr Handle, clsWindowSubClass
^SubClass, Object^ Window, ref class Message
WindowsMessage )
objParent->SyncScrollBars( this->Handle, this,
objWindow, WindowMessage );
and this error also occured:
c:\chris\sample
test\synchronize_scrolling\Form1.h(253) : error C2660:
'Project::Form1::clsRTFScrollSync::SyncScrollBars' :
function does not take 4 arguments
at this part:
objParent->SyncScrollBars( this->Handle, this,
objWindow, WindowMessage );
How to change it?
I was confused.
If you might to see the website, here is the link:
http://www.codeproject.com/KB/cpp/RTFSynchronizedScrolling.aspx
Thank you.
Here is the FULL VB source code:
Imports System.Runtime.InteropServices
Public Class clsRTFScrollSync
Private Declare Auto Function SendScrollPosMessage
_
Lib "user32.dll" Alias "SendMessage"(
_
ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As IntPtr, _
ByRef lParam As POINT) As Integer
Private Const WM_USER = &H400
Private Const EM_GETSCROLLPOS = WM_USER + 221
Private Const EM_SETSCROLLPOS = WM_USER + 222
Private Structure POINT
Public x As Integer
Public y As Integer
End Structure
Private aControls As New ArrayList
Private sbScrollBarType As
Windows.Forms.ScrollBars
Public Property ScrollBarToSync() As
Windows.Forms.ScrollBars
Get
Return sbScrollBarType
End Get
Set(ByVal Value As Windows.Forms.ScrollBars)
sbScrollBarType = Value
End Set
End Property
Public Sub AddControl(ByVal RTFControl As Object)
Dim objControlSubClass As New
clsWindowSubClass(RTFControl.Handle, _
RTFControl, Me)
aControls.Add(objControlSubClass)
End Sub
Public Sub SyncScrollBars(ByVal Handle As IntPtr,
_
ByVal SubClass As
clsWindowSubClass, _
ByVal Window As Object,
_
ByRef WindowsMessage As
Message)
Static blnIgnoreMessages As Boolean
If blnIgnoreMessages = True Then Exit Sub
blnIgnoreMessages = True
Dim blnChangeVertPos As Boolean = False
Dim blnChangeHorizPos As Boolean = False
Dim lngVertPos, lngHorizPos As Long
Dim stcScrollPoint As New Point
Dim ptrScrollPoint As IntPtr
SendScrollPosMessage(Handle, EM_GETSCROLLPOS,
_
New IntPtr(0),
stcScrollPoint)
lngVertPos = stcScrollPoint.y
lngHorizPos = stcScrollPoint.x
If (sbScrollBarType =
RichTextBoxScrollBars.Both Or _
sbScrollBarType =
RichTextBoxScrollBars.Vertical) Then
blnChangeVertPos = True
If (sbScrollBarType =
RichTextBoxScrollBars.Both Or _
sbScrollBarType =
RichTextBoxScrollBars.Horizontal) Then
blnChangeHorizPos = True
If blnChangeVertPos = True Or
blnChangeHorizPos = True Then
Dim objSubClass As clsWindowSubClass
Dim objWindowMessage As New
Windows.Forms.Message
For Each objSubClass In aControls
If objSubClass.Handle.ToInt32 <>
Handle.ToInt32 Then
SendScrollPosMessage(objSubClass.Handle,
EM_GETSCROLLPOS, _
New
IntPtr(0), stcScrollPoint)
If blnChangeHorizPos = True Then
stcScrollPoint.x =
lngHorizPos
If blnChangeVertPos = True Then
stcScrollPoint.y =
lngVertPos
SendScrollPosMessage(objSubClass.Handle,
EM_SETSCROLLPOS, _
New
IntPtr(0), stcScrollPoint)
End If
Next
End If
blnIgnoreMessages = False
End Sub
End Class
Public Class clsWindowSubClass
Inherits System.Windows.Forms.NativeWindow
Private objWindow As Object
Private objParent As clsRTFScrollSync
Public Sub New(ByVal Handle As IntPtr, ByVal
Window As Object,
ByVal Parent As
clsRTFScrollSync)
objWindow = Window
objParent = Parent
MyBase.AssignHandle(Handle)
End Sub
Protected Overrides Sub WndProc(ByRef
WindowMessage As _
system.Windows.Forms.Message)
MyBase.WndProc(WindowMessage)
objParent.SyncScrollBars(MyBase.Handle, Me, _
objWindow,
WindowMessage)
End Sub
End Class
Here is what I've tried to convert into C++ Whidbey:
public: ref class clsRTFScrollSync {
[DllImport("user32.dll")] //, EntryPoint =
"SendMessage", CharSet = CharSet::Auto, SetLastError =
true, ExactSpelling = true)];
static int SendScrollPosMessage(IntPtr hWnd, int Msg,
IntPtr ^wParam, POINT ^lParam);
private: static int const WM_USER = 1024;
private: static int const EM_GETSCROLLPOS = WM_USER +
221;
private: static int const EM_SETSCROLLPOS = WM_USER +
222;
private: ref struct POINT{
public: int x;
public: int y;
};
private: ArrayList ^aControls; //jgn lupa init gcnew
ArrayList
private: ScrollBars ^sbScrollBarType; // As
Windows.Forms.ScrollBars
public: property ScrollBars ^ScrollBarToSync {
ScrollBars ^get() {
return sbScrollBarType;
}
void set(ScrollBars ^Value) {
sbScrollBarType = Value;
}
}
public: void AddControl(Control ^RTFControl) {
clsWindowSubClass ^objControlSubClass;
objControlSubClass->New(RTFControl->Handle,
RTFControl, this);
aControls = gcnew ArrayList();
aControls->Add(objControlSubClass);
}
public:
void SyncScrollBars( IntPtr Handle,
clsWindowSubClass ^SubClass, Object^ Window, ref class
Message WindowsMessage ) {
static bool blnIgnoreMessages;// As Boolean
//if( blnIgnoreMessages == true )
//exit(0); // Sub
blnIgnoreMessages = true;
bool blnChangeVertPos = false;
bool blnChangeHorizPos = false;
long lngVertPos, lngHorizPos;
Point^ stcScrollPoint = gcnew Point();
IntPtr ^ptrScrollPoint;
SendScrollPosMessage( Handle, EM_GETSCROLLPOS, gcnew
IntPtr(0), stcScrollPoint );
lngVertPos = stcScrollPoint->Y;
lngHorizPos = stcScrollPoint->X;
//sbScrollBarType = ScrollBars::
if ( sbScrollBarType == ScrollBars::Both ||
sbScrollBarType == ScrollBars::Vertical )
blnChangeVertPos = true;
if (sbScrollBarType == ScrollBars::Both ||
sbScrollBarType == ScrollBars::Horizontal)
blnChangeHorizPos = true;
if ( blnChangeVertPos == true || blnChangeHorizPos
== true ) {
clsWindowSubClass ^objSubClass;
Message ^objWindowMessage = gcnew Message();
for each (objSubClass in aControls) {
if ( Convert::ToInt32(objSubClass->Handle) !=
Convert::ToInt32(Handle) ) {
SendScrollPosMessage(objSubClass->Handle,
EM_GETSCROLLPOS, gcnew IntPtr(0), stcScrollPoint);
if ( blnChangeHorizPos == true )
stcScrollPoint->X = lngHorizPos;
if ( blnChangeVertPos == true )
stcScrollPoint->Y = lngVertPos;
SendScrollPosMessage(objSubClass->Handle,
EM_SETSCROLLPOS, gcnew IntPtr(0), stcScrollPoint);
}
} //for each
} //if ( blnChangeVertpos == true ||
blnChangeHorizPos == true )
blnIgnoreMessages = false;
} //end of void SyncScrollBars
}; //end of class clsRTFScrollSync
ref class clsWindowSubClass :
System::Windows::Forms::NativeWindow {
private: Object ^objWindow; // As Object
private: clsRTFScrollSync ^objParent;
public:
void New( IntPtr Handle, Object ^Window,
clsRTFScrollSync ^Parent ) {
objWindow = Window;
objParent = Parent;
this->AssignHandle(Handle);
}
protected: virtual void WndProc(
System::Windows::Forms::Message WindowMessage )
override {
this->WndProc(WindowMessage);
objParent->SyncScrollBars( this->Handle, this,
objWindow, WindowMessage );
}
};
[Edited by - mittens on February 24, 2008 3:33:47 PM]