Thread: Creating a Dialog Based Application without MFC

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    28

    Creating a Dialog Based Application without MFC

    Hi,

    I am just a beginner at windows programming, so I am wondering, how do I create a dialog-based application (similar to that of using VC++ and MFC) with just the pure windows API?

    Currently I am just doing the following, but I have a slight feeling in my gut it's not the correct way to do it

    Code:
    HWND g_dlg = NULL;
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    	g_dlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_CALC), NULL, CalcProc);
    	ShowWindow(g_dlg, SW_SHOW);
    
    	MSG msg;
    	while (GetMessage(&msg, NULL, 0, 0) > 0)
    	{
    		if (!IsDialogMessage(g_dlg, &msg))
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    	}
    	return 0;
    }
    Any help is greatly appreciated Thank you very much.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Since you are using the dialog as your main window then you could just use a modal dialog and avoid create a message loop with the DialogBox macro.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    28
    Quote Originally Posted by Quantum1024
    Since you are using the dialog as your main window then you could just use a modal dialog and avoid create a message loop with the DialogBox macro.
    Blah, its been a long day. Thank you Quantum, of course I could do that. Revised code would look something like this for future reference:

    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    	return DialogBox(hInstance, MAKEINTRESOURCE(IDD_CALC), NULL, CalcProc);
    }
    I think... I didn't look up the API but I think the CreateDialog and DialogBox functions have the same parameters. But what they do is quite different

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Use MFC. In this case, it will make your life a lot easier.

    1. Start an MFC project
    2. Choose dialog-based
    3. Create your dialog resource using the resource editor
    4. Link the controls/variables with classes/names using class wizard.
    5. Create a message map using class wizard.
    6. Put your code in where MFC tells you to in the new message handler functions.
    7. Create the dialog box using CDialog::DoModal()

    Done.

    I would show you how to do this in Win32, but it only complicates things and probably isn't the easiest way. The simplest way is to use MFC - you will be up and running within 20 min max.

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    28
    Quote Originally Posted by Bubba
    Use MFC. In this case, it will make your life a lot easier.

    ...

    I would show you how to do this in Win32, but it only complicates things and probably isn't the easiest way. The simplest way is to use MFC - you will be up and running within 20 min max.
    I know how to do it in MFC. I kinda did the backwards route and learned MFC before learning the pure APIs. So now that I know MFC and I know I couldve done this very easily in MFC, I'd like to learn how to do it with the pure APIs.

  6. #6
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Quote Originally Posted by MitchellH
    I know how to do it in MFC. I kinda did the backwards route and learned MFC before learning the pure APIs. So now that I know MFC and I know I couldve done this very easily in MFC, I'd like to learn how to do it with the pure APIs.
    I work purely in the API and won't touch MFC. Ever. The first site that I went to to learn how to work with the API was here, theForger's API tutorial.

    The MSDN will also help a great deal once you learn how to search it easily (Read: Use google).

  7. #7
    Registered User
    Join Date
    May 2005
    Posts
    28
    Quote Originally Posted by Lithorien
    I work purely in the API and won't touch MFC. Ever. The first site that I went to to learn how to work with the API was here, theForger's API tutorial.

    The MSDN will also help a great deal once you learn how to search it easily (Read: Use google).
    Yes, I also used that tutorial and it was great! But I was wondering how to make a dialog-based app. The DialogBox() way seems pretty good... is that the correct way?

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> is that the correct way?
    It's one of many "correct ways".

    About Dialog Boxes

    gg

  9. #9
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Quote Originally Posted by MitchellH
    Yes, I also used that tutorial and it was great! But I was wondering how to make a dialog-based app. The DialogBox() way seems pretty good... is that the correct way?
    One of many correct ways, yes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC run application by clicking on file...
    By dug in forum Windows Programming
    Replies: 4
    Last Post: 12-02-2004, 04:33 AM
  2. MFC Save As dialog
    By Micko in forum Windows Programming
    Replies: 0
    Last Post: 08-23-2004, 02:02 PM
  3. problem with MFC application
    By Micko in forum Windows Programming
    Replies: 1
    Last Post: 07-12-2004, 05:36 PM
  4. Document Class and Dialog Windows :: MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 12-01-2002, 12:27 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM