Results 1 to 1 of 1
  1. #1
    Dwar
    Dwar is offline
    Veteran Dwar's Avatar
    Join Date
    2010 Mar
    Posts
    2,221
    Thanks
    211
    Thanked 2,224 Times in 289 Posts
    Rep Power
    10

    Simple menu class

    The function's name speak for themselves, except for InitControls. To initiate the hotkeys for the menu, just put InitControls in a loop and create a seperate thread for it.
    void MainThread()
    {
    while(true)
    {
    MenuInstance->InitControls();
    }
    }
    ....
    CreateThread(0,0,(LPTHREAD_START_ROUTINE)MainThrea d,0,0,0);

    That's the only seemingly confusing part. Use the menu item's index to get it's current status ( on/off ).

    Menu.h:
    #include <windows.h>
    #include <d3d9.h>
    #include <d3dx9.h>

    struct MenuItem {
    int index;
    char* text;
    bool status;
    MenuItem* pNext;
    };

    class cMenu {
    private:
    IDirect3DDevice9* m_pDevice;
    ID3DXFont* m_pFont;
    MenuItem* MenuItems;
    int CurrSelected;
    int m_nItems;

    public:
    cMenu(IDirect3DDevice9*,ID3DXFont*);
    void Update(IDirect3DDevice9*,ID3DXFont*);

    void AddItem(char*,int);
    void RenderMenu(void);
    void InitControls(void);
    void Release(void);
    bool GetStatus(int);
    };

    #endif

    Menu.cpp
    #include "Menu.h"


    cMenu::cMenu(IDirect3DDevice9 *pDevice, ID3DXFont *pFont)
    {
    cMenu::m_pDevice = pDevice;
    cMenu::m_pFont = pFont;
    cMenu::MenuItems = NULL;
    cMenu::CurrSelected = 1;
    cMenu::m_nItems = 0;
    }

    void cMenu::Update(IDirect3DDevice9 *pDevice, ID3DXFont *pFont)
    {
    cMenu::m_pDevice = pDevice;
    cMenu::m_pFont = pFont;
    }

    void cMenu::AddItem(char *text, int index)
    {
    MenuItem* Ptr = new MenuItem;
    MenuItem* Before = new MenuItem;
    MenuItem* New = new MenuItem;

    New->index = index;
    New->text = text;
    New->status = false;
    New->pNext = NULL;

    if(cMenu::MenuItems == NULL)
    {
    cMenu::MenuItems = New;
    cMenu::MenuItems->pNext = NULL;
    } else {
    Ptr = cMenu::MenuItems;
    while(Ptr->pNext != NULL)
    {
    Ptr = Ptr->pNext;
    }
    Ptr->pNext = New;
    }
    cMenu::m_nItems++;

    }

    void cMenu::RenderMenu()
    {
    MenuItem* Ptr = new MenuItem;
    MenuItem* Before = new MenuItem;
    MenuItem* New = new MenuItem;

    RECT rect;
    rect.top = 20;
    rect.left = 20;
    rect.right = 150;
    rect.bottom = 20;

    Ptr = cMenu::MenuItems;
    do
    {
    if(!(Ptr->index == CurrSelected) && !Ptr->status)
    {
    cMenu::m_pFont->DrawText(0,Ptr->text,-1,&rect,DT_LEFT|DT_NOCLIP,D3DCOLOR_XRGB(255,0,0)) ;
    cMenu::m_pFont->DrawText(0,"Off",-1,&rect,DT_RIGHT|DT_NOCLIP,D3DCOLOR_XRGB(255,0,0)) ;
    }
    if(Ptr->index == CurrSelected && !Ptr->status)
    {
    cMenu::m_pFont->DrawText(0,Ptr->text,-1,&rect,DT_LEFT|DT_NOCLIP,D3DCOLOR_XRGB(0,255,0)) ;
    cMenu::m_pFont->DrawText(0,"Off",-1,&rect,DT_RIGHT|DT_NOCLIP,D3DCOLOR_XRGB(0,255,0)) ;
    }

    if(!(Ptr->index == CurrSelected) && Ptr->status)
    {
    cMenu::m_pFont->DrawText(0,Ptr->text,-1,&rect,DT_LEFT|DT_NOCLIP,D3DCOLOR_XRGB(255,0,0)) ;
    cMenu::m_pFont->DrawText(0,"On",-1,&rect,DT_RIGHT|DT_NOCLIP,D3DCOLOR_XRGB(255,0,0)) ;
    }
    if(Ptr->index == CurrSelected && Ptr->status)
    {
    cMenu::m_pFont->DrawText(0,Ptr->text,-1,&rect,DT_LEFT|DT_NOCLIP,D3DCOLOR_XRGB(0,255,0)) ;
    cMenu::m_pFont->DrawText(0,"On",-1,&rect,DT_RIGHT|DT_NOCLIP,D3DCOLOR_XRGB(0,255,0)) ;
    }


    rect.top += 17;
    Ptr = Ptr->pNext;
    }while(Ptr != NULL);



    }

    void cMenu::InitControls()
    {
    MenuItem* Ptr = new MenuItem;

    if(GetAsyncKeyState(VK_DOWN))
    {
    if(CurrSelected != cMenu::m_nItems)
    CurrSelected += 1;

    Sleep(100);
    }
    if(GetAsyncKeyState(VK_UP))
    {
    if(CurrSelected != 1)
    CurrSelected -= 1;

    Sleep(100);
    }
    if(GetAsyncKeyState(VK_RIGHT))
    {
    Ptr = cMenu::MenuItems;
    while(Ptr != NULL)
    {
    if(Ptr->index == CurrSelected)
    {
    break;
    }
    Ptr = Ptr->pNext;
    }
    Ptr->status = !Ptr->status;

    Sleep(100);
    }
    if(GetAsyncKeyState(VK_LEFT))
    {
    Ptr = cMenu::MenuItems;
    while(Ptr != NULL)
    {
    if(Ptr->index == CurrSelected)
    {
    break;
    }
    Ptr = Ptr->pNext;
    }
    Ptr->status = !Ptr->status;

    Sleep(100);
    }
    }

    void cMenu::Release()
    {
    cMenu::m_pDevice->Release();
    cMenu::m_pFont->Release();
    }

    bool cMenu::GetStatus(int index)
    {
    MenuItem* Ptr = new MenuItem;
    Ptr = cMenu::MenuItems;
    while(Ptr != NULL)
    {
    if(Ptr->index == index)
    {
    break;
    }
    Ptr = Ptr->pNext;
    }
    return Ptr->status;
    }

    The whole project is the attached file below.
    by Void

    Please register or login to download attachments.

    Please, post your questions on forum, not by PM or mail

    I spend my time, so please pay a little bit of your time to keep world in equilibrium

