连连看API版本的源代码[7]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

LRESULT CALLBACK WndProc ( HWND hwnd, UINT message,
    WPARAM wParam, LPARAM lParam )
{
 HDC  hdc,hdcMem;
 //HBRUSH hBrush ;
 PAINTSTRUCT ps ;//绘图结构
 static RECT  rect,rect2 ;//矩形
 static HBITMAP hBitmap1,hBitmap2;//两个位图文件句柄
 HBITMAP hBitmap3;
 BITMAP  bitmap ;//位图文件
 static int cxBack,cyBack,cxPre,cyPre,cxStart,cyStart;
    //cxBack,cyBack:背景图片大小
    //cxPre,cyPre:牌面图片大小  
 int x,y,i,j,num;

 bool find;//是否有路径标志
 static bool first_started=false;//是否是刚打开程序
 static bool bPrompt=false;//是否提示
 TCHAR    szBuffer[14];
 static HINSTANCE hInstance ;
 static HMENU  hMenu ;//菜单句柄
 static int  iCurrentLevel = IDM_APP_LOW ;//记录游戏难度
 static int  iTime = 100 ;//记录游戏的剩余时间
 static  int  iShuffle=0,iPrompt=0;
  //iShuffle:重新洗牌的剩余次数,iPrompt:提示的剩余次数
 static int iCount=0;//统计消去的对数,用于判断是否胜利
 static Linker_Matrix linker ;//连连看的运算矩阵
 static point  pSelected[2] ;//用于记录选择的两个点
    
 switch (message)
 {
 case WM_CREATE://进行初始化;
  //PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
  //GetClientRect(hwnd,&rect);

  MoveWindow(hwnd,(GetSystemMetrics(SM_CXSCREEN)-xsize)/2,(GetSystemMetrics(SM_CYSCREEN)-ysize)/2,xsize,ysize,false);
  //将窗口移置屏幕中间

  hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
  hMenu = GetMenu (hwnd) ;
  pSelected[0].x=pSelected[0].y=0;
  pSelected[1].x=pSelected[1].y=0;

  hBitmap1 = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_BACK"));
  hBitmap2 = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_PRE"));
  

  GetObject (hBitmap1, sizeof (BITMAP), &bitmap) ;

  cxBack = bitmap.bmWidth ;
  cyBack = bitmap.bmHeight/7 ;
  GetObject (hBitmap2, sizeof (BITMAP), &bitmap) ;

  cxPre = bitmap.bmWidth/2 ;
  cyPre = bitmap.bmHeight/42 ;

  //SendMessage(hwnd,WM_COMMAND,IDM_APP_START,0);
  first_started=true;
  
  return 0 ;

 case WM_TIMER:
  if(iTime>0)
   iTime--;

  //使字体所在区域无效化,重绘
  rect.left = 0;
  rect.right = xsize;
  rect.top  = 0;
  rect.bottom = 20;
  InvalidateRect (hwnd, &rect, true) ;
  rect.left = 0;
  rect.right = 0;
  rect.top  = 0;
  rect.bottom = 0;

  if( iTime<=0 )
  {
   iCount=0;
   KillTimer (hwnd, TimerID) ;
   MessageBox (hwnd, TEXT ("时间到,你输了!!"),szAppName, MB_OK | MB_ICONQUESTION) ;
   

   SendMessage(hwnd,WM_COMMAND,IDM_APP_START,0);

   linker=Linker_Matrix();
   InvalidateRect (hwnd, NULL, true) ;
  }
  


  return 0;

  

 case WM_PAINT:
  hdc = BeginPaint (hwnd, &ps) ;
  
  //GetClientRect (hwnd, &rect) ;
  hdcMem = CreateCompatibleDC (hdc) ;
   
  

本文关键:连连看API版本的源代码
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top