win32 dialog help

Hey everyone I need some help. First a little back story. I am getting a new Pocket PC for Christmas and i thought it would be cool to have a FIRST playbook application on it so i could make autonomous “plays”. I did a little research and found out i need to learn win32 (something I have wanted to do anyway) before I could write an app for windows CE. so i found a nifty little tutorial that explained windows programming well. Then i hit a wall. I did the the tutorial on modal dialogs. Everything complied fine but no dialog box when i select the about menu under help. I’m using DevC++. Here is the code. Anyone got any Ideas? Thanks.

#include <windows.h>
#include "resource.h"

/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK AboutDialog(HWND, UINT, WPARAM , LPARAM);
/* Make the class name into a global variable */
char szClassName ] = "WindowsApp";
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)

{
    HWND hwnd;			   /* This is the handle for our window */
	MSG messages;		    /* Here messages to the application are saved */
	WNDCLASSEX wincl;		/* Data structure for the windowclass */

	/* The Window structure */
	wincl.hInstance = hThisInstance;
	wincl.lpszClassName = szClassName;
	wincl.lpfnWndProc = WindowProcedure;	  /* This function is called by windows */
    wincl.style = CS_DBLCLKS;				 /* Catch double-clicks */
	wincl.cbSize = sizeof(WNDCLASSEX);

	/* Use default icon and mouse-pointer */
	wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
	wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
	wincl.lpszMenuName  = MAKEINTRESOURCE(IDI_MAIN_MENU); /* No menu */
    wincl.cbClsExtra = 0;					  /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;					  /* structure or the window instance */
	/* Use light-gray as the background of the window */
	wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);

	/* Register the window class, if fail quit the program */
	if(!RegisterClassEx(&wincl)) return 0;

	/* The class is registered, let's create the program*/
	hwnd = CreateWindowEx(
		   0,	 /* Extended possibilites for variation */
		   szClassName,		 /* Classname */
		   "[BX] WhiteBoard",		 /* Title Text */
		   WS_OVERLAPPEDWINDOW, /* default window */
		   0,	   /* Windows decides the position */
		   0,	   /* where the window ends up on the screen */
		   544,				 /* The programs width */
		   375,				 /* and height in pixels */
		   NULL,		/* The window is a child-window to desktop */
		   NULL,			    /* No menu */
		   hThisInstance,	   /* Program Instance handler */
		   NULL				 /* No Window Creation data */
		   );

	if(hwnd == NULL)
	{
		MessageBox(NULL, "Window Creation Failed!", "Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	/* Make the window visible on the screen */
	ShowWindow(hwnd, nFunsterStil);
	/*upadate window*/
	UpdateWindow(hwnd);
	/* Run the message loop. It will run until GetMessage( ) returns 0 */
	while(GetMessage(&messages, NULL, 0, 0) > 0)
	{
		   /* Translate virtual-key messages into character messages */
		   TranslateMessage(&messages);
		   /* Send message to WindowProcedure */
		   DispatchMessage(&messages);
	}

	/* The program return-value is 0 - The value that PostQuitMessage( ) gave */
	return messages.wParam;
}

/* This function is called by the Windows function DispatchMessage( ) */
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)				  /* handle the messages */
	{
		   case WM_LBUTTONDOWN:
			break;
		   case WM_COMMAND:
				  switch(LOWORD(wParam))
				  {
				    case IDI_HELP_ABOUT:
						  DialogBox(GetModuleHandle(NULL), 
						  MAKEINTRESOURCE(IDI_DIA_ABOUT), hwnd,reinterpret_cast<DLGPROC>(AboutDialog));
					 
					break;
				    case IDI_FILE_EXIT:
					  PostMessage(hwnd, WM_CLOSE, 0, 0);
					break;
				  }
		   break;
		   case WM_DESTROY:
		   PostQuitMessage(0);		/* send a WM_QUIT to the message queue */
		   break;
		   default:				   /* for messages that we don't deal with */
		   return DefWindowProc(hwnd, message, wParam, lParam);
	}
	return 0;
}


