From: "Don"
Subject: WIN32 CALLBACK problems - PLEASE HELP
Date: 1997/11/17
Message-ID:
Organization: Dummy connection record
Newsgroups: comp.lang.c++,comp.os.ms-windows.programmer.win32,fido.win32,microsoft.public.win32,microsoft.public.win32.programmer,microsoft.public.win32.programmer.kernel
Please e-mail responses to: puppy@dog.astra.co.uk
your help would be greatly appreciated
If you need help- just ask!!
Here's the problem:
I want to encapsulate my WIN32 application in a class "DbApp"
However when I try to assign my "WndProc" function to the
WindowsClass.lpfnWndProc variable for WindowsClass registration I get the
ERROR:
"Cannot convert 'long (__stdcall DbApp::*)(void *,unsigned int,unsigned
int,long)' to 'long (__stdcall *)(void *,unsigned int,unsigned int,long)'"
Notice the (__stdcall DbApp::*) to (__stdcall *) difference!
I don't understand what I need to do to allow the Windows-API to access my
"class member functions" without it being a global function,
I tried many different combinations of pointer declarations with no avail
PLEAS HELP!
here's my source code:
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
"testapp.cpp"
#include "DbApp.cpp"
#include
#include
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, LPSTR lpszArgs,
int nWinMode)
{
DbApp DataBase(hThisInst, nWinMode);
// insert and run setup program here if database isn't valid for any
reason
return DataBase.Run_Msg_Loop();
}
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
"DbApp.cpp"
#include
#include
class DbApp
{
// StatusWindow status(hWnd); // status.hwnd
// ScheduleWindow schedule(hWnd); // schedule.hwnd
// DailyLogWindow log(hWnd); // log.hwnd
LPCTSTR lpszName; // MainWindow
class name
LPCTSTR lpszTitle; // MainWindow
titlebar
public:
MSG msg;
HINSTANCE hInst; // the handle
for this instance
HWND hWnd; // the handle
for the window
WPARAM Run_Msg_Loop(); // the message
loop for the main window
// returning
from this function will exit the program!
DbApp::DbApp(HINSTANCE hThisInst, int nCmdShow); // class
constructor
// window
definition and registration
LRESULT CALLBACK WndProc(HWND hwndReceiver, UINT uMsg, WPARAM wParam,
LPARAM lParam);
};
////////////////////////////////////////////////////////////////////////////
////////////////////////
DbApp::DbApp(HINSTANCE hThisInst, int nCmdShow)
{
lpszName = "DbApp"; // MainWindow class name
lpszTitle = "Main"; // MainWindow titlebar
// DEFINE & REGISTER WINDOWS CLASS
WNDCLASSEX wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
// ** ** ** ** ** ** ** ** ** ** ** ** HERE'S MY PROBLEM
** ** ** ** ** ** ** ** ** ** ** ** **
wc.lpfnWndProc = &DbApp::WndProc; // tried (WNDPROC),
WndProc, &WndProc and others
// ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hThisInst;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // change
this later
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = lpszName;
wc.cbSize = sizeof(WNDCLASSEX);
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // change this
later
RegisterClassEx(&wc);
hInst = hThisInst; // save the current
instance handle
hWnd = CreateWindowEx(WS_EX_TOPMOST,
lpszName,
lpszTitle,
WS_CAPTION | WS_MAXIMIZEBOX | WS_MINIMIZEBOX
| WS_VISIBLE, // WS_EX_TOOLWINDOW
CW_USEDEFAULT, CW_USEDEFAULT, // X,Y location
60, 20, // width, height
NULL,
NULL,
hInst,
NULL);
if(hWnd)
{
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////
WPARAM DbApp::Run_Msg_Loop()
{
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
////////////////////////////////////////////////////////////////////////////
////////////////////////
LRESULT CALLBACK DbApp::WndProc(HWND hwndReceiver, UINT uNewMsg, WPARAM
wParam, LPARAM lParam)
{
switch(uNewMsg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{ /*
case IDM_EXIT:
DestroyWindow(hWnd);
break; */
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd, uNewMsg, wParam, lParam));
}
return(0L);
}
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
PLEASE HELP
Don E. Stewart II
puppy@dog.astra.co.uk
|