First of all, thanks to Vckbase for the exchange of the environment and the numerous XDJM to provide selfless help, I am quite fruitful in this. Recently because of the work of a PDA embedded project, the evil to fill some of this knowledge, back to feel a lot of detours, so wrote this little game, take out to share, hope as a PDA game to write the introductory tutorial, can give later some help, the level is limited, do not laugh.
The code involved is for the WINCE3.0 (PPC2002) platform, while taking into account the WIN32 platform, designed to discuss the preparation of the same time to adapt to the 2 platform of common code, using the most original BitBlt map and the way out of the screen, the texture effect is relatively rough. The treatment of sound is also relatively naïve, hope not to mislead beginners. The game algorithm and the picture part reference Wang Zhengsheng's A10 attack fighter and the Kylinx Kplan code, in this to two authors announces the source code selfless behavior to express the gratitude!
Procedural points:
1, PC and wince compilation environment distinction, using #if _win32_wce #else #endif宏, similar to StdAfx.h
//WINCE环境
#if _WIN32_WCe
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <aygshell.h>
#include <sipapi.h>
#define ScreenW 240 //游戏窗口宽度
#define ScreenH 320 //游戏窗口高度
#else //PC环境,只在WIN2000 Pro/VC6下测试过
#include <stdio.h>
#include <mmsystem.h>
#pragma comment(lib,"winmm.lib")
#define TCHAR char
#define wcslen strlen
#define wcscmp strcmp
#define wcscpy strcpy
#define wcscat strcat
#define wcsncpy strncpy
#define swprintf sprintf
#define SHLoadDIBitmap(szBmpName) (HBITMAP)LoadImage(GetModuleHandle(NULL),\
szBmpName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
#define ScreenW 450 //游戏窗口宽度
#define ScreenH 550 //游戏窗口高度
#endif
About this, I believe we all know, just mention, not in detail
2. Part of the game setup
This part of the implementation of relatively naïve, edit get focus, in the corresponding HDC area to draw the press any key message, and then infinite wait for the message (keyboard press), do not know if there is a better way? See the "Set Window callback function" code snippet for details:
if (HiWord (wParam) = = En_setfocus)
{
GetCursorPos (&P);
ScreenToClient (HWNDSET,&P);
GetClientRect (HWNDSET,&RCDLG);
Rc.left = p.x;
Rc.right = Rc.left + 80;
if (rc.right>rcdlg.right)
{
Rc.right = Rcdlg.right;
Rc.left = rc.right-80;
}
Rc.top = P.Y;
Rc.bottom = Rc.top + 20;
HDC = GetDC (Hwndset);
SetBkMode (HDC, transparent);
SetTextColor (HDC, RGB (255,0,0));
DrawText (Hdc,text ("Press any Key"), -1,&rc,dt_left);
Todo
{
Wait for the keyboard to press the message
MSG msg;
GetMessage (&msg,null,0,0);
if (msg.message = = Wm_keydown)
{
if ((vkey = LoWord (msg.wparam))!=-1)
bpress = TRUE;
}
}while (bpress = = FALSE);
swprintf (Str,text ("%d"), vkey);
Only detect these special key values, other special almost no
if (0 = = wcscmp (Str,text ("16"))
wcscpy (Str,text ("SHIFT"));
else if (0 = wcscmp (str,text ("17"))
wcscpy (Str,text ("Control"));
else if (0 = wcscmp (str,text ("32"))
wcscpy (Str,text ("Space"));
else if (0 = wcscmp (str,text ("37"))
wcscpy (Str,text ("left"));
else if (0 = wcscmp (str,text ("38"))
wcscpy (Str,text ("Up"));
else if (0 = wcscmp (str,text ("39"))
wcscpy (Str,text ("Rtght"));
else if (0 = wcscmp (str,text ("40"))
wcscpy (Str,text ("Down"));
Else
swprintf (Str,text ("%c"), vkey);
SetWindowText (:: GetFocus (), str);
SendMessage (hwndset,wm_nextdlgctl,0,0);
InvalidateRect (hwndset,&rc,true);
DeleteDC (HDC);
//end if (hiword (wParam) = = En_setfocus) here