/*Dialog procedure*/
BOOL CALLBACK AboutDialog(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  switch(message)
  {
	case WM_INITDIALOG:
	{
	  /// initialize dialog
	}
	break;

	case WM_COMMAND:
	{
	  switch(LOWORD(wParam))
	  {
		case IDOK:
		{
		  /// handle OK button click
		  EndDialog(hwnd, IDOK);
		}
		break;

		case IDCANCEL:
		{
		  /// handle Cancel button click
		  EndDialog(hwnd, IDCANCEL);
		}
		break;
	  }
	}
	break;
  }

  return TRUE;
}

If you’re familiar with the .NET languages you can write a PPC application in Visual Studio targeting the compact framework. I wrote a program to time contractions when my wife was expecting in about an hour. There is even an emulator so you can test it on your PC without downloading it to the PDA. The framework class documentation has a flag that indicates whether the class is supported by the compact framework.

I compiled and ran the code on WinXP-Pro.
When you click on the menu, instead of giving you a dialog box, the controls on the dialog become part of the MDI environment of the parent window. I’ll try out some different things and get back to you.

There’s any number of things that could be going wrong, but my guess would be that the dialog is being created, but not shown.

One thing I noticed was that you grab the WM_INITDIALOG message in AboutDialog, but don’t do anything with it. If you don’t process a given message, your handler routine should return FALSE to signify to windows that it should use the default behavior, which in this case involves painting the window to the screen, etc. Try changing the last line of your handler to “return FALSE;” and putting a “return TRUE;” after both of the EndDialog(…) calls. For example, here’s the aboutDialog callback routine that I use in RoboGUI:


 BOOL CALLBACK aboutProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){
 	switch(message){
 	case WM_COMMAND:
 		switch(LOWORD(wParam)){
 		case IDOK:
 		case IDCANCEL:
 			EndDialog(hDlg, 0);
 			return TRUE;
 		}
 		break;
 	}
 	return FALSE;
 }
 

If that doesn’t work, could you post the entire VC++ project (zipped)? Make sure to delete the Debug and Release directories first… they tend to be quite large.

Unfortanuly i don’t now much of anything about .net. I tried changing and adding the returns and nothing happened. Here is the full project.

whiteboard.zip

Thanks for your help guys

I thought you were supposed to use DefWindowProc(), ie:

 LRESULT CALLBACK aboutProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){
 	switch(message){
 	...
 	}
 	return DefWindowProc(hDlg, messagem wParam, lParam);
 }

I looked this up in MSDN just now. Microsoft Learn: Build skills that open doors in your career Though if I’m misunderstanding this, please tell me.

Hmmm… well, the included exe works just fine for me (both XP Professional and linux using wine), as does recompiling (using DevC++ 4.9.8.0), so I’m guessing something strange is happening with your computer. What version of Windows are you running?

Also, if you could add the following code and try running it again, that would be great:

-In WindowProcedure, in the IDI_HELP_ABOUT case, just above the line DialogBox(…):
MessageBox(NULL, “Got menu click”, “Test”, MB_OK);

-In AboutDialog, in the WM_INITDIALOG case:
MessageBox(NULL, “Got init dialog”, “Test”, MB_OK);

Then try choosing About from the help menu and see how many message boxes show up.

-Rob

Maybe… I can’t really remember. It’s been a long time since I’ve done any API stuff (I’ve been doing Qt almost exclusively recently, and it was MFC before that).

Yeah it is definitely my computer. I’m running XP home. The funny thing is it doesn’t run of my other computer with windows XP Pro. I finally got it to work with my laptop.

I added those message box and i don’t get any of them on my main computer.
The link about is updated with that code. Well i guess I can take it from here thanks.

I just downloaded the project, and it works fine for me (XP Pro SP1). I can’t recompile, though- I use VC++ 6.

What you may want to do is center the dialog box somewhere, just to make sure it isn’t appearing off-screen.

Interesting, on my XP Pro SP 2 it works. I haven’t tried recompiling. When you say it doesn’t work on your other XP Pro computers, what do you mean? Do the “got click” and “got init” msgbox’s come up?

When you say it doesn’t work on your other XP Pro computers, what do you mean? Do the “got click” and “got init” msgbox’s come up?

I don’t get any of the messages. Which of course means it is not receiving the command however my exit menu works find.