我现在已经把一个鼠坑通过FOR循环,在窗体中央变出了9个来.3行3列.
可是我现在想要把地鼠的小图片随机替换这九个鼠坑的图片.该怎么做啊?
最好有代码参考啊~思路很简单,我现在就是烦该怎么实现.
因为刚学,实在很菜,请大家慷慨帮忙哦!

解决方案 »

  1.   

    你可以通过把图片load以后
    放在内存dc里面
    然后等到要画的时候通过bitblt,把图片画到对应的位置上去
      

  2.   

    这个我知道啊,关键是实现过程还是很茫然.因为动手写过的程序不多.
    对了,那随机数怎么弄,我看过一些代码,可不明白SRAND和RAND,为什么要两个函数?怎么用的?
    而且哪个用在哪里?有点晕.
      

  3.   

    先给你一段关于随即数方面的例子
    msdn上,照着用就可以了
    Example
    /* RAND.C: This program seeds the random-number generator
     * with the time, then displays 10 random integers.
     */#include <stdlib.h>
    #include <stdio.h>
    #include <time.h>void main( void )
    {
       int i;   /* Seed the random-number generator with current time so that
        * the numbers will be different every time we run.
        */
       srand( (unsigned)time( NULL ) );   /* Display 10 numbers. */
       for( i = 0;   i < 10;i++ )
          printf( "  %6d\n", rand() );
    }Output
        6929
        8026
       21987
       30734
       20587
        6699
       22034
       25051
        7988
       10104
      

  4.   

    这个我看过了,.你能说说srand( (unsigned)time( NULL ) );这里面的TIME 是什么用的么?
    我就是不明白.
      

  5.   

    再给你一段贴图的代码//将位图选进设备场景中
    HDC memdc;
    memdc = CreateCompatibleDC(hDC);
    HBITMAP hOldMap = SelectObject(memdc ,hBitMap);然后通过BitBlt把memdc的内容考到hDC里面注意一下坐标,以及图片的大小这里,hDC是你窗体的dc 可以通过getdc获得
    hBitMap 是你位图的句柄
    可以通过LoadImage或者LoadBitmap获得
      

  6.   

    随机种子以当前的时间作为随机种子
    The srand function sets the starting point for generating a series of pseudorandom integers. To reinitialize the generator, use 1 as the seed argument. Any other value for seed sets the generator to a random starting point. rand retrieves the pseudorandom numbers that are generated. Calling rand before any call to srand generates the same sequence as calling srand with seed passed as 1.你可以试一下,如果你以一个特定的常量数作为随机种子,那么出来的数都是一样的
      

  7.   

    多谢多谢!前天我在问SDK的问题哪里问的时候也是你说的呀!
      

  8.   

    ……………………
    ……………………
    不客气,大家一起学习
    学sdk的话,
    看看
    windows程序设计
    这本书很不错,有机会去一定要好好看看