Solved

Dialog won't show

Posted on 2000-03-11
23
410 Views
Last Modified: 2012-06-22
The following source code compiles but with 10 warnings.  The following warnings are at the bottom.  The code is supposed to show a dialog definied in a rc as the main form.  The program should just show one form (the dialog box).


 -- SOURCE CODE --


/********************************************************************\
*  generic.c: Source code for generic                                *
*                                                                    *
*  Comments: Generic Win32-based Application                         *
*                                                                    *
*  Functions:                                                        *
*     WinMain      - Application entry point                         *
*     MainWndProc  - main window procedure                           *
*     AboutDlgProc - dialog procedure for About dialog               *
*                                                                    *
*                                                                    *
\********************************************************************/

/*********************  Header Files  *********************/

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

/*********************  Prototypes  ***********************/

LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );
BOOL CALLBACK AboutDlgProc( HWND, UINT, WPARAM, LPARAM );

/*******************  Global Variables ********************/

HANDLE ghInstance;
HWND hDlgMain;


/********************************************************************\
*  Function: int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int)    *
*                                                                    *
*   Purpose: Initializes Application                                 *
*                                                                    *
*  Comments: Register window class, create and display the main      *
*            window, and enter message loop.                         *
*                                                                    *
*                                                                    *
\********************************************************************/

int PASCAL WinMain( HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpszCmdLine,
    int nCmdShow )
{
   WNDCLASS wc;
   MSG msg;
   HWND hWnd;
   FARPROC lpfn;

   if( !hPrevInstance )
   {
      wc.lpszClassName = "GenericAppClass";
      wc.lpfnWndProc = MainWndProc;
      wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
      wc.hCursor = LoadCursor( NULL, IDC_ARROW );
      wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
      wc.lpszMenuName = "GenericAppMenu";
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;

      RegisterClass( &wc );
   }

   ghInstance = hInstance;

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

   ShowWindow( hWnd, nCmdShow );

   lpfn = MakeProcInstance(AboutDlgProc, hInstance);
   hDlgMain = CreateDialog(hInstance, MAKEINTRESOURCE(IDM_ABOUT), hWnd, lpfn);

   ShowWindow(hDlgMain, SW_SHOW);



   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 */
}

/********************************************************************\
* Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM) *
*                                                                    *
*  Purpose: Processes Application Messages                           *
*                                                                    *
* Comments: The following messages are processed                     *
*                                                                    *
*           WM_PAINT                                                 *
*           WM_COMMAND                                               *
*           WM_DESTROY                                               *
*                                                                    *
*                                                                    *
\********************************************************************/

LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,
   LPARAM lParam )
{
   PAINTSTRUCT ps;
   HDC hDC;

   switch( msg ) {


        

        case WM_SETFOCUS:
             SetFocus(hDlgMain);
             break;


/**************************************************************\
*     WM_PAINT:                                                *
\**************************************************************/

      case WM_PAINT:
         hDC = BeginPaint( hWnd, &ps );

         TextOut( hDC, 10, 10, "Hello, World!", 13 );

         EndPaint( hWnd, &ps );
         break;

/**************************************************************\
*     WM_COMMAND:                                              *
\**************************************************************/

      case WM_COMMAND:
         switch( wParam ) {
            case IDM_ABOUT:
               DialogBox( ghInstance, "AboutDlg", hWnd, (DLGPROC)
                          AboutDlgProc );
            break;
         }
      break;

/**************************************************************\
*     WM_DESTROY: PostQuitMessage() is called                  *
\**************************************************************/

      case WM_DESTROY:
         PostQuitMessage( 0 );
         break;

/**************************************************************\
*     Let the default window proc handle all other messages    *
\**************************************************************/

      default:
         return( DefWindowProc( hWnd, msg, wParam, lParam ));
   }

   return 0;
}

/********************************************************************\
* Function: LRESULT CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM)*
*                                                                    *
*  Purpose: Processes "About" Dialog Box Messages                    *
*                                                                    *
* Comments: The About dialog box is displayed when the user clicks   *
*           About from the Help menu.                                *
*                                                                    *
\********************************************************************/


