Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42215

[C] - using API functions

$
0
0
finally i can use API in functions in C;)
Code:

#include <conio.h>
#include <conio2.h>
#include <stdio.h>
#include <windows.h>

HWND foco;
HDC  a;
 
int main()
{
        foco = GetForegroundWindow(); //get the handle
        a=GetDC( foco); //get the DC
       
        SetWindowPos(foco, 0, 100, 100, 500, 500, 0); //change the window and size position
        SetWindowText(foco, "Generic Application 1.0"); //change the caption\title window
       
        getch();       
        return 0;
}

but now i'm trying load an image and then draw it:
Code:

#include <conio.h>
#include <conio2.h>
#include <stdio.h>
#include <windows.h>

void DrawBitmap(HDC hdcDest, char* filename, int x, int y);

HWND foco;
HDC  a;
 
int main()
{
        foco = GetForegroundWindow();
        a=GetDC( foco);
       
        //SetWindowPos(foco, 0, 100, 100, 500, 500, 0);
        //SetWindowText(foco, "Generic Application 1.0");
        DrawBitmap(a,"C:\\Users\\Joaquim\\Pictures\\Sprites\\Breath of Fire II Party Sprites_ficheiros\\Bleu Battle.gif",0,0);       
        getch();       
        return 0;
}

void DrawBitmap(HDC hdcDest, char *filename, int x, int y)
{
        HBITMAP image;
        BITMAP bm;
        HDC hdcMem;
        image = (HBITMAP)LoadImage(0, filename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
        GetObject(image, sizeof(BITMAP), &bm);
        hdcMem = CreateCompatibleDC(hdcDest);
        SelectObject(hdcMem, image);
        BitBlt(
                hdcDest,
                x, y,
                bm.bmWidth, bm.bmHeight,
                hdcMem,
                0, 0,
                SRCCOPY);
        DeleteDC(hdcMem);
        DeleteObject((HBITMAP)image);
}

i found these funtion in internet and i just don't understand 3 things.
but i don't get any error and the image isn't showed:(
why the image isn't showed?:(

Viewing all articles
Browse latest Browse all 42215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>