放逐之城有食物还饿死:一个简单得不得了的C问题啊

来源:百度文库 编辑:高考问答 时间:2024/04/28 01:03:33
因为刚刚接触C,所以什么都不懂
谁可以说下这个程序要怎么写:
点确定后出现对话框:"请等待"
然后5秒后关闭上一个“请等待”对话框,跳出确定,然后点OK,自动关闭程序
就这么简单,拜托各位大大帮忙啊

我想楼主说的C语言可能指的是Windows下的C语言程序设计吧.
下面的代码是根据VC6自动建的"Hello World"改编的,我不知道该怎么把整个工程中的所有文件发上来(不知道有没有专用的uue压缩软件,没的话...我也没法了),所以只选了我认为几个比较重要的文件

=========================ex2.cpp文件=========================
// ex2.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text

// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM); //对话框回调函数

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;

// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_EX2, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_EX2);

// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}

//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_EX2);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_EX2;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);
}

//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

static HWND hWndButton;
static BOOL btnClicked = FALSE;

switch (message)
{
case WM_CREATE:
////////////////////////////////////////////////////////////////
hWndButton = CreateWindowEx( 0L, "BUTTON", "确定",
WS_CHILD | BS_PUSHBUTTON,
50, 50, 100, 60,
hWnd, (HMENU)NULL,
hInst, (LPVOID)NULL); //创建一个BUTTON控件
ShowWindow(hWndButton, TRUE); //显示创建的按钮
break;
////////////////////////////////////////////////////////////////
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
/**********************************************************
//接收按钮按下所发生的事件.
//
//罗嗦一下,对于控件的通知消息通常是WM_COMMAND消息,这个消息
//的lParam为控件句柄; LOWORD(wParam)为控件ID,HIWORD(wParam)
//为消息的代码.
//
***********************************************************/
case BN_CLICKED:
if((HWND)lParam == hWndButton)
{
if(!btnClicked)
{
DialogBox(hInst, (LPCTSTR)IDD_DIALOG, hWnd, (DLGPROC)DlgProc);
btnClicked = TRUE;
}
else
DestroyWindow(hWnd);
}
break;
////////////////////////////////////////////////////////////////
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Mesage handler for about box.
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, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}

//对话框回调函数
LRESULT CALLBACK DlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
SetTimer(hDlg, ID_TIMER, /*这个ID_TIMER我在资源里定义了*/
5000, (TIMERPROC)NULL);
return TRUE;
case WM_TIMER:
EndDialog(hDlg, LOWORD(wParam));
break;
case WM_DESTROY:
KillTimer(hDlg, ID_TIMER);
break;
}
return FALSE;
}

=========================resource.h文件=========================
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by ex2.rc
//
#define IDC_MYICON 2
#define IDD_EX2_DIALOG 102
#define IDD_ABOUTBOX 103
#define IDS_APP_TITLE 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDS_HELLO 106
#define IDI_EX2 107
#define IDI_SMALL 108
#define IDC_EX2 109
#define ID_TIMER 110
#define IDR_MAINFRAME 128
#define IDD_DIALOG 130
#define IDC_STATIC -1

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 131
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 111
#endif
#endif

=========================ex2.rc文件=========================
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS
#include "resource.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// Chinese (P.R.C.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Icon
//

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_EX2 ICON DISCARDABLE "ex2.ICO"
IDI_SMALL ICON DISCARDABLE "SMALL.ICO"

/////////////////////////////////////////////////////////////////////////////
//
// Menu
//

IDC_EX2 MENU DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "E&xit", IDM_EXIT
END
POPUP "&Help"
BEGIN
MENUITEM "&About ...", IDM_ABOUT
END
END

/////////////////////////////////////////////////////////////////////////////
//
// Accelerator
//

IDC_EX2 ACCELERATORS MOVEABLE PURE
BEGIN
"?", IDM_ABOUT, ASCII, ALT
"/", IDM_ABOUT, ASCII, ALT
END

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

IDD_ABOUTBOX DIALOG DISCARDABLE 22, 17, 230, 75
STYLE DS_MODALFRAME | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 8, "System"
BEGIN
ICON IDI_EX2,IDC_MYICON,14,9,16,16
LTEXT "ex2 Version 1.0",IDC_STATIC,49,10,119,8,SS_NOPREFIX
LTEXT "Copyright (C) 2006",IDC_STATIC,49,20,119,8
DEFPUSHBUTTON "OK",IDOK,195,6,30,11,WS_GROUP
END

IDD_DIALOG DIALOG DISCARDABLE 0, 0, 157, 59
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
CAPTION "Dialog"
FONT 10, "System"
BEGIN
CONTROL "请等待...",IDC_STATIC,"Static",SS_SIMPLE | WS_GROUP,63,
25,31,8
END

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

2 TEXTINCLUDE DISCARDABLE
BEGIN
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""windows.h""\r\n"
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""resource.h""\r\n"
"\0"
END

3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END

1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END

#endif // APSTUDIO_INVOKED

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

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_DIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 150
TOPMARGIN, 7
BOTTOMMARGIN, 52
END
END
#endif // APSTUDIO_INVOKED

/////////////////////////////////////////////////////////////////////////////
//
// String Table
//

STRINGTABLE DISCARDABLE
BEGIN
IDS_APP_TITLE "ex2"
IDS_HELLO "Hello World!"
IDC_EX2 "EX2"
END

#endif // Chinese (P.R.C.) resources
/////////////////////////////////////////////////////////////////////////////

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

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

============================================
楼主的消息已收到
试发了下,当场晕倒...
可能百度不允许发类似于uue格式打包的乱字符,发了好几次,每次都提示页面找不到!
算了,我把这个放到一个空间里,那空间速度很慢很慢很慢的说,但是是能下的,多试几次,不行用多线程下.哎,毕竟现在免费的东西难找啊~
下载地址1:
http://www.websamba.com/sideweb/temp/ex2.rar
下载地址2:
http://www.box.net/index.php?rm=box_v2_download_shared_file&file_id=f_13505186

我学过C但第一次听说C能写出面象对象的程序还弹出个对话况,真是老了啊什么都不懂了,顺便提示下 楼主说的好象是VB写的或JAVA写的或网页C好象还没这能力或许是我功力太浅吧

我也只会用C来应付考试,就是还不会用它来写一个像样的程序.