Similar Threads

  1. Simple VB Write/Read Memory Class
    By Dwar in forum VB, .NET Framework
    Replies: 3
    Last Post: 2012-07-22, 05:11 PM
  2. [Source] Evo Button Menu
    By Dwar in forum D3D Programming
    Replies: 3
    Last Post: 2012-07-19, 08:20 AM
  3. [Hack] Perfect World D3D AutoPot Ingame Menu
    By Grooguz in forum Perfect World Bots, Cheats
    Replies: 3
    Last Post: 2012-02-11, 02:44 PM
  4. Replies: 0
    Last Post: 2010-12-15, 01:40 PM
  5. [Source] Keyboard Menu
    By Dwar in forum D3D Programming
    Replies: 0
    Last Post: 2010-12-15, 01:15 PM
Visitors found this page by searching for:

how to make a d3d menu in c

c d3d menu

d3d menĂ¼ c

c d3d menu tutorial

c game menu tutorial

d3d menu source code c

c d3d9 menu

simple menu d3d

d3d menu class

c d3d menu source code

C D3D menu source

programming game menu c

D3D9 Menu.h

text menu class c

simple d3d9 menu

text menu c

menu D3D C

game menu class

programming games c menu

game menu c

simple d3d menu

d3d9 menu

c menu class code

simple menu in c

d3d9 menu c

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •