Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call back function

Status
Not open for further replies.

raghu75

Programmer
Nov 21, 2000
66
IN
All,
How can i pass a member variable of my class to the callback function .
Is this possible.if so pl. share me the code.
 
//file app.h
#if !defined(__APP_H)
#define __APP_H
#include<windows.h>
#include<string>
class CFWnd
{
static LRESULT CALLBACK xWndProc(HWND,int,WPARAM,LPARAM);
friend class CFWndClass;
HWND hWnd;
class CFWndClass:public WNDCLASS
{
friend class CFWnd;
bool isRegistered;
std::string sName;
public:
CFWndClass(char* name=&quot;name&quot;)
{
sName=name;
int* x=new int;
*x=100;
cbClsExtra=0;
cbWndExtra=0;
hbrBackground=(HBRUSH)1;
hCursor=LoadCursor(0,IDC_ARROW);
hIcon=LoadIcon(0,IDI_APPLICATION);
hInstance=GetModuleHandle(0);
lpfnWndProc=(WNDPROC)xWndProc;
lpszClassName=sName.begin();
lpszMenuName=0;
style=CS_HREDRAW|CS_VREDRAW;
//RegisterClass(this);
}
CFWndClass& Create();
};
CFWndClass cfWndCls;
bool isInitialized;
public:
CFWnd():isInitialized(false){}
virtual ~CFWnd(){}
virtual void initialize(){}
virtual bool WndProc(HWND,int,WPARAM,LPARAM);
operator HWND(){return hWnd;}
CFWnd& Create();
void test(){MessageBox(0,&quot;hello people&quot;,&quot;&quot;,0);}
void show(int nCmdShow = SW_SHOW)
{
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
}
};
#endif
//end of app.h
////////////////////////////////////////////////
////////////////////////////////////////////////
//app.cpp
#include<windows.h>
#include&quot;app.h&quot;
#include<string>
#include<strstream>
using namespace std;
CFWnd& CFWnd::Create()
{
CFWndClass x;
RegisterClass(&cfWndCls);
hWnd=CreateWindow(cfWndCls.sName.c_str(),
cfWndCls.sName.c_str(),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
0,0,GetModuleHandle(0),0);
SetWindowLong(hWnd,GWL_USERDATA,(long)this);
return *this;
}
bool CFWnd::WndProc(HWND,int,WPARAM,LPARAM)
{
return true;
}
LRESULT CALLBACK CFWnd::xWndProc(HWND hWnd,int message,WPARAM wParam,LPARAM lParam)
{
ostrstream xxx;


CFWnd* x=(CFWnd*)GetWindowLong(hWnd,GWL_USERDATA);
if(x==0)
{
return DefWindowProc(hWnd,message,wParam,lParam);
}
if(!x->isInitialized)
{
x->initialize();
x->isInitialized = true;
}
switch(message)
{
case WM_CREATE:
MessageBox(0,&quot;&quot;,&quot;&quot;,0);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
if(!x->WndProc(hWnd,message,wParam,lParam))
{
return 0;
}
return DefWindowProc(hWnd,message,wParam,lParam);
}
//end of app.cpp
//test.cpp
#include &quot;app.h&quot;
int main()
{
CFWnd xx;
xx.Create();
xx.show();
MSG* msg = new MSG;
while(GetMessage(msg,0,0,0))
{
TranslateMessage(msg);
DispatchMessage(msg);
}
return 0;
} John Fill
1c.bmp


ivfmd@mail.md
 
Maybe it is not the best architecture, but it works. I did it very quickly. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top