Solved

How do i show a dialog as the program?

Posted on 2000-03-10
18
464 Views
Last Modified: 2008-02-20
Can someone show me a step by step way of making a program just be a dialog designed in the resource editor and getting it to show as the main form just using C, I don't want to use MFC.
0
Comment
Question by:Markenstein
  • 10
  • 8
18 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 2604579
From the MS VC help
********************************
SAMPLE: Sample Code Using a Dialog Box as the Main Window
Last reviewed: February 15, 1996
Article ID: Q68556  
The information in this article applies to:
Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1


SUMMARY
A modeless dialog box can act as the main window of a Windows-based application. Two advantages of this approach are:

The main window of the application can be created in the Dialog Editor.
Focus control is managed by Windows as it is for a dialog box.

The Microsoft Software Library contains a file that demonstrates the necessary principles.
Download DLGMAIN.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

Microsoft Download Service (MSDL)

      Dial (206) 936-6735 to connect to MSDL
      Download DLGMAIN.EXE (size: 21808 bytes)

Internet (anonymous FTP)

      ftp ftp.microsoft.com
      Change to the \SOFTLIB\MSLFILES directory
      Get DLGMAIN.EXE (size: 21808 bytes)


MORE INFORMATION
The information below outlines the necessary modifications to the code in GENERIC, a sample application provided with the Windows Software Development Kit (SDK) version 3.0, that will result in a Windows-based application that uses a modeless dialog box as its main window.

To GENERIC.C, make the following changes:


//  1. Create a global variable to hold the window handle of the
//     dialog box.

   HWND hDlgMain;

//  2. In the WinMain() procedure, declare a FARPROC variable. This
//     variable holds the procedure-instance address for the dialog
//     procedure.

   FARPROC lpfn;

//  3. Modify the CreateWindow() call in InitInstance() to specify 0
//     (zero) for nWidth and nHeight when the main window is created.
//     Do this so that the main window is not shown until the size of
//     the dialog box is known.

   hWnd = CreateWindow("GenericWClass", "Dialog as Main Window",
             WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
             CW_USEDEFAULT, 0, 0, 0, NULL, NULL, hInstance, NULL);

//  4. In WinMain(), create a procedure-instance for the dialog
//     procedure.

   lpfn = MakeProcInstance(Dialog1, hInst);

//  5. In WinMain, create the dialog box using CreateDialog().

   hDlgMain = CreateDialog(hInst, "DIA1", hWnd, lpfn);

//  6. Add code to WinMain() to show the dialog box.

   ShowWindow(hDlgMain, SW_SHOW);

//  7. Windows sends messages to the modeless dialog box through the
//     program's main message queue. To process messages intended for
//     the dialog box, modify message queue processing in WinMain() as
//     follows:

   while (GetMessage(&msg,   // Message structure
                     NULL,   // Handle of window receiving message
                     NULL,   // Lowest message to handle
                     NULL))  // Highest message to handle
   {
      if (hDlgMain == NULL || !IsDialogMessage(hDlgMain, &msg))
      {
      TranslateMessage(&msg); // Translate virtual key codes
      DispatchMessage(&msg);  // Dispatches message to window
      }
   }
   return msg.wParam;     /* Returns the value from PostQuitMessage */

//  8. When the application receives a WM_SETFOCUS message, it must
//     set the input focus to the control that acts as the
//     application's main window. Adding the following code to
//     MainWndProc() processes the WM_SETFOCUS message as required:

   case WM_SETFOCUS:
      SetFocus(hDlgMain);
      break;


In the dialog function, make the remaining changes:

//  9. In the dialog function, declare a variable of type RECT to
//     store the bounding rectangle of the modeless dialog box.

   RECT rect;

// 10. Retrieve the dimensions of the dialog box. This information
//     will be used to calculate the size of the parent window.

   case WM_INITDIALOG:
      GetWindowRect(hDlg, &rect);

