Jul 31, 2001 #1 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.
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.
Jul 31, 2001 #2 Cagliostro Programmer Sep 13, 2000 4,226 GB //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 CFWndClassublic WNDCLASS { friend class CFWnd; bool isRegistered; std::string sName; public: CFWndClass(char* name="name" { 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,"hello people","",0);} void show(int nCmdShow = SW_SHOW) { ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); } }; #endif //end of app.h //////////////////////////////////////////////// //////////////////////////////////////////////// //app.cpp #include<windows.h> #include"app.h" #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,"","",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 "app.h" 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 ivfmd@mail.md Upvote 0 Downvote
//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 CFWndClassublic WNDCLASS { friend class CFWnd; bool isRegistered; std::string sName; public: CFWndClass(char* name="name" { 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,"hello people","",0);} void show(int nCmdShow = SW_SHOW) { ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); } }; #endif //end of app.h //////////////////////////////////////////////// //////////////////////////////////////////////// //app.cpp #include<windows.h> #include"app.h" #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,"","",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 "app.h" 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 ivfmd@mail.md
Jul 31, 2001 #3 Cagliostro Programmer Sep 13, 2000 4,226 GB Maybe it is not the best architecture, but it works. I did it very quickly. John Fill ivfmd@mail.md Upvote 0 Downvote