>_<:picture resource

>_<:If you master the ways of mapping picture,then this problem is not problem!Just using your head think some logical method.

>_<:Here,I use a array save where and whith picture should show.For example:use array mapindex save information.then when you map these pictures,only need to calculate the real position and then move it to the bufdc ,finally put it in the mdc (here bufdc in charge of making an exchange between every picture and mdc)

int mapindex[rows*cols]=
{,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,,,
,,,,,,, };
 //按照mapIndex 数组中的定义取出对应图块,进行地图拼接
for(i=;i<rows*cols;i++)
{
SelectObject(bufdc,map[mapindex[i]]);
rowNum=i/cols;//求列编号
colNum=i%cols;//求行编号
x=colNum*;//求贴图x坐标
y=rowNum*; BitBlt(mdc,x,y,,,bufdc,,,SRCCOPY);
}

>_<:Finally, only need to copy mdc to hdc.

>_<:Here is the code

 //{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by FE.RC
//
#define IDR_MAINFRAME 128
#define IDD_FE_DIALOG 102
#define IDD_ABOUTBOX 103
#define IDS_APP_TITLE 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDS_HELLO 106
#define IDI_FE 107
#define IDI_SMALL 108
#define IDC_FE 109
#define IDC_MYICON 2
#define IDC_STATIC -1
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif

resourse.h

 // stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
// #if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // Windows Header Files:
#include <windows.h> // C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h> // Local Header Files // TODO: reference additional headers your program requires here //{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)

StdAfx.h

 #include "stdafx.h"
#include "resourse.h"
#include "stdio.h"
#include "time.h" #define MAX_LOADSTRING 100 // Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
HBITMAP fullmap;
HDC mdc;
const int rows=,cols=; // Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
void MyPaint(HDC hdc);
//========================================================================================
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg; MyRegisterClass(hInstance);//调用函数向系统注册窗口类别,输入参数hInstance是目前运行程序的对象代码; // 调用InitInstance函数,进行初始化操作;
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
} // 消息循环(通过消息循环来获取信息,
//进行必要的键盘信息转换而后将控制权交给操作系统,
//有操作系统决定哪个程序的消息处理函数处理消息
while (GetMessage(&msg, NULL, , )) //获取程序消息
{
TranslateMessage(&msg);//转换伪码及字符
DispatchMessage(&msg);//将控制权交给系统,再有系统决定负责处理消息的程序;
} return msg.wParam;
}
//===================================================================================== //=============================================================================================
//在建立程序窗口实体之前,必须先定义一个窗口类别,其中包含所要建立窗口的信息,
//并向系统注册,这里的MyRegisterClass函数就是进行定义及注册窗口类别的函数。
//==============================================================================================
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex; //申请一个窗口类别“WNDCLASSEX”和结构”wcex“
//--------------------------------------------------------------
//定义vcex结构的各项信息,其中设定信息处理函数(lpfnWndProc)
//为WNDPROC,类别名称为(lpszClassName)为”fe";
//--------------------------------------------------------------
wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = ;
wcex.cbWndExtra = ;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "fe";
wcex.hIconSm = NULL; return RegisterClassEx(&wcex);//调用RegisterClassEx函数注册类别,返回一个“ATOM"形态的字符串
//此字符串即为类别名称”fe";
}
//============================================================================================ //============================================================================================
//按照前面所定义的窗口类别来建立并显示实际的程序窗口
//============================================================================================
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
HDC hdc,bufdc;
hInst = hInstance; // 把instance handle 储存在全局变量中; hWnd = CreateWindow("fe","绘图窗口",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, , CW_USEDEFAULT, , NULL, NULL, hInstance, NULL);
//-----------------------------------------------
//调用CreateWindow函数来建立一个窗口对象
//第一个参数就是窗口建立依据的类别名称
//-----------------------------------------------
if (!hWnd)
{
return FALSE;
}
//------------------------------------------------
//设定窗口的位置及窗口的大小,然后绘制显示在设备上
//-------------------------------------------------
MoveWindow(hWnd,,,,,true);//位置及大小
ShowWindow(hWnd, nCmdShow);//改定窗口显示时的状态
UpdateWindow(hWnd);//将窗口绘制在显示设备上 /*int mapindex[rows*cols]={2,2,3,2,0,1,0,1,
0,2,2,0,3,0,1,1,
0,3,0,7,0,0,0,1,
2,0,3,0,0,0,2,2,
2,7,0,6,0,2,2,2,
2,0,4,0,2,2,0,0,
0,0,2,3,2,1,0,1,
0,0,2,0,3,0,1,1};*/
int mapindex[rows*cols];
srand((unsigned)time(NULL));
for(int j=rows*cols-;j>=;j--)
{
mapindex[j]=rand()%;
} hdc=GetDC(hWnd);
mdc=CreateCompatibleDC(hdc);
bufdc=CreateCompatibleDC(hdc);
fullmap=CreateCompatibleBitmap(hdc,cols*,rows*); SelectObject(mdc,fullmap); HBITMAP map[];
char filename[]="";
int rowNum,colNum;
int i,x,y; for(i=;i<;i++)
{
sprintf(filename,"map%d.bmp",i);
map[i]=(HBITMAP)LoadImage(NULL,filename,IMAGE_BITMAP,,,LR_LOADFROMFILE);
} //按照mapIndex 数组中的定义取出对应图块,进行地图拼接
for(i=;i<rows*cols;i++)
{
SelectObject(bufdc,map[mapindex[i]]);
rowNum=i/cols;//求列编号
colNum=i%cols;//求行编号
x=colNum*;//求贴图x坐标
y=rowNum*; BitBlt(mdc,x,y,,,bufdc,,,SRCCOPY);
} MyPaint(hdc); ReleaseDC(hWnd,hdc);
DeleteDC(bufdc); return TRUE;
}
//============================================================================================ //============================================================================================
//
//============================================================================================
void MyPaint(HDC hdc)
{
SelectObject(mdc,fullmap);
BitBlt(hdc,,,cols*,rows*,mdc,,,SRCCOPY);
}
//============================================================================================ //============================================================================================
//在前面定义类别的时候把WndProc定义为消息处理函数(当某些外部消息发生时,会按消息的类型
//来决定该如何进行处理。此外该函数也是一个回叫函数(CALLBACK)(windows系统函数)每一个
//程序都会接收信息,选择性接受、处理;
//============================================================================================
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc; switch (message) //判断消息类型
{
case WM_PAINT: //窗口重绘制
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY: //处理窗口结束消息
PostQuitMessage();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return ;
}
//============================================================================================

