Archief - [PROG][C++] Initialisatie van DirectX

Het archief is een bevroren moment uit een vorige versie van dit forum, met andere regels en andere bazen. Deze posts weerspiegelen op geen enkele manier onze huidige ideeën, waarden of wereldbeelden en zijn op sommige plaatsen gecensureerd wegens ontoelaatbaar. Veel zijn in een andere tijdsgeest gemaakt, al dan niet ironisch - zoals in het ironische subforum Off-Topic - en zouden op dit moment niet meer gepost (mogen) worden. Toch bieden we dit archief nog graag aan als informatiedatabank en naslagwerk. Lees er hier meer over of start een gesprek met anderen.

IceSkull[BE]

Legacy Member
Ik heb dus net men boek uit van C++, en ik ben begonnen met DirectX. Maar het eerste programma wil niet compilen zonder foutmeldingen.. bedoeling is hier een blanco venster.

hier is de code:

#include <windows.h>

HINSTANCE hInst;
HWND wndHandle;

//forward declarations
bool initWindow(HINSTANCE hInstance); //prototype
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
if(!initWindow(hInstance))
return false;

MSG msg;
ZeroMemory( &msg, sizeof(msg));
while(msg.message!=WM_QUIT)
{
//Check message queue
while (GetMessage(&msg, wndHandle, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}



/******************************************************************************
* bool initWindow( HINSTANCE hInstance )
* initWindow registers the window class for the application, creates the window
******************************************************************************/
bool initWindow( HINSTANCE hInstance )
{
WNDCLASSEX wcex;

// Fill in the WNDCLASSEX structure. This describes how the window
// will look to the system
wcex.cbSize = sizeof(WNDCLASSEX); // the size of the structure
wcex.style = CS_HREDRAW | CS_VREDRAW; // the class style
wcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callback
wcex.cbClsExtra = 0; // extra bytes to allocate for this class
wcex.cbWndExtra = 0; // extra bytes to allocate for this instance
wcex.hInstance = hInstance; // handle to the application instance
wcex.hIcon = 0; // icon to associate with the application
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); // the default cursor
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // the background color
wcex.lpszMenuName = NULL; // the resource name for the menu
wcex.lpszClassName = "DirectXExample"; // the class name being created
wcex.hIconSm = 0; // the handle to the small icon
RegisterClassEx(&wcex);

// Create the window
wndHandle = CreateWindow(
"DirectXExample", // the window class to use
"DirectXExample", // the title bar text
WS_OVERLAPPEDWINDOW, //the window style
CW_USEDEFAULT, // the starting x coordinate
CW_USEDEFAULT, // the starting y coordinate
640, // the pixel width of the window
480, // the pixel height of the window
NULL, // the parent window; NULL for desktop
NULL, // the menu for the application; NULL for none
hInstance, // the handle to the application instance
NULL); // no values passed to the window
// Make sure that the window handle that is created is valid
if (!wndHandle)
return false;

// Display the window on the screen
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}



/******************************************************************************
* LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
* LPARAM lParam)
* The window procedure
******************************************************************************/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// Check any available messages from the queue
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
// Always return the message to the default window
// procedure for further processing
return DefWindowProc(hWnd, message, wParam, lParam);
}


en hier is de foutmelding:
1>------ Build started: Project: example1, Configuration: Debug Win32 ------
1>Compiling...
1>winmain.cpp
1>c:\program files\microsoft visual studio 8\user files\projects\example1\example1\winmain.cpp(52) : error C2440: '=' : cannot convert from 'const char [15]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\program files\microsoft visual studio 8\user files\projects\example1\example1\winmain.cpp(68) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [15]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\Program Files\Microsoft Visual Studio 8\User Files\Projects\example1\example1\Debug\BuildLog.htm"
1>example1 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

kan iemand die hier ervaring mee heeft me mee helpen? thx.

killgore

Legacy Member
LPCWSTR is unicode (wchar_t), ma ge zult nog steeds implicit moeten casten aangezien winapi met short werkt.

IceSkull[BE]

Legacy Member
euhm... ben net me DirectX begonnen, ma moet ik nu iets gaan wijzigen?

killgore

Legacy Member
IceSkull[BE] zei:
euhm... ben net me DirectX begonnen, ma moet ik nu iets gaan wijzigen?
ah, zie et al

ipv gewoon "string" te gebruiken:
TEXT("string")

zou geen fouten mogen geven.
dit is trouwens winapi en geen directx :p

IceSkull[BE]

Legacy Member
ah kweeni, tis nen boek van Course PTR.. en er staat vanboven:
Chapter 2 :: Your first DirectX Program

don't blaim me :p
Het archief is een bevroren moment uit een vorige versie van dit forum, met andere regels en andere bazen. Deze posts weerspiegelen op geen enkele manier onze huidige ideeën, waarden of wereldbeelden en zijn op sommige plaatsen gecensureerd wegens ontoelaatbaar. Veel zijn in een andere tijdsgeest gemaakt, al dan niet ironisch - zoals in het ironische subforum Off-Topic - en zouden op dit moment niet meer gepost (mogen) worden. Toch bieden we dit archief nog graag aan als informatiedatabank en naslagwerk. Lees er hier meer over of start een gesprek met anderen.
Terug
Bovenaan