This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
No Subject
- To: gnu-win32 at cygnus dot com
- From: mjiinas at ix dot netcom dot com
- Date: Fri, 17 Oct 1997 04:59:12 -0500 (CDT)
Hi... I'm an experienced C programmer, but new to C++ and Windows programming. I
recently bought a book on Win95 programming, and it contained some source code for a very
simple example program of which I'll include later. I've tried to compile this simple
program, but failed. I get spammed with several "undefined reference to" error messages.
Also, on another note, is there a way to download all the Cygnus docs off the net
without doing it page by page? This is extremely annoying. DJGPP has a very informative
and useful INFO command. I don't want to spend hours on-line every time I want to refer to
the docs, or have a folder full of a jumble of documents with a confusing list of pages.
Okay, back to the code... They are listed as follows.
1: compile command line.
2: LISTING2.H
3: LISTING2.CPP
4: LISTING2.RC
Any help will be greatly appreciated. Thanks... ^_^
g++ listing2.cpp -lstdc++
LISTING2.H
#define IDM_EXIT 100
#define IDM_TEST 200
#define IDM_ABOUT 301
#define IDC_TEXT 101
#define IDC_EDIT 102
#define IDC_BTN 103
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
LISTING2.CPP
#include <windows.h>
#include "listing2.h"
#if defined (WIN32)
#define IS_WIN32 TRUE
#else
#define IS_WIN32 FALSE
#endif
#define IS_NT IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
#define IS_WIN32S IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
#define IS_WIN95 (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
HINSTANCE hInst; // current instance
LPCTSTR lpszAppName = "MyApp";
LPCTSTR lpszTitle = "Listing 3-2";
BOOL RegisterWin95( CONST WNDCLASS* lpwc );
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HWND hWnd;
WNDCLASS wc;
// Register the main application window class.
//............................................
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( hInstance, lpszAppName );
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = lpszAppName;
wc.lpszClassName = lpszAppName;
if ( IS_WIN95 )
{
if ( !RegisterWin95( &wc ) )
return( FALSE );
}
else if ( !RegisterClass( &wc ) )
return( FALSE );
hInst = hInstance;
// Create the main application window.
//....................................
hWnd = CreateWindow( lpszAppName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0,
CW_USEDEFAULT, 0,
NULL,
NULL,
hInstance,
NULL
);
if ( !hWnd )
return( FALSE );
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
while( GetMessage( &msg, NULL, 0, 0) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return( msg.wParam );
}
BOOL RegisterWin95( CONST WNDCLASS* lpwc )
{
WNDCLASSEX wcex;
wcex.style = lpwc->style;
wcex.lpfnWndProc = lpwc->lpfnWndProc;
wcex.cbClsExtra = lpwc->cbClsExtra;
wcex.cbWndExtra = lpwc->cbWndExtra;
wcex.hInstance = lpwc->hInstance;
wcex.hIcon = lpwc->hIcon;
wcex.hCursor = lpwc->hCursor;
wcex.hbrBackground = lpwc->hbrBackground;
wcex.lpszMenuName = lpwc->lpszMenuName;
wcex.lpszClassName = lpwc->lpszClassName;
// Added elements for Windows 95.
//...............................
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName,
IMAGE_ICON, 16, 16,
LR_DEFAULTCOLOR );
return RegisterClassEx( &wcex );
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
static HWND hText = NULL;
static HWND hEdit = NULL;
static HWND hBtn = NULL;
switch ( uMsg )
{
case WM_COMMAND :
switch( LOWORD( wParam ) )
{
case IDM_TEST :
hText = CreateWindow( "STATIC", "Static Text",
WS_CHILD | WS_VISIBLE | SS_LEFT,
10, 10, 100, 15,
hWnd,
(HMENU)IDC_TEXT,
hInst, NULL );
hEdit = CreateWindow( "EDIT", "",
WS_CHILD | WS_VISIBLE |
ES_LEFT | WS_BORDER,
110, 8, 100, 20,
hWnd,
(HMENU)IDC_EDIT,
hInst, NULL );
hBtn = CreateWindow( "BUTTON", "Push Button",
WS_CHILD | WS_VISIBLE |
BS_PUSHBUTTON,
50, 50, 100, 32,
hWnd,
(HMENU)IDC_BTN,
hInst, NULL );
break;
case IDM_ABOUT :
DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
break;
case IDM_EXIT :
DestroyWindow( hWnd );
break;
}
break;
case WM_DESTROY :
PostQuitMessage(0);
break;
default :
return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
}
return( 0L );
}
LRESULT CALLBACK About( HWND hDlg,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return (TRUE);
case WM_COMMAND:
if ( LOWORD(wParam) == IDOK
|| LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, TRUE);
return (TRUE);
}
break;
}
return (FALSE);
}
LISTING2.RC
#include "windows.h"
#include "listing2.h"
MYAPP ICON DISCARDABLE "GENERIC.ICO"
MYAPP MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", IDM_EXIT
END
MENUITEM "Test!", IDM_TEST
POPUP "&Help"
BEGIN
MENUITEM "&About Listing 3-2...", IDM_ABOUT
END
END
ABOUTBOX DIALOG 22, 17, 171, 43
STYLE DS_MODALFRAME | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU
CAPTION "Listing 3-2"
FONT 8, "MS Sans Serif"
{
CONTROL "MyApp", -1, "STATIC", SS_ICON | WS_CHILD | WS_VISIBLE, 3, 2, 16, 16
CONTROL "Generic Application", -1, "STATIC", SS_LEFT | WS_CHILD | WS_VISIBLE | WS_GROUP,
28, 4, 100, 8
CONTROL "OK", IDOK, "BUTTON", BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_GROUP |
WS_TABSTOP, 116, 26, 50, 14
}
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".