BOOL CALLBACK AboutDlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{

    RECT rect;
      
      switch( uMsg ) {
      case WM_INITDIALOG:
                  GetWindowRect(hDlg, &rect);




   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.

                  return hDlg;

      case WM_COMMAND:
         switch( wParam ) {
            case IDOK:
               EndDialog( hDlg, TRUE );
               return TRUE;
         }
      break;

        

   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 FALSE;
}



 -- WARNINGS --

D:\Book2\Generic\Generic.c(76) : warning C4113: 'int (__stdcall *)()' differs in parameter lists from 'int (__stdcall *)(struct HWND__ *,unsigned int ,unsigned int ,long )'
D:\Book2\Generic\Generic.c(84) : warning C4047: 'function' : 'unsigned int ' differs in levels of indirection from 'void *'
D:\Book2\Generic\Generic.c(84) : warning C4024: 'GetMessageA' : different types for formal and actual parameter 3
D:\Book2\Generic\Generic.c(85) : warning C4047: 'function' : 'unsigned int ' differs in levels of indirection from 'void *'
D:\Book2\Generic\Generic.c(85) : warning C4024: 'GetMessageA' : different types for formal and actual parameter 4
D:\Book2\Generic\Generic.c(223) : warning C4047: 'return' : 'int ' differs in levels of indirection from 'struct HWND__ *'
D:\Book2\Generic\Generic.c(240) : warning C4047: 'function' : 'unsigned int ' differs in levels of indirection from 'void *'
D:\Book2\Generic\Generic.c(240) : warning C4024: 'PostMessageA' : different types for formal and actual parameter 3
D:\Book2\Generic\Generic.c(240) : warning C4047: 'function' : 'long ' differs in levels of indirection from 'void *'
D:\Book2\Generic\Generic.c(240) : warning C4024: 'PostMessageA' : different types for formal and actual parameter 4
Linking...

Generic.exe - 0 error(s), 10 warning(s)
0
Comment
Question by:Markenstein
  • 9
  • 6
  • 4
  • +3
23 Comments
 
LVL 5

Expert Comment

by:Wyn
Comment Utility
Which dialog is going wrong?
The modal or modeless one?

In your code there are many obsolete funcions like MakeProcInstance(),eliminate them.
And make sure you have a dialog box named "AboutDlg"

Regards
W.Yinan
0
 

Expert Comment

by:pdundon
Comment Utility
I can't be sure from the code you've given, but I think the problem lies in the line

   hDlgMain = CreateDialog(hInstance, MAKEINTRESOURCE(IDM_ABOUT), hWnd, lpfn);

You're using IDM_ABOUT here, which looks like the ID of the message used to invoke the dialog, rather than the ID of the dialog template. Did you mean IDD_ABOUT?
0
 

Author Comment

by:Markenstein
Comment Utility
Alright i changed

   lpfn = MakeProcInstance(AboutDlgProc, hInstance);
   hDlgMain = CreateDialog(hInstance, MAKEINTRESOURCE(IDM_ABOUT), hWnd, lpfn);

to:

   hDlgMain = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG),hWnd, (DLGPROC)GenericDlgProc);

But it still doesn't show up.  Any other suggestions?
0
 
LVL 5

Expert Comment

by:Wyn
Comment Utility
Do you really contain those resource ?
0
 

Author Comment

by:Markenstein
Comment Utility
In generic.rc i have a dialog and it comes up as IDD_DIALOG in the resource tab under Dialog.  In resource.h i have the line:
#define IDD_DIALOG                      1000
0
 

Author Comment

by:Markenstein
Comment Utility
Oh and also i included that file in my source using #include "resource.h"
0
 
LVL 5

Expert Comment

by:Wyn
Comment Utility
And in the directory of resource.h.Do you have the corresponding .rc?
0
 
LVL 5

Expert Comment

by:Wyn
Comment Utility
You can mail me the project to yinansuibi@163.net.
I'm curious it doesnt work.
Regards
W.Yinan
0
 
LVL 3

Expert Comment

by:Redlord
Comment Utility
This is not really an answer to your question but it should get rid of all or most of the warnings.

Line 84: change the GetMessage Call to
    "GetMessage(&msg,NULL,0,0)"
    this is only because of the way
    that NULL is defined.

Line 223: just add a (BOOL) infront of
    hDlg
    "return (BOOL)hDlg;"

Line 240: Again just replace the NULLs
    with 0
    "PostMessage(GetParent(hDlg), WM_CLOSE, 0, 0);"
0
 
LVL 3

Expert Comment

by:Redlord
Comment Utility
UPDATE:

Line 223: This should just return true
   not the hwnd to the Dlg


Line 219: Try adding SWP_SHOWWINDOW
0
 

Author Comment

by:Markenstein
Comment Utility
Alright this is what i have now
0 Errors, 0 Warnings but it still doesn't show the dialog.


/********************************************************************\
*  generic.c: Source code for generic                                *
*                                                                    *
*  Comments: Generic Win32-based Application                         *
*                                                                    *
*  Functions:                                                        *
*     WinMain      - Application entry point                         *
*     MainWndProc  - main window procedure                           *
*     AboutDlgProc - dialog procedure for About dialog               *
*                                                                    *
*                                                                    *
\********************************************************************/

/*********************  Header Files  *********************/

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

/*********************  Prototypes  ***********************/

LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );
BOOL WINAPI GenericDlgProc (HWND hwnd, UINT msg,
                               WPARAM wParam,  LPARAM lParam);

/*******************  Global Variables ********************/

HANDLE ghInstance;
HWND hDlgMain;
HICON hIcon;


/********************************************************************\
*  Function: int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int)    *
*                                                                    *
*   Purpose: Initializes Application                                 *
*                                                                    *
*  Comments: Register window class, create and display the main      *
*            window, and enter message loop.                         *
*                                                                    *
*                                                                    *
\********************************************************************/

int PASCAL WinMain( HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpszCmdLine,
    int nCmdShow )
{
   WNDCLASS wc;
   MSG msg;
   HWND hWnd;

   if( !hPrevInstance )
   {
      wc.lpszClassName = "GenericAppClass";
      wc.lpfnWndProc = MainWndProc;
      wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
      wc.hInstance = hInstance;
        wc.cbWndExtra = DLGWINDOWEXTRA;
      wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
      wc.hCursor = LoadCursor( NULL, IDC_ARROW );
      wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
      wc.lpszMenuName = "GenericAppMenu";
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;

      RegisterClass( &wc );
   }

   ghInstance = hInstance;

   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, nCmdShow );
   UpdateWindow(hWnd);

   hDlgMain = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG),
                                          hWnd, (DLGPROC)GenericDlgProc);
   
   
   ShowWindow(hDlgMain, SW_SHOW);
   UpdateWindow(hDlgMain);



   while (GetMessage(&msg,   // Message structure
                     NULL,   // Handle of window receiving message
                     0,   // Lowest message to handle
                     0))  // 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 */
}

/********************************************************************\
* Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM) *
*                                                                    *
*  Purpose: Processes Application Messages                           *
*                                                                    *
* Comments: The following messages are processed                     *
*                                                                    *
*           WM_PAINT                                                 *
*           WM_COMMAND                                               *
*           WM_DESTROY                                               *
*                                                                    *
*                                                                    *
\********************************************************************/

LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,
   LPARAM lParam )
{
   PAINTSTRUCT ps;
   HDC hDC;

   switch( msg ) {


        

        case WM_SETFOCUS:
             SetFocus(hDlgMain);
             break;


/**************************************************************\
*     WM_PAINT:                                                *
\**************************************************************/

      case WM_PAINT:
         hDC = BeginPaint( hWnd, &ps );

         //TextOut( hDC, 10, 10, "Hello, World!", 13 );

         EndPaint( hWnd, &ps );
         break;

/**************************************************************\
*     WM_COMMAND:                                              *
\**************************************************************/
/*
      case WM_COMMAND:
         switch( wParam ) {
            case IDM_ABOUT:
               DialogBox( ghInstance, "AboutDlg", hWnd, (DLGPROC)
                          AboutDlgProc );
            break;
         }
      break;
*/
/**************************************************************\
*     WM_DESTROY: PostQuitMessage() is called                  *
\**************************************************************/

      case WM_DESTROY:
         PostQuitMessage( 0 );
         break;

/**************************************************************\
*     Let the default window proc handle all other messages    *
\**************************************************************/

      default:
         return( DefWindowProc( hWnd, msg, wParam, lParam ));
   }

   return 0;
}

/********************************************************************\
* Function: LRESULT CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM)*
*                                                                    *
*  Purpose: Processes "About" Dialog Box Messages                    *
*                                                                    *
* Comments: The About dialog box is displayed when the user clicks   *
*           About from the Help menu.                                *
*                                                                    *
\********************************************************************/


BOOL WINAPI GenericDlgProc (HWND hwnd, UINT msg,
                               WPARAM wParam,  LPARAM lParam)
    {

      RECT rect ;
      switch (msg) {

          case WM_INITDIALOG:
           //hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE(IDI_ICON1)); // Load the icon that is to be displayed
                               // when minimized.
           
                    GetWindowRect(hwnd, &rect);

                    SetWindowPos(GetParent(hwnd), // 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 | SWP_SHOWWINDOW);
                                 // Retain current position and
                                 // ordering.
                    return TRUE;

           case WM_PAINT: {
               PAINTSTRUCT ps;

               BeginPaint( hwnd, &ps );
               EndPaint( hwnd, &ps );
           }
           break;
       }
       return FALSE;

   }

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Expert Comment

by:Redlord
Comment Utility
Try: http://bcgrizzly.com/~forger/winprog/tutorial/

really good tutorial by theForger, has tons of good info on Windows API programing

0
 

Author Comment

by:Markenstein
Comment Utility
I have a book, (Programming Windows 5th Edition), and i sort of understand some of the stuff that is going on.  All i want to do is have a application that is a dialog, like windows calculater that comes from a resource which i can edit easily using VC++'s resource editor.  My book doesn't show me how to do that.
0
 
LVL 3

Expert Comment

by:Redlord
Comment Utility
If you just want it to be a dialog box then you can use the DialogBox function instead of the CreateDialog function

using the DialogBox function you dont have to have a parent window or a message loop or any of that stuff, just place "DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG),
hWnd, (DLGPROC)GenericDlgProc);"
in winmain and have your DialogProc handle all of the messages
0
 

Author Comment

by:Markenstein
Comment Utility
I replaced

   hDlgMain = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG),
hWnd, (DLGPROC)GenericDlgProc);

with    

DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), hWnd, (DLGPROC)GenericDlgProc);

and it compiles, but nothing shows up.
0
 
LVL 5

Expert Comment

by:Wyn
Comment Utility
->If you just want it to be a dialog box then you can use the DialogBox function instead of the CreateDialog function
============================
Redlord,this is not a good suggestion.You change the program logic.

Markenstein,you'd mail to me the project.I cannot find anything more in your code.
Regards
W.Yinan
0
 
LVL 3

Expert Comment

by:Norbert
Comment Utility
Just a stupid question inside the dialog editor did you enable the visible flag ?
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
Comment Utility
Main problem: name of class
working text:(ddisplaying windows!):
 
/********************************************************************\
*  generic.c: Source code for generic                                *
*                                                                    *
*  Comments: Generic Win32-based Application                         *
*                                                                    *
*  Functions:                                                        *
*     WinMain      - Application entry point                         *
*     MainWndProc  - main window procedure                           *
*     AboutDlgProc - dialog procedure for About dialog               *
*                                                                    *
*                                                                    *
\********************************************************************/

/*********************  Header Files  *********************/

#include <windows.h>
#define IDM_ABOUT 100
//#include "generic.h"

/*********************  Prototypes  ***********************/

LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );
BOOL    CALLBACK AboutDlgProc( HWND, UINT, WPARAM, LPARAM );

/*******************  Global Variables ********************/

HANDLE ghInstance;
HWND hDlgMain;


/********************************************************************\
*  Function: int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int)    *
*                                                                    *
*   Purpose: Initializes Application                                 *
*                                                                    *
*  Comments: Register window class, create and display the main      *
*            window, and enter message loop.                         *
*                                                                    *
*                                                                    *
\********************************************************************/

int PASCAL WinMain( HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR /*lpszCmdLine*/,
    int nCmdShow )
{
   WNDCLASS wc;
   MSG msg;
   HWND hWnd;
//   FARPROC lpfn;
            //main problem : name in lpszClassName and
            //in CreateWindow must be same!
     static char  szAppName[] = "GenericAppClass" ;

   if( !hPrevInstance )
   {
      wc.lpszClassName = szAppName;
      wc.lpfnWndProc = MainWndProc;
      wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
      wc.hCursor = LoadCursor( NULL, IDC_ARROW );
      wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 );
      wc.lpszMenuName = "GenericAppMenu";
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;

      RegisterClass( &wc );
   }

   ghInstance = hInstance;

   hWnd = CreateWindow (szAppName, "Dialog as Main Window",
                          WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          NULL, NULL, hInstance, NULL) ;
