Solved

Program executing, but no window.

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 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