主题:我写了一个,小窗口程序,可是不知道如何,相应菜单事件,请指教。
我写了一个,小窗口程序,可是不知道如何,相应菜单事件,请指教。
谢谢一楼的提示:
我是在WINDOWS下,用API编程,用C++语言:
//这里是主程序:
/********************************************************************\
* Windows程序的基本例程
* standard.c: Source code for standard
*
* Comments: standard Application
*
* Functions:
* WinMain - Application entry point
* MainWndProc - main window procedure
*
\********************************************************************/
/********************* Header Files *********************/
#include <windows.h>
/********************* Prototypes ***********************/
LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );
/******************* Global Variables ********************/
HANDLE ghInstance;
/********************************************************************\
* Function: int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
*
* Purpose: Initializes Application
*
* Comments: Register window class, create and display the main
* window, and enter message loop.
*
\********************************************************************/
int PASCAL WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
int nCmdShow )
{
WNDCLASS wc;
MSG msg;
HWND hWnd;
if( !hPrevInstance )
{
wc.lpszClassName = "standardAppClass";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
wc.lpszMenuName = "StandardMenu";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass( &wc );
}
ghInstance = hInstance;
hWnd = CreateWindow( "standardAppClass",
"standard Application",
WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
0,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow( hWnd, nCmdShow );
// UpdateWindow(hWnd);
while( GetMessage( &msg, NULL, 0, 0 ) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return (int)msg.wParam;
}
/********************************************************************\
* Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM
*
* Purpose: Processes Application Messages
*
* Comments: The following messages are processed
*
* WM_PAINT
* WM_LBUTTONDOWN
* WM_DESTROY
*
\********************************************************************/
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam )
{
PAINTSTRUCT ps;
HDC hDC;
switch( msg ) {
/**************************************************************\
* WM_PAINT:
\**************************************************************/
case WM_PAINT:
hDC = BeginPaint( hWnd, &ps );
TextOut( hDC, 10, 10, "Hello, World!", 13 );
EndPaint( hWnd, &ps );
break;
/**************************************************************\
* WM_LBUTTONDOWN:
\**************************************************************/
case WM_LBUTTONDOWN:
MessageBox(NULL, "跨过长城,走向世界!", "^_^", MB_OK);
break;
/**************************************************************\
* WM_DESTROY: PostQuitMessage() is called
\**************************************************************/
case WM_DESTROY:
PostQuitMessage( 0 );
break;
/**************************************************************\
*Let the default window proc handle all other messages
\**************************************************************/
default:
return( DefWindowProc( hWnd, msg, wParam, lParam ));
}
return 0;
}
//这里是资源头文件:
//
// Used by STANDARD.RC
//
#define IDM_OPEN 104
#define IDM_EXIT 105
#define IDM_CLOSE 106
#define IDM_COPY 107
#define IDM_CUT 108
#define IDM_PASTE 109
//这里是资源文件:
// resource script.
//
#include "resource.h"
#include "windows.h"
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
StandardMenu MENU DISCARDABLE
BEGIN
POPUP "文件"
BEGIN
MENUITEM "打开", IDM_OPEN
MENUITEM "关闭", IDM_CLOSE
MENUITEM "退出", IDM_EXIT
END
POPUP "编辑"
BEGIN
MENUITEM "复制", IDM_COPY
MENUITEM "剪切", IDM_CUT
MENUITEM "粘贴", IDM_PASTE
END
END
谢谢一楼的提示:
我是在WINDOWS下,用API编程,用C++语言:
//这里是主程序:
/********************************************************************\
* Windows程序的基本例程
* standard.c: Source code for standard
*
* Comments: standard Application
*
* Functions:
* WinMain - Application entry point
* MainWndProc - main window procedure
*
\********************************************************************/
/********************* Header Files *********************/
#include <windows.h>
/********************* Prototypes ***********************/
LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM );
/******************* Global Variables ********************/
HANDLE ghInstance;
/********************************************************************\
* Function: int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
*
* Purpose: Initializes Application
*
* Comments: Register window class, create and display the main
* window, and enter message loop.
*
\********************************************************************/
int PASCAL WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmdLine,
int nCmdShow )
{
WNDCLASS wc;
MSG msg;
HWND hWnd;
if( !hPrevInstance )
{
wc.lpszClassName = "standardAppClass";
wc.lpfnWndProc = MainWndProc;
wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
wc.lpszMenuName = "StandardMenu";
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClass( &wc );
}
ghInstance = hInstance;
hWnd = CreateWindow( "standardAppClass",
"standard Application",
WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
0,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow( hWnd, nCmdShow );
// UpdateWindow(hWnd);
while( GetMessage( &msg, NULL, 0, 0 ) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return (int)msg.wParam;
}
/********************************************************************\
* Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM
*
* Purpose: Processes Application Messages
*
* Comments: The following messages are processed
*
* WM_PAINT
* WM_LBUTTONDOWN
* WM_DESTROY
*
\********************************************************************/
LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam,
LPARAM lParam )
{
PAINTSTRUCT ps;
HDC hDC;
switch( msg ) {
/**************************************************************\
* WM_PAINT:
\**************************************************************/
case WM_PAINT:
hDC = BeginPaint( hWnd, &ps );
TextOut( hDC, 10, 10, "Hello, World!", 13 );
EndPaint( hWnd, &ps );
break;
/**************************************************************\
* WM_LBUTTONDOWN:
\**************************************************************/
case WM_LBUTTONDOWN:
MessageBox(NULL, "跨过长城,走向世界!", "^_^", MB_OK);
break;
/**************************************************************\
* WM_DESTROY: PostQuitMessage() is called
\**************************************************************/
case WM_DESTROY:
PostQuitMessage( 0 );
break;
/**************************************************************\
*Let the default window proc handle all other messages
\**************************************************************/
default:
return( DefWindowProc( hWnd, msg, wParam, lParam ));
}
return 0;
}
//这里是资源头文件:
//
// Used by STANDARD.RC
//
#define IDM_OPEN 104
#define IDM_EXIT 105
#define IDM_CLOSE 106
#define IDM_COPY 107
#define IDM_CUT 108
#define IDM_PASTE 109
//这里是资源文件:
// resource script.
//
#include "resource.h"
#include "windows.h"
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
StandardMenu MENU DISCARDABLE
BEGIN
POPUP "文件"
BEGIN
MENUITEM "打开", IDM_OPEN
MENUITEM "关闭", IDM_CLOSE
MENUITEM "退出", IDM_EXIT
END
POPUP "编辑"
BEGIN
MENUITEM "复制", IDM_COPY
MENUITEM "剪切", IDM_CUT
MENUITEM "粘贴", IDM_PASTE
END
END