游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2234|回复: 4

高手看看我的贴图程序错在哪里

[复制链接]

3

主题

4

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2007-5-20 15:21:00 | 显示全部楼层 |阅读模式
win32 Application程序:为什么我的图显示不出来呢?
望高手不吝赐教,谢谢。。。
其中m0.bmp,m1.bmp,m2.bmp,m3.bmp是3张小图,bg.bmp是大图。
// map1.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"
#include<stdio.h>
#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                                                                // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];
HBITMAP fullmap;
HDC mdc;
const int rows=10,cols=10;                                                                // The title bar text
void MyPaint(HDC hdc);
// 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);

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
        // TODO: Place code here.
        MSG msg;
        HACCEL hAccelTable;

        // Initialize global strings
        LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
        LoadString(hInstance, IDC_MAP1, szWindowClass, MAX_LOADSTRING);
        MyRegisterClass(hInstance);

        // Perform application initialization:
        if (!InitInstance (hInstance, nCmdShow))
        {
                return FALSE;
        }

        hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MAP1);

        // Main message loop:
        while (GetMessage(&msg, NULL, 0, 0))
        {
                if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
                {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                }
        }

        return msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
//    This function and its usage is only necessary if you want this code
//    to be compatible with Win32 systems prior to the 'RegisterClassEx'
//    function that was added to Windows 95. It is important to call this function
//    so that the application will get 'well formed' small icons associated
//    with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
        WNDCLASSEX wcex;

        wcex.cbSize = sizeof(WNDCLASSEX);

        wcex.style                        = CS_HREDRAW | CS_VREDRAW;
        wcex.lpfnWndProc        = (WNDPROC)WndProc;
        wcex.cbClsExtra                = 0;
        wcex.cbWndExtra                = 0;
        wcex.hInstance                = hInstance;
        wcex.hIcon                        = LoadIcon(hInstance, (LPCTSTR)IDI_MAP1);
        wcex.hCursor                = LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground        = (HBRUSH)(COLOR_WINDOW+1);
        wcex.lpszMenuName        = (LPCSTR)IDC_MAP1;
        wcex.lpszClassName        = szWindowClass;
        wcex.hIconSm                = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

        return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HANDLE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;
   HDC mdc,bufdc,hdc;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   MoveWindow(hWnd,10,10,800,600,true);
   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   int mapIndex[rows*cols]={2,2,2,2,2,0,1,0,1,0,
                                3,3,2,2,0,0,0,1,2,0,
                                                        3,0,0,0,0,0,0,0,2,1,
                                                        2,2,2,0,0,0,0,2,2,2,
                                                        2,2,0,0,0,0,2,2,2,2,
                                                        2,2,0,0,0,2,0,0,2,2,
                                                        2,0,0,0,2,2,2,0,1,0,
                                                        0,0,2,3,3,3,1,1,1,1,
                                                        0,2,1,3,3,3,3,3,3,0,
                                                        2,0,2,1,0,3,0,1,3,2};
   hdc=GetDC(hWnd);
   mdc=CreateCompatibleDC(hdc);
   bufdc=CreateCompatibleDC(hdc);

   HBITMAP map[4];
   char filename[20]="";
   int rownum,colnum;
   int x,y,i;
   int xstart,ystart;

   xstart=(rows-1)*32;
   ystart=0;
   fullmap=(HBITMAP)LoadImage(NULL,"bg1.bmp",IMAGE_BITMAP,800,600,LR_LOADFROMFILE);

   MyPaint(hdc);
   for(i=0;i<4;i++)
   {
           sprintf(filename,"m%d.bmp",i);
           map=(HBITMAP)LoadImage(NULL,filename,IMAGE_BITMAP,128,32,LR_LOADFROMFILE);
   }
   for(i=0;i<rows*cols;i++)
   {
           SelectObject(bufdc,map[mapIndex]);
           rownum=i/cols;
           colnum=i%cols;
           x=xstart+colnum*32+rownum*(-32);
           y=ystart+rownum*16+colnum*16;
           BitBlt(mdc,x,y,64,32,bufdc,64,0,SRCAND);
           BitBlt(mdc,x,y,64,32,bufdc,0,0,SRCPAINT);
   }

   ReleaseDC(hWnd,hdc);
   DeleteDC(bufdc);
   return TRUE;
}
void MyPaint(HDC hdc)
{
        SelectObject(mdc,fullmap);
        BitBlt(hdc,0,0,800,600,mdc,0,0,SRCCOPY);
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND        - process the application menu
//  WM_PAINT        - Paint the main window
//  WM_DESTROY        - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
        int wmId, wmEvent;
        PAINTSTRUCT ps;
        HDC hdc;
        TCHAR szHello[MAX_LOADSTRING];
        LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

        switch (message)
        {
                case WM_COMMAND:
                        wmId    = LOWORD(wParam);
                        wmEvent = HIWORD(wParam);
                        // Parse the menu selections:
                        switch (wmId)
                        {
                                case IDM_ABOUT:
                                   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
                                   break;
                                case IDM_EXIT:
                                   DestroyWindow(hWnd);
                                   break;
                                default:
                                   return DefWindowProc(hWnd, message, wParam, lParam);
                        }
                        break;
                case WM_PAINT:
                        hdc = BeginPaint(hWnd, &ps);
                        // TODO: Add any drawing code here...
//                        DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
                        EndPaint(hWnd, &ps);
                        break;
                case WM_DESTROY:
                        PostQuitMessage(0);
                        break;
                default:
                        return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
        switch (message)
        {
                case WM_INITDIALOG:
                                return TRUE;

                case WM_COMMAND:
                        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
                        {
                                EndDialog(hDlg, LOWORD(wParam));
                                return TRUE;
                        }
                        break;
        }
    return FALSE;
}

29

主题

224

帖子

224

积分

中级会员

Rank: 3Rank: 3

积分
224
QQ
发表于 2007-5-20 21:19:00 | 显示全部楼层

Re:高手看看我的贴图程序错在哪里

case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
// DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
好象把你的图覆盖掉了,你看看这样行不行:

case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
MyPaint(hdc);
// DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;

3

主题

4

帖子

0

积分

新手上路

Rank: 1

积分
0
 楼主| 发表于 2007-5-21 10:55:00 | 显示全部楼层

Re:高手看看我的贴图程序错在哪里

MS这样改还是不行啊

2

主题

7

帖子

7

积分

新手上路

Rank: 1

积分
7
发表于 2007-5-21 17:54:00 | 显示全部楼层

Re:高手看看我的贴图程序错在哪里

如果不是DX开发的话 要用黑白图片设置遮照

29

主题

224

帖子

224

积分

中级会员

Rank: 3Rank: 3

积分
224
QQ
发表于 2007-5-23 13:21:00 | 显示全部楼层

Re:高手看看我的贴图程序错在哪里

搞不懂了,能力有限
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-26 09:26

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表