// 11. Size the parent window to be the same size as the dialog box.

   SetWindowPos(GetParent(hDlg), // Get the window handle of the
                                 // parent of the dialog box.

     NULL,                       // Identifies a window that in the
                                 // window-manager's list will
                                 // precede the positioned window.
                                 // This is not used for this example.

     0,                          // Specify the x-coordinate of the
                                 // window's upper-left corner.

     0,                          // Specify the x-coordinate of the
                                 // window's upper-left corner.

     rect.right - rect.left,     // Based on the values returned by
                                 // GetWindowRect, calculate the new
                                 // width of the main window.

     rect.bottom - rect.top + GetSystemMetrics(SM_CYCAPTION)
                            + GetSystemMetrics(SM_CYMENU),
                                 // Based on the values returned by
                                 // GetWindowRect, the height of the
                                 // caption bar, and the height of
                                 // the menu bar, calculate the new
                                 // height of the main window.

     SWP_NOMOVE | SWP_NOZORDER);
                                 // Retain current position and
                                 // ordering.

// 12. When the application receives a WM_CLOSE message, close the
//     modeless dialog box and post a WM_CLOSE message to the main
//     window.

   case WM_CLOSE:
      DestroyWindow(hDlg);  // Close the modeless dialog box using
                            // DestroyWindow.
      hDlgMain = NULL;      // Set the handle of the modeless dialog
                            // box to null.
      PostMessage(GetParent(hDlg), WM_CLOSE, NULL, NULL);
      break;


Make one change to GENERIC.RC: Modify the dialog box template to specify the additional style WS_CHILD. Doing so will ensure that the dialog box moves with the parent window as the parent is moved.
 


--------------------------------------------------------------------------------

Additional reference words: 3.00 3.10 softlib DLGMAIN.EXE
KBCategory: kbprg kbfile
KBSubcategory: UsrDlgs


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
c 1998 Microsoft Corporation. All rights reserved. Terms of Use.
 

0
 
LVL 22

Expert Comment

by:nietod
ID: 2604584
Let me know if you have any questions.
0
 

Author Comment

by:Markenstein
ID: 2606719
Sorry, you'll have to excuse me i'm not that smart.  I need a step by step way to make it, something where i don't have to do anything myself but follow directions.  Like File>New, type this in, goto the build menu... etc etc.   PS: I'm using Visual C++ 6.0
0
 
LVL 22

Expert Comment

by:nietod
ID: 2607609
Create a new workspace:

Go to "File" menu
Select "New" item
in the dialog that appears, press the "Projects" tab
Select "Win32 Application" from list on the left
Type project name and location on disk in the edit boxes on the right.
select "Create New Workspace"
Press "Ok"
Choose "and empty project"

press okay and the workspace will be created.

Create a new source code file and paste generic.c into it (it is in the help).  

Add the source code to the project by:

Go to "Project" menu
select "Add to project" item.
select "files" item
choose your source code file.

Make the changes to the source code described above.

Windows programming requires a great deal of basic knowledge.  You need to know a lot about how windows programs work and you need to know how you programmihng tools work.  It is not possible to get that sort of information here, there's just too much.  We fill in the gaps.  If you don't know how to use VC, get a book on it.  There are many available at an ordinary bookstore or at www.fatbrain.com.  Same with learning how to program in windows.  Get some basic books and read them first.  Then ask if you have questions.
0
 

Author Comment

by:Markenstein
ID: 2607624
I do have a book and i've been reading it.  It doesn't explain how to use the resource editor or make the main program a modeless dialog.  I tried to get your code to work but i couldn't i kept getting like 30 errors.  I don't see how i can put the code in the "dialog function", whats that?  I usually just have a big winmain and a big winproc, do i need seperate ones for each form?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2607648
Each type of window has its own window procedure each type of dialog has  its own dialog procedure.  Just add a basic dialog procedure to the program like

BOOL CALLBACK DlgPrc(HWND WndHnd,UNIT Msg,WPARAM WrdPrm,LPARAM LngPrm)
{
    switch (Msg)
    {
    case WM_INITDIALOG;
         return ??? // ID  item to be initially highligted
    };
    return 0;
}

Then modify it as directed.
0
 

Author Comment

by:Markenstein
ID: 2607682
I still don't get what to do for everything else, it doesn't want to compile. Can i get the whole source?
0
 
LVL 22

Expert Comment

by:nietod
ID: 2607692
What errors are you getting?
0
 

Author Comment

