Solved

Program executing, but no window.

Posted on 2004-08-01
2
308 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best way to accomplish this task? 3 89
Build VS2015 project in bat command 3 93
What .NET URL re-routing tool did I use? 2 76
How can my static class become undefined?? 8 65
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…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 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