Solved

Program executing, but no window.

Posted on 2004-08-01
2
303 Views
Last Modified: 2013-12-03
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
Comment
Question by:TKD
2 Comments
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 11697134
after registering your class call the createWindow function.

You'll need a var of HWND as that is what CreateWindow returns
0
 
LVL 8

Accepted Solution

by:
adg080898 earned 20 total points
ID: 11758779
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

757 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