by:Markenstein
ID: 2607713
D:\Book2\Ch11\FFF\FFF\FFF.C(16) : error C2065: 'WndProc' : undeclared identifier
D:\Book2\Ch11\FFF\FFF\FFF.C(16) : warning C4047: '=' : 'long (__stdcall *)(struct HWND__ *,unsigned int ,unsigned int ,long )' differs in levels of indirection from 'int '
D:\Book2\Ch11\FFF\FFF\FFF.C(42) : warning C4047: '=' : 'int (__stdcall *)()' differs in levels of indirection from 'const int '
D:\Book2\Ch11\FFF\FFF\FFF.C(46) : warning C4113: 'int (__stdcall *)()' differs in parameter lists from 'int (__stdcall *)(struct HWND__ *,unsigned int ,unsigned int ,long )'
D:\Book2\Ch11\FFF\FFF\FFF.C(57) : error C2373: 'WndProc' : redefinition; different type modifiers
D:\Book2\Ch11\FFF\FFF\FFF.C(111) : warning C4047: 'function' : 'unsigned int ' differs in levels of indirection from 'void *'
D:\Book2\Ch11\FFF\FFF\FFF.C(111) : warning C4024: 'PostMessageA' : different types for formal and actual parameter 3
D:\Book2\Ch11\FFF\FFF\FFF.C(111) : warning C4047: 'function' : 'long ' differs in levels of indirection from 'void *'
D:\Book2\Ch11\FFF\FFF\FFF.C(111) : warning C4024: 'PostMessageA' : different types for formal and actual parameter 4
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 22

Expert Comment

by:nietod
ID: 2607786
I really need to see the code that goes with theerros.  each error has a line number in parenthesis, like (16) for the first one.  the lines right around the error are probably the best.

>> WndProc' : undeclared identifier
Do you have a window procedure called "WndProc" defined in your program?  Is it declared before the point where this error occurs?

>> 'WndProc' : redefinition; different type modifiers
Do you have a forward definition for WndProc that does not match its declaration?
0
 

Author Comment

by:Markenstein
ID: 2607947
i got it down to this error and warnings
Compiling...
FFF.C
D:\Book2\Ch11\FFF\FFF\FFF.C(41) : error C2065: 'Dialog1' : undeclared identifier
D:\Book2\Ch11\FFF\FFF\FFF.C(41) : warning C4047: '=' : 'int (__stdcall *)()' differs in levels of indirection from 'int '
D:\Book2\Ch11\FFF\FFF\FFF.C(45) : warning C4113: 'int (__stdcall *)()' differs in parameter lists from 'int (__stdcall *)(struct HWND__ *,unsigned int ,unsigned int ,long )'
D:\Book2\Ch11\FFF\FFF\FFF.C(110) : warning C4047: 'function' : 'unsigned int ' differs in levels of indirection from 'void *'
D:\Book2\Ch11\FFF\FFF\FFF.C(110) : warning C4024: 'PostMessageA' : different types for formal and actual parameter 3
D:\Book2\Ch11\FFF\FFF\FFF.C(110) : warning C4047: 'function' : 'long ' differs in levels of indirection from 'void *'
D:\Book2\Ch11\FFF\FFF\FFF.C(110) : warning C4024: 'PostMessageA' : different types for formal and actual parameter 4
Error executing cl.exe.




