这个是基于最新的SDK(截止至2013.8)写的,学习sdk的可以看看,不懂的留言即可

代码如下:
[cpp]
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include "resource.h"
#include <mmsystem.h>
#pragma comment(lib, "WINMM.LIB")
//#include <ShellAPI.h> 新的sdk已经不需要这个头文件了
// 宏定义
#define PlayTipWav PlaySound(_T("SystemStart"), NULL, SND_FILENAME | SND_ASYNC)
//
HINSTANCE hInst;
//
// 函数声明
LRESULT CALLBACK WndProcExp1(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
//
// 主函数
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
WNDCLASSEX Exp1;
//
Exp1.cbSize = sizeof(WNDCLASSEX);
Exp1.style = 3; // 窗口样式"CS_HREDRAW | CS_VREDRAW","0x0002+0x0001"=3
Exp1.lpfnWndProc = WndProcExp1;
Exp1.cbClsExtra = NULL;
Exp1.cbWndExtra = NULL;
Exp1.hInstance = hInstance;
Exp1.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON));
Exp1.hCursor = LoadCursor(NULL,IDC_ARROW);
Exp1.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
Exp1.lpszMenuName = NULL;
Exp1.lpszClassName = _T("Exp1");
Exp1.hIconSm = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON));
//
// 关于窗口类的注册
if (!RegisterClassEx(&Exp1)) // 如果窗口类注册未成功
MessageBox(NULL,_T("窗口类注册失败!!!"),_T("错误!"),NULL);
else
MessageBox(NULL,_T("窗口类注册成功!!!"),_T("恭喜!"),NULL);
//
hInst=hInstance;
//
// 开始创建窗口
HWND hWnd=CreateWindow(
_T("Exp1"),_T("Win32 程序实例 — Exp1"),
WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME,
CW_USEDEFAULT,CW_USEDEFAULT,1024,768,NULL,NULL,hInstance,NULL);
//
// 窗口创建相关
if (!hWnd)
MessageBox(NULL,_T("创建窗口失败!!!"),_T("Oops!"),NULL);
else
MessageBox(NULL,_T("创建窗口成功!!!"),_T("恭喜!"),NULL);
//
ShowWindow(hWnd,nCmdShow);
// UpdateWindow(hWnd);
//
// 主循环
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam; // 强制类型转换!
}
//
// 具体实现函数
LRESULT CALLBACK WndProcExp1(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
int CtrlID=LOWORD(wParam);

//
switch(message)
{
case WM_CREATE: // 绘制相关
// 绘制区域1
CreateWindow(_T("button"),_T("这里是区域1"),WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
5,5,1008,480,hWnd,(HMENU)0001,((LPCREATESTRUCT)lParam)->hInstance,NULL);
// 关于按钮
CreateWindow(_T("button"),_T("关于程序"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
945,710,70,24,hWnd,(HMENU)0002,((LPCREATESTRUCT)lParam)->hInstance,NULL);
// 关于作者
CreateWindow(_T("button"),_T("关于作者"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
870,710,70,24,hWnd,(HMENU)0003,((LPCREATESTRUCT)lParam)->hInstance,NULL);
// 播放BGM
CreateWindow(_T("button"),_T("播放BGM"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
795,710,70,24,hWnd,(HMENU)0004,((LPCREATESTRUCT)lParam)->hInstance,NULL);
// 停止BGM
CreateWindow(_T("button"),_T("停止BGM"),WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
720,710,70,24,hWnd,(HMENU)0005,((LPCREATESTRUCT)lParam)->hInstance,NULL);
//

break;
// 消息响应
case WM_COMMAND:
switch(CtrlID)
{
case 0001:
MessageBox(hWnd,_T("您点击了区域1"),_T("Tip"),NULL);
break;
case 0002:
PlayTipWav; // 播放声音
MessageBox(hWnd,_T("本示例适合入门的sdk开发者\n\n By ragnaroks"),_T("关于"),NULL);
break;
case 0003:
ShellExecute(NULL,_T("open"),_T("http://www.ragnaroks.org/about"),NULL,NULL,SW_SHOW);
break;
case 0004:
PlaySound(_T("res\\BGM.wav"),NULL, SND_FILENAME | SND_ASYNC);
break;
case 0005:
PlaySound(NULL,NULL, SND_FILENAME | SND_ASYNC);
break;
}
// 绘制相关
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// 绘制设备上下文
// 结束绘制
EndPaint(hWnd, &ps);
break;
// 程序退出
case WM_DESTROY:
PostQuitMessage(0);
break;
// 其他
default:
return DefWindowProc(hWnd, message, wParam, lParam);
break;
}
return 0;
}
[/cpp]

[另有一篇”WinSDK 示例 Exp1-改”推荐查看]点击打开