School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,096 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,032 people online right now. Registration is fast and FREE... Join Now!




Show a text in a game screen using DirectX(prob)

 

Show a text in a game screen using DirectX(prob)

James_Alex

8 Oct, 2009 - 04:34 AM
Post #1

D.I.C Head
Group Icon

Joined: 21 Aug, 2009
Posts: 100


Dream Kudos: 50
My Contributions
i tries this
CODE

#include <stdio.h>
#include <windows.h>
#include <process.h>
#include "ChatBox.h"
#include <d3d9.h>
#include <d3dx9.h>
#include <time.h>


#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
LPD3DXBUFFER Buf;
LPD3DXMESH Mesh;
LPDIRECT3DTEXTURE9 Texture;
HWND hWnd;
ID3DXSprite *Sprite;
ID3DXFont *Font;

void ChatBox::Create()
{
    
    hWnd = FindWindow(NULL, "GTA: San Andreas");
    if(hWnd == NULL)
    {
        printf("Error");
        Sleep(5000);
    }
    //SetWindowText(hWnd, "PES:MP");
    initD3D(hWnd);
    Run(hWnd);
    //d9dx->render_frame(d3d, d3ddev);
}

void ChatBox::Draw()
{
    RECT rect;
    rect.top        = 9;
    rect.left        = 9;
    rect.bottom        = 110;
    rect.right        = 550;
    if(FAILED(D3DXCreateFont(d3ddev, 100, 100, FW_BOLD, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &Font)))
    {
        MessageBox(NULL, "An Error has been occured when creating the ChatBox\n the error may come from your DirectX\n try to reinstall it or re-try to open again.1", "Error", MB_OK | MB_ICONSTOP);
        return;
    }    
    if(FAILED(D3DXCreateSprite(d3ddev,&Sprite)))
    {
        MessageBox(NULL, "An Error has been occured when creating the ChatBox\n the error may come from your DirectX\n try to reinstall it or re-try to open again.1", "Error", MB_OK | MB_ICONSTOP);
        return;
    }
    if(FAILED(Sprite->Begin( D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE )))
    {
        MessageBox(NULL, "An Error has been occured when creating the ChatBox\n the error may come from your DirectX\n try to reinstall it or re-try to open again.", "Error", MB_OK | MB_ICONSTOP);
        return;
    }
    
    Font->DrawTextA(Sprite, "teest", -1, &rect, DT_NOCLIP|DT_SINGLELINE|DT_LEFT,0xFF000000);
    Font->Release();
    Sprite->End();  
}

int ChatBox::AddMessage(const char *Msg, ...)
{
    char buf[512];
    memset(buf,0,512);
    va_list ap;
    va_start(ap, Msg);
    vsprintf(buf, Msg, ap);
    va_end(ap);
    return 1;
}
int initD3D(HWND hwnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if (d3d == NULL)
    {
        MessageBox(hwnd, "An Error has been occured when creating the ChatBox\n the error may come from your DirectX\n try to reinstall it or re-try to open again.", "Error", MB_OK | MB_ICONSTOP);
        return 0;
    }
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
       d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
    if (d3ddev == NULL)
    {
        MessageBox(hwnd, "An Error has been occured when creating the ChatBox\n the error may come from your DirectX\n try to reinstall it or re-try to open again.", "Error", MB_OK | MB_ICONSTOP);
        return 0;
    }
    srand(time(NULL));
    return 1;

}

void Run(HWND hwnd)
{
    if (d3ddev == NULL)
    {
        MessageBox(hwnd, "An Error has been occured when creating the ChatBox\n the error may come from your DirectX\n try to reinstall it or re-try to open again.", "Error", MB_OK | MB_ICONSTOP);
        return;
    }
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,255,0), 1.0f, 0);
    if(FAILED(d3ddev->BeginScene()))
    {
        MessageBox(hwnd, "An Error has been occured when creating the ChatBox\n the error may come from your DirectX\n try to reinstall it or re-try to open again.", "Error", MB_OK | MB_ICONSTOP);
        return;
        
    }
    else
    {
        d3ddev->EndScene();
    }
    d3ddev->Present(NULL, NULL, NULL, NULL);
}