#include <windows.h>                  

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                           PSTR szCmdLine, int iCmdShow)
{
      static TCHAR szAppName[] = TEXT ("SysMets2");
      HWND hDlgMain, hwnd;
      MSG                  msg;
      WNDCLASS      wndclass;
      FARPROC lpfn;

      wndclass.style                  = CS_HREDRAW | CS_VREDRAW;
      wndclass.lpfnWndProc      = WndProc;
      wndclass.cbClsExtra            = 0;
      wndclass.cbWndExtra            = 0;
      wndclass.hInstance            = hInstance;
      wndclass.hIcon                  = LoadIcon(NULL, IDI_APPLICATION);
      wndclass.hCursor            = LoadCursor(NULL, IDC_ARROW);
      wndclass.hbrBackground      = (HBRUSH) GetStockObject(WHITE_BRUSH);
      wndclass.lpszMenuName      = NULL;
      wndclass.lpszClassName      = szAppName;

      if(!RegisterClass (&wndclass))
      {
            MessageBox(NULL, TEXT("This program requires Windows NT"),
                           szAppName, MB_ICONERROR);
            return 0;
      }


   hwnd = CreateWindow("GenericWClass", "Dialog as Main Window",
             WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
             CW_USEDEFAULT, 0, 0, 0, NULL, NULL, hInstance, NULL);

      ShowWindow(hwnd, iCmdShow);
      UpdateWindow(hwnd);


   lpfn = MakeProcInstance(Dialog1, hInstance);

//  5. In WinMain, create the dialog box using CreateDialog().

   hDlgMain = CreateDialog(hInstance, "DIA1", hwnd, lpfn);

      while(GetMessage(&msg, NULL, 0, 0))
      {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
      }
      return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
      

      switch(message)
      {
   RECT rect;

// 10. Retrieve the dimensions of the dialog box. This information
//     will be used to calculate the size of the parent window.

   case WM_INITDIALOG:
      GetWindowRect(hDlg, &rect);

// 11. Size the parent window to be the same size as the dialog box.

   SetWindowPos(GetParent(hDlg), // Get the window handle of the
                                 // parent of the dialog box.

     NULL,                       // Identifies a window that in the
                                 // window-manager's list will
                                 // precede the positioned window.
                                 // This is not used for this example.

     0,                          // Specify the x-coordinate of the
                                 // window's upper-left corner.

     0,                          // Specify the x-coordinate of the
                                 // window's upper-left corner.

     rect.right - rect.left,     // Based on the values returned by
                                 // GetWindowRect, calculate the new
                                 // width of the main window.

     rect.bottom - rect.top + GetSystemMetrics(SM_CYCAPTION)
                            + GetSystemMetrics(SM_CYMENU),
                                 // Based on the values returned by
                                 // GetWindowRect, the height of the
                                 // caption bar, and the height of
                                 // the menu bar, calculate the new
                                 // height of the main window.

     SWP_NOMOVE | SWP_NOZORDER);
                                 // Retain current position and
                                 // ordering.

// 12. When the application receives a WM_CLOSE message, close the
//     modeless dialog box and post a WM_CLOSE message to the main
//     window.

   case WM_CLOSE:
      DestroyWindow(hDlg);  // Close the modeless dialog box using
                            // DestroyWindow.
      //hDlgMain = NULL;      // Set the handle of the modeless dialog
                            // box to null.
      PostMessage(GetParent(hDlg), WM_CLOSE, NULL, NULL);
      break;



      }
   
      return DefWindowProc(hDlg, message, wParam, lParam);
}



0
 
LVL 22

Expert Comment

by:nietod
ID: 2608193
These error messages shouldn't be a total mystery.  Some error messages are unclear or unacurate.  These are not.

>> D:\Book2\Ch11\FFF\FFF\FFF.C(41) :
>> error C2065: 'Dialog1' : undeclared identifier
You don't have anything declared called "dialog1".
That is supposed to be the name of the dialog window procedure.  
You don't seem to have this procedure.

>> D:\Book2\Ch11\FFF\FFF\FFF.C(45) :
>> warning C4113: 'int (__stdcall *)()'
>> differs in parameter lists from 'int
>> (__stdcall *)(struct HWND__ *,unsigned
>> int ,unsigned int ,long )'
One of the parameters has the wrong type.  In this case it is the last parameter.  "lpfn" is declared to be type FARPROC, but CreateDialog() takes a pointer of type DLGPROC.  You will need to cast this pointer to type DLGPROC.

On what line is the other errors occuring on?

The window procedure is not the dialog procedure.  The windows procedure will not get a WM_INITDIALOG message.  That goes to the dialog procedure.
0
 

Author Comment

by:Markenstein
ID: 2608292
Alright, i got it compile now with no errors or warnings.  Only when it runs nothing shows up.  What do i have to do to get my dialog (IDD_DIALOG1) from script5.rc to show up?  Heres my code:


