源码图片资源下载:http://yunpan.cn/cjfX8pUHciGYs 提取码 da83
#include "KuGou.h"
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("KuGou") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = NULL;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = (HICON)LoadImage(NULL,TEXT ("image\\icon.ico"),IMAGE_ICON,0,0,LR_LOADFROMFILE);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
//注册子窗口控件
RegisterCtl();
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
0, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
SetWindowLong(hwnd,GWL_STYLE,WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_POPUP);
ShowWindow (hwnd, SW_SHOWNORMAL) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
TRACKMOUSEEVENT tme;
ZeroMemory(&tme, sizeof(tme));
static int bInit = false; //阻止多次初始化,导致最小化再打开窗口边框丢失
int i;
switch (message)
{
case WM_CREATE:
//初始化
Init( hwnd );
//创建控件
CreateChildCtr(lParam, st_ui.hwndButton,hwnd);
return 0 ;
case WM_SIZE:
if (!bInit)
InitSize(lParam);
InitCtlRt(st_ui.ctrRt);
AdjustCtlPlace();
bInit = true;
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
//画界面
DrawUI(hdc);
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_LBUTTONDOWN:
if (CLOSE == mouseIn[CLOSE])
{
DeleteObj();
PostQuitMessage(0);
DestroyWindow(hwnd);
}
if (MIN == mouseIn[MIN])
::SendMessage(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
::SendMessage(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
return 0 ;
case WM_MOUSEMOVE:
int CtrId;
CtrId = isInWndCtr(LOWORD(lParam),HIWORD(lParam));
if (-1 != CtrId)
InvalidateRect(hwnd,&st_ui.ctrRt[mouseIn[CtrId]],false);
if (-1 != lastmouseIn && CtrId != lastmouseIn)
{
InvalidateRect(hwnd,&st_ui.ctrRt[lastmouseIn],false);
lastmouseIn = -1;
}
//追踪鼠标
if( !bMouseTracking )
{
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = hwnd;
tme.dwHoverTime = 0;
TrackMouseEvent(&tme);
bMouseTracking = true;
}
return 0 ;
//处理WM_MOUSELEAVE,鼠标离开窗口会出发此消息
case WM_MOUSELEAVE:
::SendMessage(hwnd, WM_MOUSEMOVE, 0, 0);
bMouseTracking = false;
return 0;
case WM_KEYUP:
if (wParam == VK_ESCAPE)
{
PostQuitMessage(0);
::DestroyWindow(hwnd);
}
return 0 ;
case WM_DESTROY:
DeleteObj();
PostQuitMessage(0);
DestroyWindow(hwnd);
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
//初始化
BOOL Init( HWND hwnd )
{
//初始化窗口数据
st_scroll.bShow = false;
bMouseTracking = false;
//初始化位图
st_ui.g_hdc = GetDC(hwnd);
//从文件加载3张边框位图
st_ui.g_hTop = (HBITMAP)LoadImage(NULL,TEXT ("image\\top.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
st_ui.g_hLeft = (HBITMAP)LoadImage(NULL,TEXT ("image\\left.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
st_ui.g_hBottom = (HBITMAP)LoadImage(NULL,TEXT ("image\\bottom.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
//初始化关闭、最小按钮
st_ui.g_hClose[0] = (HBITMAP)LoadImage(NULL,TEXT ("image\\close1.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
st_ui.g_hClose[1] = (HBITMAP)LoadImage(NULL,TEXT ("image\\close2.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
st_ui.g_hMin[0] = (HBITMAP)LoadImage(NULL,TEXT ("image\\min1.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
st_ui.g_hMin[1] = (HBITMAP)LoadImage(NULL,TEXT ("image\\min2.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
//获取位图尺寸
GetObject(st_ui.g_hTop, sizeof(st_ui.infoTop), &st_ui.infoTop);
GetObject(st_ui.g_hLeft, sizeof(st_ui.infoLeft), &st_ui.infoLeft);
GetObject(st_ui.g_hBottom, sizeof(st_ui.infoBottom), &st_ui.infoBottom);
GetObject(st_ui.g_hClose[0], sizeof(st_ui.infoClose[0]), &st_ui.infoClose[0]);
GetObject(st_ui.g_hClose[1], sizeof(st_ui.infoClose[1]), &st_ui.infoClose[1]);
GetObject(st_ui.g_hMin[0], sizeof(st_ui.infoMin[0]), &st_ui.infoMin[0]);
GetObject(st_ui.g_hMin[1], sizeof(st_ui.infoMin[1]), &st_ui.infoMin[1]);
//建立兼容DC
st_ui.g_mdc = CreateCompatibleDC(st_ui.g_hdc);
ReleaseDC(hwnd,st_ui.g_hdc);
//播放音乐
PlaySound (TEXT ("music\\hellokugou.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
return TRUE;
}
//画界面
void DrawUI(HDC hdc)
{
int i;
//画界面顶部
SelectObject (st_ui.g_mdc, st_ui.g_hTop) ;
StretchBlt (hdc, 0, 0, st_ui.w_top,st_ui.h_top,
st_ui.g_mdc, 0, 0, st_ui.infoTop.bmiHeader.biWidth,
st_ui.infoTop.bmiHeader.biHeight, SRCCOPY) ;
//画界面左边