//   hWnd = CreateWindow("GenericWClass", "Dialog as Main Window",
//             WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
//             CW_USEDEFAULT, 100, 400, 400, NULL, NULL, hInstance, NULL);

   ShowWindow( hWnd, nCmdShow);

//   lpfn = MakeProcInstance(AboutDlgProc, hInstance);
   hDlgMain = CreateDialog(hInstance, MAKEINTRESOURCE(IDM_ABOUT), hWnd,
               (DLGPROC)AboutDlgProc);

   ShowWindow(hDlgMain, SW_SHOW);



   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 */
}

/********************************************************************\
* Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM) *
*                                                                    *
*  Purpose: Processes Application Messages                           *
*                                                                    *
* Comments: The following messages are processed                     *
*                                                                    *
*           WM_PAINT                                                 *
*           WM_COMMAND                                               *
*           WM_DESTROY                                               *
*                                                                    *
*                                                                    *
\********************************************************************/

LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,
   LPARAM lParam )
{
   PAINTSTRUCT ps;
   HDC hDC;

   switch( msg ) {
      case WM_SETFOCUS:
      SetFocus(hDlgMain);
      break;


/**************************************************************\
*     WM_PAINT:                                                *
\**************************************************************/

      case WM_PAINT:
         hDC = BeginPaint( hWnd, &ps );

         TextOut( hDC, 10, 10, "Hello, World!", 13 );

         EndPaint( hWnd, &ps );
         break;

/**************************************************************\
*     WM_COMMAND:                                              *
\**************************************************************/

      case WM_COMMAND:
         switch( wParam ) {
            case IDM_ABOUT:
               DialogBox( ghInstance, "AboutDlg", hWnd, (DLGPROC)
                          AboutDlgProc );
            break;
         }
      break;

/**************************************************************\
*     WM_DESTROY: PostQuitMessage() is called                  *
\**************************************************************/

      case WM_DESTROY:
         PostQuitMessage( 0 );
         break;

/**************************************************************\
*     Let the default window proc handle all other messages    *
\**************************************************************/

      default:
         return( DefWindowProc( hWnd, msg, wParam, lParam ));
   }

   return 0;
}

/********************************************************************\
* Function: LRESULT CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM)*
*                                                                    *
*  Purpose: Processes "About" Dialog Box Messages                    *
*                                                                    *
* Comments: The About dialog box is displayed when the user clicks   *
*           About from the Help menu.                                *
*                                                                    *
\********************************************************************/


BOOL CALLBACK AboutDlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM /*lParam*/)
{

    RECT rect;

switch( uMsg ) {
      case WM_INITDIALOG:
         GetWindowRect(hDlg, &rect);




   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.

           return TRUE ;

      case WM_COMMAND:
         switch( wParam ) {
            case IDOK:
               EndDialog( hDlg, TRUE );
               return TRUE;
         }
      break;

   

   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 FALSE;
}

Alex
0
 
LVL 5

Expert Comment

by:Wyn
Comment Utility
Oh , my god.
I'm told it's the dialog window doesnt show ,not the main window
I'm cheated
:)
0
 

Author Comment

by:Markenstein
Comment Utility
Yeah i'm sorry Alex but its not the main window i want to see, i just want to see the dialog AS the main window.  Like windows calculator.
0
 

Author Comment

by:Markenstein
Comment Utility
Yes i checked the visible flag in the rc editor Norbert, if someone has the source code or an example of how to show a dialog from a rc script as the main form then that will work too.  As long as i can get it to compile and work properly.
0
 

Author Comment

by:Markenstein
Comment Utility
Yes i checked the visible flag in the rc editor Norbert, if someone has the source code or an example of how to show a dialog from a rc script as the main form then that will work too.  As long as i can get it to compile and work properly.
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 50 total points
Comment Utility
Simple change
>>ShowWindow( hWnd, nCmdShow);
 to
ShowWindow( hWnd, SW_HIDE);
And nou you see only dialog(main window
invisible)
Alex




0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

772 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

11 Experts available now in Live!

Get 1:1 Help Now