圣诞节程序c语言,windows编程入门二:圣诞节的礼物——从“屏幕飘雪”程序说起...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

这段是定义全局变量和写一个窗口。大家注意ShowWindow(hwnd,SW_SHOWMINIMIZED),这说明当创建时是最小化的窗口。

#include

#include

#include

#include "resource.h"

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM) ;

HINSTANCE hInst;

HDC hScrnDC;

HDC hCoverScrnDC;

HDC hMaskDC;

HDC hSnowDC;

HBITMAP hCoverScrnBmp;

HBITMAP hMaskBmp;

HBITMAP hSnowBmp;

int Position[300][2] = {0};

int Snow[300] = {0};

int xScrn;

int yScrn;

int Vx;

int Vy;

int pVx;

int pVy;

int nCount = 0;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)

{

hInst = hInstance;

static TCHAR szAppName[]=TEXT("Snow");

HWND hwnd;

MSG msg;

WNDCLASS wndclass ;

wndclass.style           =CS_HREDRAW|CS_VREDRAW;

wndclass.lpfnWndProc     =WndProc;

wndclass.cbClsExtra      =0;

wndclass.cbWndExtra      =0;

wndclass.hInstance       =hInstance;

wndclass.hIcon           =LoadIcon(hInst,MAKEINTRESOURCE(IDI_ICON1));

wndclass.hCursor         =LoadCursor(NULL,IDC_IBEAM);

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 ;

}

hwnd=CreateWindow(szAppName,

TEXT("Snow"),

WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT,

CW_USEDEFAULT,

CW_USEDEFAULT,

CW_USEDEFAULT,

NULL,

NULL,

hInstance,

NULL);

ShowWindow(hwnd,SW_SHOWMINIMIZED);

UpdateWindow(hwnd);

while (GetMessage(&msg,NULL,0,0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msg.wParam;

}

你可能感兴趣的:(圣诞节程序c语言)