问题描述
- 这个程序错在哪?求高手回答
-
#include
#include
#include
#include
#include "Snow.h"/* UpdateLayeredWindow declaration*/
typedef BOOL (WINAPI lpfnUpdateLayeredWindow)(
HWND, HDC, POINT, SIZE*, HDC, POINT*,COLORREF, BLENDFUNCTION*, DWORD);/* global variables /
ULONG_PTR gidplusStartupToken;
lpfnUpdateLayeredWindow lpMyFunc;
const TCHAR szAppName[] = _T("DeskSnow");
const int iScreenWidth = GetSystemMetrics(SM_CXSCREEN);
const int iScreenHeight = GetSystemMetrics(SM_CYSCREEN);
std::vector<CSnow> vctSnow; /* vector container holds images *//* global function */
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM wPara, LPARAM lPara);
void CreateSnow();void CreateSnow(HDC hdc)
{
//std::vector::iterator iter;
std::vector::iterator iter;
for(iter=vctSnow.begin(); iter!=vctSnow.end(); iter++)
{
if((*iter)->ReachBoundrary())
{
delete (*iter);
vctSnow.erase(iter);CSnow::m_bFirstTime = false; CSnow *pSnow = new CSnow; vctSnow.push_back(pSnow); break; } } for(iter=vctSnow.begin(); iter!=vctSnow.end(); ++iter) (*iter)->DrawSnow(hdc);
}
void Display(HWND hwnd, float timeDela)
{
HDC hdc = GetDC(hwnd);
HDC hMemDC = CreateCompatibleDC(hdc);
HBITMAP hBitmap = CreateCompatibleBitmap(hdc, iScreenWidth, iScreenHeight);
SelectObject(hMemDC, hBitmap);CreateSnow(hMemDC); HDC hScreenDC = GetDC(NULL); POINT ptSrc = {0, 0}; SIZE size = {iScreenWidth, iScreenHeight}; BLENDFUNCTION blend; blend.AlphaFormat = AC_SRC_ALPHA; blend.BlendFlags = 0; blend.BlendOp = AC_SRC_OVER; blend.SourceConstantAlpha = 255; lpMyFunc(hwnd, hScreenDC, &ptSrc, &size, hMemDC, &ptSrc, 0, &blend, 2); DeleteDC(hMemDC); DeleteObject(hBitmap);
}
int WINAPI WinMain( In HINSTANCE hInstance,
In_opt HINSTANCE hPrevInstance,
In LPSTR lpCmdLine,
In int nShowCmd )
{Gdiplus::GdiplusStartupInput gdiInput; Gdiplus::GdiplusStartup(&gidplusStartupToken, &gdiInput, NULL); MSG msg; WNDCLASSEX wex; HWND hWnd; wex.cbClsExtra = 0; wex.cbSize = sizeof(WNDCLASSEX); wex.cbWndExtra = 0; wex.hbrBackground = (HBRUSH)COLOR_BACKGROUND; wex.hCursor = LoadCursor(NULL, IDC_APPSTARTING); wex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wex.hInstance = hInstance; wex.lpfnWndProc = WndProc; wex.lpszClassName = szAppName; wex.lpszMenuName = NULL; wex.style = CS_DBLCLKS; RegisterClassEx(&wex); /* Create a window, the size is the same as screen's */ hWnd = CreateWindowEx(WS_EX_LAYERED|WS_EX_TOPMOST/*|WS_EX_TOOLWINDOW*/,szAppName, szAppName, 0, 0, 0, iScreenWidth, iScreenHeight, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nShowCmd); UpdateWindow(hWnd); static float dwLastTick = (float)timeGetTime(); ZeroMemory(&msg, sizeof(msg)); while(msg.message != WM_QUIT) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); }else{ float dwCurrTick = (float)timeGetTime(); float timeDela = dwCurrTick - dwLastTick; Display(hWnd, timeDela); dwLastTick = dwCurrTick; } } Gdiplus::GdiplusShutdown(gidplusStartupToken); return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wPara, LPARAM lPara)
{
HINSTANCE hUser32;switch (msg) { case WM_CREATE: /* Load function*/ hUser32 = LoadLibrary(_T("User32.dll")); lpMyFunc = (lpfnUpdateLayeredWindow)GetProcAddress(hUser32, "UpdateLayeredWindow"); FreeLibrary(hUser32); for(int i=0; i<50; ++i) { CSnow *pSnow = new CSnow; vctSnow.push_back(pSnow); } PlaySound(_T("Music\贝多芬 - 致爱丽丝.WAV"), NULL, SND_ASYNC | SND_FILENAME|SND_SYSTEM); break; case WM_DESTROY: PostQuitMessage(0); break; default: break; } return DefWindowProc(hwnd, msg, wPara, lPara);
}