#include <windows.h>                        

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc2(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                           PSTR szCmdLine, int iCmdShow)
{
      static TCHAR szAppName[] = TEXT ("Dialog");
      HWND hDlgMain, hwnd;
      MSG                  msg;
      WNDCLASS      wndclass;
      FARPROC lpfn;

      wndclass.style                  = CS_HREDRAW | CS_VREDRAW;
      wndclass.lpfnWndProc      = WndProc;
      wndclass.cbClsExtra            = 0;
      wndclass.cbWndExtra            = 0;
      wndclass.hInstance            = hInstance;
      wndclass.hIcon                  = LoadIcon(NULL, IDI_APPLICATION);
      wndclass.hCursor            = LoadCursor(NULL, IDC_ARROW);
      wndclass.hbrBackground      = (HBRUSH) GetStockObject(WHITE_BRUSH);
      wndclass.lpszMenuName      = NULL;
      wndclass.lpszClassName      = szAppName;

      if(!RegisterClass (&wndclass))
      {
            MessageBox(NULL, TEXT("This program requires Windows NT"),
                           szAppName, MB_ICONERROR);
            return 0;
      }


   hwnd = CreateWindow("GenericWClass", "Dialog as Main Window",
             WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
             CW_USEDEFAULT, 0, 0, 0, NULL, NULL, hInstance, NULL);

      ShowWindow(hwnd, iCmdShow);
      UpdateWindow(hwnd);


   lpfn = MakeProcInstance(WndProc2, hInstance);

//  5. In WinMain, create the dialog box using CreateDialog().

   hDlgMain = CreateDialog(hInstance, "DIA1", hwnd, (DLGPROC)lpfn);

      while(GetMessage(&msg, NULL, 0, 0))
      {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
      }
      return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
      switch(message)
      {
      
      case WM_CLOSE:
      DestroyWindow(hwnd);  // Close the modeless dialog box using
                            // DestroyWindow.
      //hDlgMain = NULL;      // Set the handle of the modeless dialog
                            // box to null.
      PostMessage(hwnd, WM_CLOSE, NULL, NULL);
      break;



      }
   
      return DefWindowProc(hwnd, message, wParam, lParam);
}
LRESULT CALLBACK WndProc2(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
      

      switch(message)
      {
   RECT rect;

// 10. Retrieve the dimensions of the dialog box. This information
//     will be used to calculate the size of the parent window.

   case WM_INITDIALOG:
      GetWindowRect(hDlg, &rect);

// 11. Size the parent window to be the same size as the dialog box.

   SetWindowPos(GetParent(hDlg), // Get the window handle of the
                                 // parent of the dialog box.

     NULL,                       // Identifies a window that in the
                                 // window-manager's list will
                                 // precede the positioned window.
                                 // This is not used for this example.

     0,                          // Specify the x-coordinate of the
                                 // window's upper-left corner.

     0,                          // Specify the x-coordinate of the
                                 // window's upper-left corner.

     rect.right - rect.left,     // Based on the values returned by
                                 // GetWindowRect, calculate the new
                                 // width of the main window.

     rect.bottom - rect.top + GetSystemMetrics(SM_CYCAPTION)
                            + GetSystemMetrics(SM_CYMENU),
                                 // Based on the values returned by
                                 // GetWindowRect, the height of the
                                 // caption bar, and the height of
                                 // the menu bar, calculate the new
                                 // height of the main window.

     SWP_NOMOVE | SWP_NOZORDER);
                                 // Retain current position and
                                 // ordering.

// 12. When the application receives a WM_CLOSE message, close the
//     modeless dialog box and post a WM_CLOSE message to the main
//     window.

   case WM_CLOSE:
      DestroyWindow(hDlg);  // Close the modeless dialog box using
                            // DestroyWindow.
      //hDlgMain = NULL;      // Set the handle of the modeless dialog
                            // box to null.
      PostMessage(GetParent(hDlg), WM_CLOSE, NULL, NULL);
      break;



      }
   
      return DefWindowProc(hDlg, message, wParam, lParam);
}



0
 
LVL 22

Expert Comment

by:nietod
ID: 2608413
At least one problem is that WndProc2 is not a dialog window procedure.  Look up "DialogProc"
0
 

Author Comment

