Hi,
i properly have coded a bitmap to be drawn in a control child of a dialogue in WINAPI.
Now i want to fit the bitmap, that has to be bigger than the window size, in specific coordinates, lateron i want to make controls that move the picture in the window.
My problem is i really don't know where i can set the variables who arrange the picture.
Here's the code (only the main, the headers are not neccessary):
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif
#include <tchar.h>
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>
#include "Resource.h"
#pragma comment (lib, "d3d9.lib")
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK Raumaktionproc (HWND, UINT, WPARAM, LPARAM);
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
LPDIRECT3DVERTEXBUFFER9 g_pVertexBuffer = NULL;
LPDIRECT3DTEXTURE9 g_pTexture = NULL;
#define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZ | D3DFVF_TEX1 )
struct Vertex
{
float x, y, z;
float tu, tv;
};
Vertex g_quadVertices[] =
{
{-1.0f, 1.0f, 0.0f, 0.0f,0.0f },
{ 1.0f, 1.0f, 0.0f, 1.0f,0.0f },
{-1.0f,-1.0f, 0.0f, 0.0f,1.0f },
{ 1.0f,-1.0f, 0.0f, 1.0f,1.0f }
};
static HWND hwndRaumkarte;
void initD3D(HWND hwndRaumkarte);
void render_frame(void);
void cleanD3D(void);
void loadTexture(void);
#define ID_StartDialog 1
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
memset(&messages,0,sizeof(messages));
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
_T("Code::Blocks Template Windows App"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nCmdShow);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance;
switch (message)
{
case WM_CREATE:
{
CreateWindow(TEXT("button"),"Karte anzeigen",WS_CHILD|WS_VISIBLE,
20, 20, 200, 40, hwnd, (HMENU) ID_StartDialog, NULL,NULL);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_StartDialog:
{
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1),hwnd, Raumaktionproc);
InvalidateRect(hwnd,NULL, TRUE);
}
}
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
BOOL CALLBACK Raumaktionproc(HWND hDlg1, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
RECT rect;
hdc=GetDC(hDlg1);
hwndRaumkarte=GetDlgItem(hDlg1, ID_RAUMKARTE);
switch (message)
{
case WM_INITDIALOG:
{
ShowWindow(GetDlgItem(hDlg1, IDD_DIALOG1), TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_OK),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_RAUMKARTE),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_VERTSCROLL),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_HORSCROLL),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_BASIS),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_FEUER),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_GEGNERAUSWAHL),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_KOM),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_FEUERBEENDEN),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_FEUERFLUCHT),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_LABWERFEN),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_LTAUSCHEN),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_MOBILINFO),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_NMOBIL),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_PLANET),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_SCAN),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_VMOBIL),TRUE);
ShowWindow(GetDlgItem(hDlg1, ID_ZIELAUSWAHLLISTE),TRUE);
EnableWindow(GetDlgItem(hDlg1, ID_GEGNERAUSWAHL),FALSE);
EnableWindow(GetDlgItem(hDlg1, ID_FEUERBEENDEN),FALSE);
EnableWindow(GetDlgItem(hDlg1, ID_FEUERFLUCHT),FALSE);
initD3D(hwndRaumkarte);
InvalidateRect(hDlg1, NULL, TRUE);
return FALSE;
};
case WM_PAINT:
{
render_frame();
}
break;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case ID_OK:
{
MessageBox(hDlg1, TEXT ("Runde im All beendet"), "EXO 1.2", MB_ICONEXCLAMATION|MB_OK);
cleanD3D();
EndDialog(hDlg1,0);
return TRUE;
}
break;
}
break;
}
return FALSE;
}
void loadTexture()
{
D3DXCreateTextureFromFile( d3ddev, "Raumkarte.bmp", &g_pTexture );
d3ddev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
d3ddev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
}
void initD3D(HWND hwndRaumkarte)
{
d3d=Direct3DCreate9(D3D_SDK_VERSION);
D3DDISPLAYMODE d3ddm;
d3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed=TRUE;
d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow=hwndRaumkarte;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hwndRaumkarte,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);
loadTexture();
d3ddev->CreateVertexBuffer( 4*sizeof(Vertex), D3DUSAGE_WRITEONLY,
D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT,
&g_pVertexBuffer, NULL );
void *pVertices = NULL;
g_pVertexBuffer->Lock( 0, sizeof(g_quadVertices), (void**)&pVertices, 0 );
memcpy( pVertices, g_quadVertices, sizeof(g_quadVertices) );
g_pVertexBuffer->Unlock();
D3DXMATRIX matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ),
1920.0f / 1080.0f, 0.1f, 100.0f );
d3ddev->SetTransform( D3DTS_PROJECTION, &matProj );
d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
}
void render_frame(void)
{
d3ddev->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0);
D3DXMATRIX matWorld;
D3DXMatrixTranslation( &matWorld, 0.5f, 0.5f, 1.0f );
d3ddev->SetTransform( D3DTS_WORLD, &matWorld );
d3ddev->BeginScene();
d3ddev->SetTexture( 0, g_pTexture );
d3ddev->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(Vertex) );
d3ddev->SetFVF( D3DFVF_CUSTOMVERTEX );
d3ddev->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
d3ddev->EndScene();
d3ddev->Present(NULL,NULL,NULL,NULL);
}
void cleanD3D(void)
{
if( g_pTexture != NULL )
g_pTexture->Release();
if( g_pVertexBuffer != NULL )
g_pVertexBuffer->Release();
d3ddev->Release();
d3d->Release();
}
For now i need someone to tell me where i have to change the attributes to render the picture in different pixel- parts.
I am a newbie, i got two books, but none can really bring light to this question.
Where do i have to start? With the vertices? With the matrix? Or is it in the parts
of D3DXMatrixTranslation or D3DXMatrixPerspectiveFovLH?
Please help, thx,
Chris
|