Solved

Dialog won't show

Posted on 2000-03-11
23
414 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
ID: 2609185
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
ID: 2609302
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
ID: 2609594
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
ID: 2609708
Do you really contain those resource ?
0
 

Author Comment

by:Markenstein
ID: 2609733
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
ID: 2609736
Oh and also i included that file in my source using #include "resource.h"
0
 
LVL 5

Expert Comment

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

Expert Comment

by:Wyn
ID: 2609749
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
ID: 2609894
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
ID: 2609909
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
ID: 2609943
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:Redlord
ID: 2610041
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
ID: 2610135
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
ID: 2610187
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
ID: 2610238
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
ID: 2610803
->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
ID: 2611378
Just a stupid question inside the dialog editor did you enable the visible flag ?
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 2611635
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
ID: 2611671
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
ID: 2612579
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
ID: 2612587
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
ID: 2612610
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
ID: 2612635
Simple change
>>ShowWindow( hWnd, nCmdShow);
 to
ShowWindow( hWnd, SW_HIDE);
And nou you see only dialog(main window
invisible)
Alex




0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

914 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

17 Experts available now in Live!

Get 1:1 Help Now