Archived

This topic is now archived and is closed to further replies.

Squeejee

Dialog Box Procedure

Recommended Posts

I am creating a game and I set the window so it is not visible, and when it is created, a dialog box pops up to act as the main window. I am having problems with the procedure for the dialog box. I keep getting this error when I compile: (85)error C2664: ''DialogBoxParamA'' : cannot convert parameter 4 from ''long (struct HWND__ *,unsigned int,unsigned int,long)'' to ''int (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'' This is the code for my dialog box and main window prpcedures:
  
//MAIN DIALOG PROC/////////////////////////////////////////////////////////////

LRESULT CALLBACK MainDlgProc(HWND hwnd,
							UINT msg,
							WPARAM wparam,
							LPARAM lparam)
{
  switch(msg)
  {
  case WM_INITDIALOG:
	{
	  // initilize stuff

	  	return 0;
	} break;

  case WM_COMMAND:
	{
	  switch(LOWORD(wparam))
	  {
	  
	  default:break;
	  }
	}

  case WM_DESTROY:
	{
	  // kill application

	  PostQuitMessage(0);
	  return 0;
	} break;

  default:break;
  }

  // process any messages that were not taken care of


  return FALSE;

}



//WINPROC////////////////////////////////////////////////////////

LRESULT CALLBACK WindowProc(HWND hwnd,
							UINT msg,
							WPARAM wparam,
							LPARAM lparam)
{
  switch(msg)
  {
  case WM_CREATE:
	{

	  // create main dialog box

	  DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_MAIN), hwnd, MainDlgProc); <------------error line

	  
	return 0;
	} break;

  case WM_COMMAND:
	{
	  switch(LOWORD(wparam))
	  {
	  case MENU_OPTIONS_ID_EXIT:
		{
		  PostQuitMessage(0);
		} break;
	  
	  default:break;
	  }
	}

  case WM_PAINT:
	{
	  hdc = BeginPaint(hwnd, &ps);
	  // do all painting

	  EndPaint(hwnd, &ps);
	  return 0;
	} break;

  case WM_DESTROY:
	{
	  // kill application

	  PostQuitMessage(0);
	  return 0;
	} break;

  default:break;
  }

  // process any messages that were not taken care of


  return (DefWindowProc(hwnd, msg, wparam, lparam));

}

  
-----

Share this post


Link to post
Share on other sites

i have a feeling that dialog procedures need to be declared


BOOL CALLBACK DialogProc(
HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);


instead of


LRESULT CALLBACK MainDlgProc(
HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam
);


...hope it helps.

Share this post


Link to post
Share on other sites
Just cast the callback function pointer.


DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_MAIN), hwnd, (DLGPROC)MainDlgProc);


The MSDN prototype for the DLGPROC is
  
INT_PTR CALLBACK DialogProc(
HWND hwndDlg, // handle to dialog box

UINT uMsg, // message

WPARAM wParam, // first message parameter

LPARAM lParam // second message parameter

);
with INT_PTR typedefed as a long.

Edited by - Colin Barry on October 16, 2001 4:37:49 AM

Share this post


Link to post
Share on other sites