先说明,我不是做MFC的。我想定义多个按扭可总是不成功,这是单独一个的:
#include <windows.h>
static HWND hwndButton = 0;//声明
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = "win player";
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_WINDOWFRAME;//程序底色,设置为白色
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
"win player",
"天使梦魔",
WS_CAPTION,//显示方式,这是一个单独的,应该用组合.因为不用任何效果所以可以为0
300,
300,
400,
250,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nFunsterStil);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_PAINT://当窗口被重画时
hdc = BeginPaint (hwnd, &ps);//使绘图区域有效
TextOut(hdc,165,10,"天使梦魔",8);//参数为:窗口句柄.X,Y坐标.内容.数量(文字占2)
TextOut(hdc,10,30,"当您看到时给我邮件,可以一起讨论C++,系统,网络等问题.",51);
TextOut(hdc,10,50,"E-mail:shakugan.shana@163.com",29);
TextOut(hdc,10,70,"QQ:297397170【397841047】",25);
TextOut(hdc,10,90,"Blog:shakugan.shana.blog.163.com",32);
TextOut(hdc,10,110,"------------------------------------------------",48);
TextOut(hdc,10,125,"梦醒的时候,就全部结束了.我在寻找什么,那是心中的永恒.",52);
EndPaint (hwnd, &ps);//结束绘图区域
return 0;
break;
case WM_CREATE://当一个窗口创建
{
hwndButton = CreateWindow (//创建一个区域,还不确定为何控件
"button",//类型为一个按钮
"退出",//按钮文本
WS_CHILD | WS_VISIBLE,//显示方式
165 , 185,//在程序上显示的X,Y坐标
60, 30,//按钮大小
hwnd,//所在窗口句柄
(HMENU) 1,//按钮ID=1
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
return 0;
break;
}
case WM_COMMAND://点击按钮
if (LOWORD(wParam) == 1 &&
HIWORD(wParam) == BN_CLICKED &&
(HWND) lParam == hwndButton)
{
DestroyWindow (hwnd);
}
return 0;
break;
case WM_DESTROY:
MessageBox (NULL, "程序已卸出内存.", "^_^", MB_OK);
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}