joe1993 2013-12-24 06:01
浏览 831

这个程序错在哪?求高手回答

#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);

}

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 MATLAB动图问题
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名