#define WIN32_LEAN_AND_MEAN
#include <ddraw.h>
#include <windows.h>
#include "dxutil.h"
#include "ddutil.h"
#include "stdafx.h"
#include "blarg.h"
#define MAX_LOADSTRING 100
// Global Variables:
bool g_bActive = false;
CDisplay *g_pDisplay = NULL;
CSurface *g_pText = NULL;
//function prototypes
bool InitDD(HWND);
void CleanUp();
void GameLoop();
HINSTANCE hInst;
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_BLARG);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCTSTR)IDC_BLARG;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CREATE:
InitDD(hWnd);
g_bActive=true;
break;
case WM_CLOSE:
g_bActive=false;
CleanUp();
DestroyWindow(hWnd);
break;
case WM_MOVE:
g_pDisplay->UpdateBounds();
break;
case WM_SIZE:
g_pDisplay->UpdateBounds();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
bool InitDD(HWND hWnd)
{
//dd init code
g_pDisplay = new CDisplay();
if(FAILED(g_pDisplay->CreateWindowedDisplay(hWnd,640,480)))
{
MessageBox(NULL,"Failed to Initialize DirectDraw",
"DirectDraw Initialization Failure",MB_OK|MB_ICONERROR);
return false;
}
return true;
}
void CleanUp()
{
SAFE_DELETE(g_pDisplay);
}
void MainLoop()
{
g_pDisplay->CreateSurfaceFromText(&g_pText,NULL,"DDraw using Common Files",
RGB(0,0,0),RGB(0,255,0));
g_pDisplay->Clear(0);
g_pDisplay->Blt(0,0,g_pText,0);
g_pDisplay->Present();
g_pText->Destroy();
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int iShowCmd)
{
WNDCLASSEX wc;
HWND hWnd;
MSG lpMsg;
wc.cbClsExtra=0;
wc.cbSize=sizeof(WNDCLASSEX);
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.lpszClassName="wc";
wc.lpszMenuName=0;
wc.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClassEx(&wc))
{
MessageBox(NULL,"Couldn't Register Window Class",
"Window Class Registration Failure",MB_OK|MB_ICONERROR);
return 0;
}
hWnd = CreateWindowEx(NULL,"wc","DirectDraw Common Files in Action",
WS_POPUPWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,640,480,0,0,
hInstance,0);
if(hWnd == NULL)
{
MessageBox(NULL,"Failed to Create Window","Window Creation Failure",
MB_OK|MB_ICONERROR);
return 0;
}
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
while(lpMsg.message != WM_QUIT)
{
if(PeekMessage(&lpMsg,0,0,0,PM_REMOVE))
{
TranslateMessage(&lpMsg);
DispatchMessage(&lpMsg);
}
else if(g_bActive)
{
MainLoop();
}
}
return lpMsg.wParam;
}
damn linker error
I get this error whenever I try to compile my win32 project
dxutil.obj : error LNK2019: unresolved external symbol __imp__timeGetTime@0 referenced in function "float __stdcall DXUtil_Timer(enum TIMER_COMMAND)" (?DXUtil_Timer@@YGMW4TIMER_COMMAND@@@Z)
here is the code I used. I include ddutil.h, ddutil.cpp, dxutil.h, and dxutil.cpp. I also linked ddraw.lib and dxguid.lib ro my project:
I can't see what's wrong with it. I include every file and library needed to use to dxutility functions. if you can point out my error, I owuld most appreciative.
I have one more error. it's a run-time though:
Run-Time Check #3 - the variable 'lpMsg' is being used without being defined.
I set it up right inside the Winmain function and only use it inside the Winmain function. Do I need to set it to NULL when I declare it?
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int iShowCmd)
{
WNDCLASSEX wc;
HWND hWnd;
MSG lpMsg;
wc.cbClsExtra=0;
wc.cbSize=sizeof(WNDCLASSEX);
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.lpszClassName="wc";
wc.lpszMenuName=0;
wc.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClassEx(&wc))
{
MessageBox(NULL,"Couldn't Register Window Class",
"Window Class Registration Failure",MB_OK|MB_ICONERROR);
return 0;
}
hWnd = CreateWindowEx(NULL,"wc","DirectDraw Common Files in Action",
WS_POPUPWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,640,480,0,0,
hInstance,0);
if(hWnd == NULL)
{
MessageBox(NULL,"Failed to Create Window","Window Creation Failure",
MB_OK|MB_ICONERROR);
return 0;
}
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
while(lpMsg.message != WM_QUIT)
{
if(PeekMessage(&lpMsg,0,0,0,PM_REMOVE))
{
TranslateMessage(&lpMsg);
DispatchMessage(&lpMsg);
}
else if(g_bActive)
{
MainLoop();
}
}
return lpMsg.wParam;
}
Run-Time Check #3 - the variable 'lpMsg' is being used without being defined.
I set it up right inside the Winmain function and only use it inside the Winmain function. Do I need to set it to NULL when I declare it?
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int iShowCmd)
{
WNDCLASSEX wc;
HWND hWnd;
MSG lpMsg;
wc.cbClsExtra=0;
wc.cbSize=sizeof(WNDCLASSEX);
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.lpszClassName="wc";
wc.lpszMenuName=0;
wc.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClassEx(&wc))
{
MessageBox(NULL,"Couldn't Register Window Class",
"Window Class Registration Failure",MB_OK|MB_ICONERROR);
return 0;
}
hWnd = CreateWindowEx(NULL,"wc","DirectDraw Common Files in Action",
WS_POPUPWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,640,480,0,0,
hInstance,0);
if(hWnd == NULL)
{
MessageBox(NULL,"Failed to Create Window","Window Creation Failure",
MB_OK|MB_ICONERROR);
return 0;
}
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
while(lpMsg.message != WM_QUIT)
{
if(PeekMessage(&lpMsg,0,0,0,PM_REMOVE))
{
TranslateMessage(&lpMsg);
DispatchMessage(&lpMsg);
}
else if(g_bActive)
{
MainLoop();
}
}
return lpMsg.wParam;
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement