?
Solved

Program executing, but no window.

Posted on 2004-08-01
2
Medium Priority
?
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 80 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

765 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