main.cpp

[游戏模版10] Win32 平面地图贴图 正的更多相关文章

  1. [游戏模版7] Win32 最简单贴图

    >_<:this is the first using mapping. >_<:There will be introducing how to do: First load ...

  2. [游戏模版13] Win32 透明贴图 主角移动

    >_<:just add previous two ways to achieve this new result // stdafx.h : include file for stand ...

  3. [游戏模版8] Win32 透明贴图

    >_<:The same with previous introduction. In the InitInstance fanction make a little change: &g ...

  4. 010--VS2013 C++ 平面地图贴图

    先准备好地图的小图片: //全局变量HDC mdc;HBITMAP fullmap;const int rows = 8, cols = 8; //-------------------------- ...

  5. [游戏模版2] Win32最小框架

    >_<:Just the minimum Win32  frame don't have any other special function. //{{NO_DEPENDENCIES}} ...

  6. [游戏模版12] Win32 稳定定时

    >_<:The last time,we learned how to use timer to make the picture run and change show,but some ...

  7. [游戏模版14] Win32 键盘控制

    >_<:compared with the previous article,this one only adds key-message listener. >_<:up d ...

  8. [游戏模版15] Win32 飞机射击

    >_<:Only give you the code,try to understand it! >_<:picture resource #include <windo ...

  9. [游戏模版16] Win32 飞机射击 敌人追踪

    >_<:AI introduction. >_<:According the plane position (nowX,nowY) relative to birds' pos ...

随机推荐

  1. CLR VIA C#事件

    事件是类型的一个成员,用来在事情发生的时候通知注册了该事件的成员. 事件和观察者模式十分的相似,所以事件应该提供如下几种能力 1.能让对象的方法登记对他的关注 2.能让对象的方法取消对他的关注 3.能 ...

  2. socket编程相关的结构体和字节序转换、IP、PORT转换函数

    注意:结构体之间不能直接进行强制转换, 必须先转换成指针类型才可以进行结构体间的类型转换, 这里需要明确的定义就是什么才叫强制转换. 强制转换是将内存中一段代码以另一种不同类型的方式进行解读, 因此转 ...

  3. oracle11g 修改字符集

    查看当前字符集SQL语句: select * from nls_database_parameters where parameter ='NLS_CHARACTERSET'; 修改字符集操作如下,首 ...

  4. lucene中模糊搜索的应用场景

    模糊搜索:wildCardQuery的时候,是用* 表示全部,?表示一个字符,那么直接用*搜索,就能查到当前索引文件的全部数据个数 这里搜索查到的个数和用工具查到的个数是一致的...

  5. max10中对DDR数据的采样转换

    (1)发现IP是这样处理DDR的数据:上长沿采的数据放在低位,下降沿采的数据在高位 (2)对于视频的行场信号是在下降沿采集,再延时一拍才能与数据对齐.

  6. .NET Remoting获取配置通道:

    接上文: public static string ChannelManagerUrl        {            get            {                retu ...

  7. TransactionScope 事务使用说明

    TransactionScope是.Net Framework 2.0滞后,新增了一个名称空间.它的用途是为数据库访问提供了一个“轻量级”[区别于:SqlTransaction]的事物.使用之前必须添 ...

  8. ln 软链接与硬链接的区别再次回顾

    以下是整理的笔记 软硬链接区别 硬链接 软链接 文件有相同的 inode 及 data block 是另一个文件 只能对已存在的文件进行创建 可以对不存在的文件进行创建 不能交叉文件系统进行硬链接的创 ...

  9. 委托 在其他类中修改form中的控件属性

    通常情况下,我们需要在其他业务类中将提示信息时时显示到主界面上,可以通过以下方式 Form1.cs using System; ; i < ; i++) {                 cb ...

  10. 字符串链接strcat

    #include "stdafx.h" #include "iostream" #include "assert.h" #include & ...