by:Markenstein
ID: 2608454
Alright i got this, still doesn't show.  What's next?



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

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK DialogProc(
  HWND hDlg,  // handle to dialog box
  UINT uMsg,     // message
  WPARAM wParam, // first message parameter
  LPARAM lParam  // second message parameter
);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                           PSTR szCmdLine, int iCmdShow)
{
      static TCHAR szAppName[] = TEXT ("Dialog");
      HWND hDlgMain, hwnd;
      MSG                  msg;
      WNDCLASS      wndclass;
      FARPROC lpfn;

      wndclass.style                  = CS_HREDRAW | CS_VREDRAW;
      wndclass.lpfnWndProc      = WndProc;
      wndclass.cbClsExtra            = 0;
      wndclass.cbWndExtra            = 0;
      wndclass.hInstance            = hInstance;
      wndclass.hIcon                  = LoadIcon(NULL, IDI_APPLICATION);
      wndclass.hCursor            = LoadCursor(NULL, IDC_ARROW);
      wndclass.hbrBackground      = (HBRUSH) GetStockObject(WHITE_BRUSH);
      wndclass.lpszMenuName      = NULL;
      wndclass.lpszClassName      = szAppName;

      if(!RegisterClass (&wndclass))
      {
            MessageBox(NULL, TEXT("This program requires Windows NT"),
                           szAppName, MB_ICONERROR);
            return 0;
      }


   hwnd = CreateWindow("GenericWClass", "Dialog as Main Window",
             WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
             CW_USEDEFAULT, 0, 0, 0, NULL, NULL, hInstance, NULL);

      ShowWindow(hwnd, iCmdShow);
      UpdateWindow(hwnd);


   lpfn = MakeProcInstance(DialogProc, hInstance);

//  5. In WinMain, create the dialog box using CreateDialog().
      
   hDlgMain = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, (DLGPROC)lpfn);

      while(GetMessage(&msg, NULL, 0, 0))
      {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
      }
      return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
      switch(message)
      {
      
      case WM_CLOSE:
      DestroyWindow(hwnd);  // Close the modeless dialog box using
                            // DestroyWindow.
      //hDlgMain = NULL;      // Set the handle of the modeless dialog
                            // box to null.
      PostMessage(hwnd, WM_CLOSE, NULL, NULL);
      break;



      }
   
      return DefWindowProc(hwnd, message, wParam, lParam);
}
INT_PTR CALLBACK DialogProc(
  HWND hDlg,  // handle to dialog box
  UINT uMsg,     // message
  WPARAM wParam, // first message parameter
  LPARAM lParam  // second message parameter
)
{

      switch(uMsg)
      {
   RECT rect;

// 10. Retrieve the dimensions of the dialog box. This information
//     will be used to calculate the size of the parent window.

   case WM_INITDIALOG:
      GetWindowRect(hDlg, &rect);

// 11. Size the parent window to be the same size as the dialog box.

   SetWindowPos(GetParent(hDlg), // Get the window handle of the
                                 // parent of the dialog box.

     NULL,                       // Identifies a window that in the
                                 // window-manager's list will
                                 // precede the positioned window.
                                 // This is not used for this example.

     0,                          // Specify the x-coordinate of the
                                 // window's upper-left corner.

     0,                          // Specify the x-coordinate of the
                                 // window's upper-left corner.

     rect.right - rect.left,     // Based on the values returned by
                                 // GetWindowRect, calculate the new
                                 // width of the main window.

     rect.bottom - rect.top + GetSystemMetrics(SM_CYCAPTION)
                            + GetSystemMetrics(SM_CYMENU),
                                 // Based on the values returned by
                                 // GetWindowRect, the height of the
                                 // caption bar, and the height of
                                 // the menu bar, calculate the new
                                 // height of the main window.

     SWP_NOMOVE | SWP_NOZORDER);
                                 // Retain current position and
                                 // ordering.

// 12. When the application receives a WM_CLOSE message, close the
//     modeless dialog box and post a WM_CLOSE message to the main
//     window.

   case WM_CLOSE:
      DestroyWindow(hDlg);  // Close the modeless dialog box using
                            // DestroyWindow.
      //hDlgMain = NULL;      // Set the handle of the modeless dialog
                            // box to null.
      PostMessage(GetParent(hDlg), WM_CLOSE, NULL, NULL);
      break;



      }
   
      return DefWindowProc(hDlg, uMsg, wParam, lParam);
}
0
 
LVL 22

Expert Comment

by:nietod
ID: 2631138
I thought you might be interested in the following link.

http://www.relisoft.com/win32/windlg.htm

I didn't see your last post.  I'm not sure why it isn't appearing.  The code at the above lionk is probably better though.  Much more up-to-date.
0
 

Author Comment

by:Markenstein
ID: 2632325
Link doesn't work.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2632506
I don't know why that link doesn't work.  It doesn't work for me either.  but if you go to

http://www.relisoft.com

and then choose "dialog program" (or somthign like that from the list on the left it does take you to that link).  And there is a good example there.  The example from MS is sort of kludgy, this one is much better.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now