API
来设置
用于控制台窗口 *** 作的API函数如下:
GetConsoleScreenBufferInfo
获取控制台窗口信息
GetConsoleTitle
获取控制台窗口标题
ScrollConsoleScreenBuffer
在缓冲区中移动数据块
SetConsoleScreenBufferSize
更改指定缓冲区大小
SetConsoleTitle
设置控制台窗口标题
SetConsoleWindowInfo
设置控制台窗口信息
此外,还有窗口字体、显示模式等控制函数,这里不再细说。下列举一个示例,程序如下:
#include
#include
#include
void
main()
{
HANDLE
hOut
=
GetStdHandle(STD_OUTPUT_HANDLE)
//
获取标准输出设备句柄
CONSOLE_SCREEN_BUFFER_INFO
bInfo
//
窗口缓冲区信息
GetConsoleScreenBufferInfo(hOut,
bInfo
)
//
获取窗口缓冲区信息
char
strTitle[255]
GetConsoleTitle(strTitle,
255)
//
获取窗口标题
printf("当前窗口标题是:薯桐%s\n",
strTitle)
_getch()
SetConsoleTitle("控制台窗口 *** 作")
//
获取窗口标题
_getch()
COORD
size
=
{80,
25}
SetConsoleScreenBufferSize(hOut,size)
//
重新设置缓冲区大小
_getch()
SMALL_RECT
rc
=
{0,0,
80-1,
25-1}
//
重置窗口位置和大小
SetConsoleWindowInfo(hOut,true
,&rc)
CloseHandle(hOut)
//亩手中
关闭标准输出设备句迅山柄
}
更多请看
http://hi.baidu.com/onlywater/blog/item/917981822ec5b8ba6d81192e.html
建立悄渣Win32应用程序:打开VC6->菜单File->New->Projects->Win32 Application->输入路径启茄悄和工程名->OK
建立MFC应用程纳举序:
打开VC6->菜单File->New->Projects->MFC AppWizard(exe)->输入路径和工程名->OK
实现要求3修改,添加功能。在消息响应的猛橘回调函数中添加该段代码LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
int nSel = 0
switch( msg )
{
case WM_CLOSE:
nSel = MessageBox(hWnd, "你真的要退出吗?", szWindowTitle, MB_YESNO | MB_ICONQUESTION)
if (nSel == IDYES)
DestroyWindow(hWnd)
break
case WM_DESTROY:
PostQuitMessage( 0 )
return 0
default:
return DefWindowProc( hWnd, msg, wParam, lParam )
}
}
完整代码如下:
#include <Windows.h>
#include <tchar.h>
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
const TCHAR szWindowClass[] = "第一个窗口"
const TCHAR szWindowTitle[] = "穗知虚主窗口标题"//WinMain函数猜燃,入口点
int WINAPI _tWinMain (HINSTANCE hInstance, HINSTANCE hPreInstance, LPTSTR lpCmdLine, int nCmdShow )
{ //注册窗口类
WNDCLASSEX wcex = { 0 }
wcex.cbSize = sizeof( WNDCLASSEX )
wcex.style = CS_HREDRAW | CS_VREDRAW
wcex.lpfnWndProc = ( WNDPROC )WndProc
wcex.hInstance = hInstance
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION)
wcex.hCursor = LoadCursor( NULL, IDC_ARROW )
wcex.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH)
wcex.lpszClassName = szWindowClass
RegisterClassEx( &wcex ) //创建窗口
HWND hWnd = CreateWindow(
szWindowClass,
szWindowTitle,
WS_OVERLAPPEDWINDOW,
100, 200, 500, 500,
HWND_DESKTOP,
NULL,
hInstance,
NULL
)
if( !hWnd )
return FALSE
ShowWindow( hWnd, nCmdShow )
UpdateWindow( hWnd )
MSG msg
while( GetMessage( &msg, NULL, 0, 0))
{
TranslateMessage( &msg )
DispatchMessage( &msg )
}
return msg.wParam
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
int nSel = 0
switch( msg )
{
case WM_CLOSE:
nSel = MessageBox(hWnd, "你真的要退出吗?", szWindowTitle, MB_YESNO | MB_ICONQUESTION)
if (nSel == IDYES)
DestroyWindow(hWnd)
break
case WM_DESTROY:
PostQuitMessage( 0 )
return 0
default:
return DefWindowProc( hWnd, msg, wParam, lParam )
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)