void render_frame(LPDIRECT3D9 d3d, LPDIRECT3DDEVICE9 d3ddev)
{
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
    d3ddev->BeginScene();
    d3ddev->EndScene();
    d3ddev->Present(NULL, NULL, NULL, NULL);
}

void cleanD3D(LPDIRECT3D9 d3d, LPDIRECT3DDEVICE9 d3ddev)
{
    d3ddev->Release();
    d3d->Release();
}


and i like to show the teest word in the GTA San Andreas screen
no errors or warnings for it and not even a probleme
but after loading it with a console nothing happens
can u help me please ?

User is offlineProfile CardPM
+Quote Post


KYA

RE: Show A Text In A Game Screen Using DirectX(prob)

9 Oct, 2009 - 05:26 PM
Post #2

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 11,499



Thanked: 508 times
Dream Kudos: 2875
Expert In: C, C++, Java

My Contributions
I just read over your code and could not find where chatBox was either called or initialized.

There isn't a main() here either. You'll put the handle code in the run scene section, but there's a missing link you haven't provided (i.e. what you're actually running).
User is online!Profile CardPM
+Quote Post

James_Alex

RE: Show A Text In A Game Screen Using DirectX(prob)

10 Oct, 2009 - 03:23 AM
Post #3

D.I.C Head
Group Icon

Joined: 21 Aug, 2009
Posts: 100


Dream Kudos: 50
My Contributions
QUOTE(KYA @ 9 Oct, 2009 - 05:26 PM) *

I just read over your code and could not find where chatBox was either called or initialized.

There isn't a main() here either. You'll put the handle code in the run scene section, but there's a missing link you haven't provided (i.e. what you're actually running).

i created new file named ChatBox this is the cpp code
and then i created the ChatBox.h and created a class and put all the functions then i called it in the main file
CODE

BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID Reserved)
{
    switch(dwReason)
    {
    case DLL_PROCESS_ATTACH:
        // Disable thread calls
        DisableThreadLibraryCalls(hModule);

            chat->Create();
            chat->Draw();

            
                
        break;
    case DLL_PROCESS_DETACH:
        break;
    }
    return true;
}

is there any probleme here ?

This post has been edited by James_Alex: 10 Oct, 2009 - 03:24 AM
User is offlineProfile CardPM
+Quote Post

James_Alex

RE: Show A Text In A Game Screen Using DirectX(prob)

7 Nov, 2009 - 11:47 AM
Post #4

D.I.C Head
Group Icon

Joined: 21 Aug, 2009
Posts: 100


Dream Kudos: 50
My Contributions
n one can help please sry for double posts
i listened that i have to hook the d3d9.dll
so i searched in a lot forums, and in the Google but nothing was found
can u help me to hook it
or gives me a link that do it please ?
thanks
User is offlineProfile CardPM
+Quote Post

Aeternalis

RE: Show A Text In A Game Screen Using DirectX(prob)

9 Nov, 2009 - 11:13 AM
Post #5

D.I.C Regular
***

Joined: 13 Jul, 2009
Posts: 273



Thanked: 25 times
My Contributions
The moderators have made it perfectly clear that we are not to provide information about hooking anything. You are welcome to search the internet for this topic. Rest assured if you use google and the correct keywords, you will find tutorials explaining exactly how this is done.

The information you are seeking will not, however, be provided here.

Good luck!
Aet

User is offlineProfile CardPM
+Quote Post

James_Alex

RE: Show A Text In A Game Screen Using DirectX(prob)

14 Nov, 2009 - 07:31 AM
Post #6

D.I.C Head
Group Icon

Joined: 21 Aug, 2009
Posts: 100


Dream Kudos: 50
My Contributions
ah ok
sry
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 11:51AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month