• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

Program executing, but no window.

Hi. Experts:
I write a simple code:
BMPViewer.c:
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;
#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 ("BMPViewer") ;
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;
     
     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
     wndclass.lpfnWndProc   = WndProc ;
     wndclass.cbClsExtra    = 0 ;
      /*      
            cbWndExtra :
            Specifies the number of extra bytes to allocate following the window instance.
            The system initializes the bytes to zero. If an application uses WNDCLASS to
            register a dialog box created by using the CLASS directive in the resource file,
            it must set this member to DLGWINDOWEXTRA.
      */
     wndclass.cbWndExtra    = DLGWINDOWEXTRA ;    // Note!
     wndclass.hInstance     = hInstance ;
     wndclass.hIcon         = LoadIcon (NULL,IDI_APPLICATION) ;
     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
     wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1) ;
     wndclass.lpszMenuName  = NULL ;
     wndclass.lpszClassName = szAppName ;
     
     if (!RegisterClass (&wndclass))
     {
          MessageBox (NULL, TEXT ("This program requires Windows NT!"),
                      szAppName, MB_ICONERROR) ;
          return 0 ;
     }
     
     hwnd = CreateDialog (hInstance, szAppName, 0, NULL) ;
     
     ShowWindow (hwnd, iCmdShow) ;
     
     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_DESTROY:
                  PostQuitMessage (0) ;
                  return 0 ;      
     }

     return DefWindowProc (hwnd, message, wParam, lParam) ;
}
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;

Viewer.rc
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// Chinese (Taiwan) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHT)
#ifdef _WIN32
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL
#pragma code_page(950)
#endif //_WIN32

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE DISCARDABLE
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE DISCARDABLE
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE DISCARDABLE
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

BMPViewer DIALOG DISCARDABLE  0, 0, 272, 194
STYLE DS_MODALFRAME | DS_CENTER | WS_VISIBLE | WS_CAPTION
CAPTION "BMP Viewer"
FONT 10, "System"
BEGIN
    DEFPUSHBUTTON   "Exit",IDOK,215,7,50,14
    PUSHBUTTON      "Open",IDOPEN,215,24,50,14
    CONTROL         "",IDC_STATIC1,"Static",SS_GRAYFRAME | NOT WS_VISIBLE,31,
                    38,184,130
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
    BMPViewer, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 265
        VERTGUIDE, 215
        TOPMARGIN, 7
        BOTTOMMARGIN, 187
        HORZGUIDE, 38
    END
END
#endif    // APSTUDIO_INVOKED

#endif    // Chinese (Taiwan) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;;;
When i executing the BMPViewer.exe,there is no window display.
But i find that BMPViewer.exe is executing.
How do i to modify???
Thanks!
0
TKD
Asked:
TKD
1 Solution
 
Jase-CoderCommented:
after registering your class call the createWindow function.

You'll need a var of HWND as that is what CreateWindow returns
0
 
adg080898Commented:
This appears to be your problem:

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     
     switch (message)
     {
     
          case WM_DESTROY:
               PostQuitMessage (0) ;
               return 0 ;    
     }

     return DefWindowProc (hwnd, message, wParam, lParam) ;     // <---- here
}


Don't call DefWindowProc! Call DefDlgProc (with the same parameters).
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now