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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Procedure pointers

Status
Not open for further replies.

MuadDubby

Programmer
Sep 23, 1999
236
CA
I'm trying to start a message loop for a win32 program, and one of the parameters I have to set is the callback routine to handle the messages. But I have to assign the address of this routine to a procedure pointer, and I have no clue how to do it!

So basically, how do I set wc.lpfnWndProc to the address of WindowProc()?

I am including a piece of my code here:

WNDCLASS wc;
ATOM MyAtom;

// Register the window class for the main window.

if (!hPrevInstance)
{
wc.style = CS_NOCLOSE;
wc.lpfnWndProc = ????;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = "MainMenu";
wc.lpszClassName = "MainWndClass";

MyAtom=RegisterClass(&wc);
.
.
.


RESULT CALLBACK WindowProc(HWND hwnd, // handle of window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam) // second message parameter
{
return (LRESULT)1;
}



Thanx! [sig][/sig]
 
I always thought your message loop should be in WinMain like in the code snippet below:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
{
MSG msg;
HANDLE hAccelTable;

hInst = hInstance;
if (!InitApplication())
return 0;
hAccelTable = LoadAccelerators(hInst,MAKEINTRESOURCE(IDACCEL));
if ((hwndMain = CreatetestWndClassWnd()) == (HWND)0)
return 0;
CreateSBar(hwndMain,"Ready",1);
ShowWindow(hwndMain,SW_SHOW);
while (GetMessage(&msg,NULL,0,0)) {
if (!TranslateAccelerator(msg.hwnd,hAccelTable,&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
} [sig]<p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href= Page</a><br> [/sig]
 
Thanx, but I ended up finding the solution this morning on my own. Still - nice to see there are people who read these things :)

I ended up using
wc.lpfnWndProc = &WindowProc;

I was just missing this one line, but it's amazing how it brings everything to a roaring halt ...

Thanx.
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top