Link to home
Start Free TrialLog in
Avatar of yesnaud
yesnaud

asked on

Windows

Hi,

a.I would like to have an example of how creating a windows and displaying it on win95.

b.I aslo would like to have a status bar, the c++ program that I am creating will take some time so I would like to display where about the program is to inform the user that it's still running and doing some stuff. Can anyone give me an example of that too...

Thanks for your help.
Avatar of Tom Knowlton
Tom Knowlton
Flag of United States of America image

Which compiler are you using?

For example, Borland C++ Builder, Microsoft Visual C++?

If you have C++ Builder, I'd be happy to send you some source code / demos on what you're trying to do.
Avatar of yesnaud
yesnaud

ASKER

Sorry it was for VC++ 6.0

It's been a long time since I've programmed in VC++.  There are plenty of people who DO know it, though.  I'm sure they'll be along shortly.  :)

Good luck.
go to file->new
and choose project
than choose MFC exe application, and walk through the instruction
Avatar of yesnaud

ASKER

I don't want to go through the instruction, I want to have a simple code, to create a window, and a status bar...

Sorry.
Use all these files below, together with the library "comctl32.lib" (common controls).

The functions "CreateStatusWindow()", "DrawStatusText()" and "MenuHelp()" could be of some help to you. You might find it worthy to look into them.

You can look in the online help for "Platform, SDK, and DDK Documentation" -> "Platform SDK" -> "User Interface Services" -> "Common Controls" -> "Status Windows".

Hope this helps !

-----[ statusbar.c ]------------------------------------------------------------

/***************************************************************************
Standard Windows headers
***************************************************************************/

#define STRICT
#include <windows.h>

#include <commctrl.h> /* for common controls support, maybe diff in NT */

#include <stdio.h> /* for sprintf */

/***************************************************************************
Special headers
***************************************************************************/

#include "resource/resource.h"   /* for the identifiers into .rc */

/***************************************************************************
Definitions
***************************************************************************/

#define NROF_STATUSPARTS 6  /* number of partitions in the status window */

/***************************************************************************
Prototyping
***************************************************************************/

BOOL CALLBACK MainWindow (HWND, UINT, WPARAM, LPARAM);

/***************************************************************************
Globals
***************************************************************************/

HINSTANCE g_hInstance   = NULL; /* global: current application instance handle */
HWND      g_hMainWindow = NULL; /* global: main window handle */
HWND      g_hStatusBar  = NULL; /* global: status bar window handle */

/***************************************************************************
Application entry point
***************************************************************************/

int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR     szCmdLine,
                    int       iCmdShow)
{
MSG msg;

g_hInstance = hInstance;

/* Initialize common controls library */
InitCommonControls();

/* Create a modeless dialog box, using a dialog from the resource script file
   In this particular case, the dialog "IDD_MAIN" in the .rc file is used.    */

g_hMainWindow = CreateDialog (hInstance, MAKEINTRESOURCE (IDD_MAIN), NULL, &MainWindow);

if (g_hMainWindow)
   {
   while (GetMessage (&msg, NULL, 0, 0))
         {
         if (g_hMainWindow == NULL || !IsDialogMessage (g_hMainWindow, &msg))
            {
            TranslateMessage (&msg);
            DispatchMessage (&msg);
            }
         }

   if (g_hMainWindow)
      {
      DestroyWindow (g_hMainWindow);
      g_hMainWindow = NULL;
      }
   }

return (0);
}

/***************************************************************************
Main window message handler
***************************************************************************/

BOOL CALLBACK MainWindow (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
BOOL  handledmsg = FALSE; /* Message handled or not state  */

RECT rcclient;
int  statuspartwidth;
int  statuspart[NROF_STATUSPARTS];
int  index;
int  style;
char sbtext[256];

switch (msg)
       {
       case WM_INITDIALOG: /* Create the status window */
                           g_hStatusBar = CreateWindow (STATUSCLASSNAME, "",
                                                        WS_CHILD | WS_VISIBLE,
                                                        0, 0, 0, 0,
                                                        hwnd, NULL, g_hInstance, NULL);

                           if (g_hStatusBar)
                              {
                              GetClientRect (hwnd, &rcclient);
                              statuspartwidth = rcclient.right / NROF_STATUSPARTS;

                              for (index = 0; index < NROF_STATUSPARTS; index++)
                                  statuspart[index] = statuspartwidth * (index + 1);

                              SendMessage (g_hStatusBar, SB_SETPARTS, NROF_STATUSPARTS, (LPARAM) statuspart);

                              for (index = 0; index < NROF_STATUSPARTS; index++)
                                  {
                                  switch (index % 3)
                                         {
                                         case 1 : style = SBT_POPOUT;
                                                  break;

                                         case 2 : style = SBT_NOBORDERS;
                                                  break;

                                         default: style = 0;
                                                  break;
                                         }

                                  sprintf (sbtext, "Statusbar part %d", index);
                                  SendMessage (g_hStatusBar, SB_SETTEXT, index | style, (LPARAM) sbtext);
                                  }
                              }

                           handledmsg = TRUE;
                           break;

       case WM_CLOSE:      SendMessage (hwnd, WM_DESTROY, 0, 0);
                           handledmsg = TRUE;
                           break;

       case WM_DESTROY:    if (g_hStatusBar)
                              {
                              DestroyWindow (g_hStatusBar);
                              g_hStatusBar = NULL;
                              }

                           PostQuitMessage (0);

                           handledmsg = TRUE;
                           break;
       }

if (msg == WM_COMMAND)
   {
   switch (LOWORD (wp))
          {
          case IDCANCEL:
          case IDOK:     SendMessage (hwnd, WM_CLOSE, (WPARAM) 0, (LPARAM) 0);
                         handledmsg = TRUE;
                         break;
          }
   }

return (handledmsg);
}





-----[ resource.h ]-------------------------------------------------------------

//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Statusbar.rc
//
#define IDD_MAIN                        101

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        102
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1001
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif





-----[ statusbar.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

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

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

IDD_MAIN DIALOG DISCARDABLE  0, 0, 352, 111
STYLE DS_3DLOOK | DS_NOFAILCREATE | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP |
    WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Statusbar"
FONT 8, "MS Sans Serif"
BEGIN
    PUSHBUTTON      "E&xit",IDOK,295,7,50,14
END


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

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
    IDD_MAIN, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 345
        TOPMARGIN, 7
        BOTTOMMARGIN, 104
    END
END
#endif    // APSTUDIO_INVOKED


#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

#endif    // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////



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


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED


Avatar of yesnaud

ASKER

Hi, it doesn't seem to find this function:

IsDialogMessage

Y.
ASKER CERTIFIED SOLUTION
Avatar of BSoeters
BSoeters

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial