Thread: A Problem with DialogBox()

  1. #1
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790

    A Problem with DialogBox()

    I am having a problem with dialog box. When I call the dialog procedure in the 4th argument, it reports the followig error:

    Code:
    C:\Program Files\DevStudio\MyProjects1\WhatClr\main.cpp(139) : error C2664: 'DialogBoxParamA' : cannot convert parameter 4 from 'int (void *,unsigned int,unsigned int,long)' to 'int (__stdcall *)(void)'
    Error executing cl.exe.
    the rest of the code:
    Code:
    #include <windows.h>
    #include "resource.h"
    #define ID_TIMER 1
    #define ID_EDIT 1
    
    LRESULT CALLBACK WndProc (HWND , UINT, WPARAM, LPARAM);
    BOOL CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
    
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
    					PSTR szCmdLine, int iCmdShow)
    {
    	static TCHAR szAppName[] = TEXT ("WhatClr");
    	HWND hwnd;
    	MSG msg;
    	WNDCLASS wndc;
    
    	wndc.style          = CS_HREDRAW | CS_VREDRAW;
    	wndc.lpfnWndProc    = WndProc;
    	wndc.cbClsExtra     = 0;
    	wndc.cbWndExtra     = 0;
    	wndc.hInstance      = hInstance;
    	wndc.hIcon          = LoadIcon (hInstance, szAppName);
    	wndc.hCursor        = LoadCursor (hInstance, szAppName);
    	wndc.hbrBackground  = (HBRUSH) GetStockObject (WHITE_BRUSH);
    	wndc.lpszMenuName   = szAppName;
    	wndc.lpszClassName  = szAppName;
    
    	if (!RegisterClass (&wndc))
    	{
    
    		MessageBox (NULL, TEXT ("Program Requiers Windows NT"),
    			szAppName, MB_ICONERROR);
    		return 0;
    	}
    
    	
    
    
                    
    	hwnd = CreateWindow (szAppName, TEXT ("Cheappad v0.5"),
    		   WS_OVERLAPPEDWINDOW,
    		   CW_USEDEFAULT, CW_USEDEFAULT,
    		   CW_USEDEFAULT, CW_USEDEFAULT,
    		   NULL, NULL, hInstance, NULL) ;
    
    	ShowWindow (hwnd, iCmdShow);
    	UpdateWindow (hwnd);
    
    	while (GetMessage (&msg, NULL, 0, 0))
    	{
    		TranslateMessage (&msg);
    		DispatchMessage  (&msg);
    	}
    	return msg.wParam ;
    }
    
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
        
    	static HWND hwndEdit;
    	int iSelect, iEnable;
    	static HINSTANCE hInstance;
    	switch (message)
    	{
    
    	case WM_CREATE:
    
    		hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
    		hwndEdit = CreateWindow (TEXT ("edit"),NULL,
    			WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER|
    			ES_LEFT | ES_MULTILINE|ES_AUTOVSCROLL,
    			0,0,0,0,hwnd, (HMENU) ID_EDIT,
    			hInstance, NULL);
    		return 0;
    
    	case WM_SETFOCUS:
    		SetFocus (hwndEdit);
    		return 0;
    
    	case WM_SIZE:
    		MoveWindow (hwndEdit, 0, 0, LOWORD (lParam), HIWORD (lParam), TRUE);
    		return 0;
    
      case WM_INITMENUPOPUP:
    
    		if (lParam == 1)
    		{
    			EnableMenuItem ((HMENU) wParam, IDM_EDIT_UNDO,
    				SendMessage (hwndEdit, EM_CANUNDO, 0, 0) ?
                           MF_ENABLED : MF_GRAYED);
    
    			
    			iSelect = SendMessage (hwndEdit, EM_GETSEL,0,0);
    
    
    			if (HIWORD (iSelect) == LOWORD (iSelect))
    				iEnable = MF_GRAYED;
    			else
    				iEnable = MF_ENABLED;
    
    			EnableMenuItem ((HMENU) wParam,IDM_EDIT_CUT,iEnable);
    			EnableMenuItem ((HMENU) wParam,IDM_EDIT_COPY, iEnable);
    			EnableMenuItem ((HMENU) wParam,IDM_EDIT_PASTE, iEnable);
    
    		
    			return 0;
    		}
    		break;
    
    	case WM_COMMAND:
    
    		if (lParam)
    		{
    			if (LOWORD (lParam) == ID_EDIT &&
    				(HIWORD (wParam) == EN_ERRSPACE ||
    				HIWORD (wParam) == EN_MAXTEXT))
    				MessageBox (hwnd, TEXT ("Cheappad out of space"),
    				TEXT ("pop"), MB_OK | MB_ICONSTOP);
    			return 0;
    		}
    		else switch (LOWORD (wParam))
    		{
    		case IDM_FILE_NEW:
    		case IDM_FILE_OPEN:
    		case IDM_FILE_SAVE:
    		case IDM_FILE_SAVE_AS:
    			MessageBeep (0);
    			return 0;
    
    		case IDM_APP_EXIT:
    			SendMessage (hwnd, WM_CLOSE, 0, 0);
    			return 0;
    
    		case IDM_HELP_ABOUT:
    
    			DialogBox (hInstance, TEXT ("AboutBox"), hwnd, AboutDlgProc);
    			return 0;
    		
    			return 0;
    		}
    	
    	case WM_DESTROY:
    		
    		PostQuitMessage(0);
    		return 0;
    	}
    
    	return DefWindowProc (hwnd, message, wParam, lParam);
    }
    
    BOOL CALLBACK AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch (message)
    	{
    case WM_INITDIALOG:
    	return TRUE;
    
    	case WM_COMMAND:
    	switch (LOWORD (wParam))
    	{
    	case IDOK:
    	case IDCANCEL:
    		EndDialog (hDlg, 0);
    		return TRUE;
    	}
    	break;
    	}
    	return FALSE;
    }
    thanks in advance

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    Do you get errors on compiling it or when running it?
    Last edited by ColdFire; 02-04-2003 at 05:49 PM.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Blame it on msvc. DialogBox is a macro that calls DialogBoxParam. The 4th parameter complained about - the DlgProc - is of the correct type despite the error msg.

    Things to try:

    1. clean & rebuild all.

    if that fails:

    2. Start a completely new project with your source and resources and delete the old project files.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    MSVC sometimes gets something stuck in its craw and requires all the files in the debug and release folders to be deleted.



    I use .c files not .cpp so some differences in the way the compiler reacts.

    Have you tried a cast?

    ie , (DLGPROC)AboutProc);
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    absolutley change this one;

    if (LOWORD (lParam) == ID_EDIT ---.> to this "LOWORD(wParam)"

    instead of - if (HIWORD (iSelect) == LOWORD (iSelect))-
    use

    try this ------ -----if(iSelect != (-1)--------------------------------------

    in WM_COMMAND
    child id = LOWORD(wParam)

  6. #6
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    Thanks for the help guys, I am rather new to windows programming, so I didnt think to cast it as something.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM