VB Lisner function in C++
Hello guys :)
I have a problem I have created a commandbutton class in c++
and it is working great I just create a new object of the class and i get a new commandbutton..
Before I started programming c++ I proggrammed a lot of visual basic..
How can I make a listner function as a member of my CommandButton class??
Visual Basic uses an ActiveX(Class) control and I automaticly get this function:
Private Sub Command1_Click()
End Sub
I want to create a similar function structure for my c++ class!
If you have programmed VB and C++ I hope you understand what I mean...
Thank you!
The best way to do it would be to with MFC, I think.
Search MSDN for it; I think it should do what you want it to.
Search MSDN for it; I think it should do what you want it to.
Yes :) but it has to be away to create listner functions in common c++ without the use of MFC and other large libraries..
My class is working like it should I just want to create different lisner funcions like on_click and on_focus etc..
My class is working like it should I just want to create different lisner funcions like on_click and on_focus etc..
OK, another way to do it would be something like this:
A bit hackish, I know, but I don't think there is a better way without MFC.
#define WIN32_LEAN_AND_MEAN#include <windows.h>#define WM_SETCLASSPTR WM_USER+1class CWindow{public: friend LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); void OnClick() {/*Do stuff here*/}protected: HWND m_wnd;};LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ static CWindow *ptr = 0; switch(uMsg) { case WM_SETCLASSPTR; ptr = (CWindow*)wParam; ptr->m_wnd = hWnd; break; case WM_LBUTTONUP: ptr->OnClick(); break; } return DefWindowProc(hWnd, uMsg, wParam, lParam);}
A bit hackish, I know, but I don't think there is a better way without MFC.
Thank you so much! The code is great :)
Correct me if I'm wrong, but the code still leave one problem unsolved..
Doesn't all the objects/buttons in the class get the
same OnClick() function?
In my CommandButton class I can create as many buttons as I want to.. Lets say I create two..
In Visual Basic i can use different code for my two different command buttons..
Private Sub Command1_Click()
'Code for first button goes here..
End Sub
Private Sub Command2_Click()
'Different code for second button goes here..
End Sub
Correct me if I'm wrong, but the code still leave one problem unsolved..
Doesn't all the objects/buttons in the class get the
same OnClick() function?
In my CommandButton class I can create as many buttons as I want to.. Lets say I create two..
In Visual Basic i can use different code for my two different command buttons..
Private Sub Command1_Click()
'Code for first button goes here..
End Sub
Private Sub Command2_Click()
'Different code for second button goes here..
End Sub
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement