Easiest way to put this: My code is throwing an access violation error whenever I run it. I have concluded it is the fault of calling this->d3ddev.(whatever) inside of the function System::renderFrame(). This function starts on line 112. If anyone could help me out here, that'd be great.
(by the way, I've gotten this working, but I wanted to put this code into classes, and that's where I started having my troubles. Also, I was told before to make sure to initialize all pointers. They are initialized, through d3d->createDevice())
system.h
#ifndef SYSTEM_H
#define SYSTEM_H
#include "stdinc.h"
class System {
private:
void initD3D (void);
void cleanD3D (void);
void setUpHWND (HINSTANCE, LPSTR, int);
static LRESULT CALLBACK StaticWindowProc(HWND, UINT, WPARAM, LPARAM);
LRESULT WindowProc(HWND, UINT, WPARAM, LPARAM);
HWND window;
WNDCLASSEX windowClass;
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
D3DPRESENT_PARAMETERS d3dpp;
HINSTANCE hInstance;
LPSTR lpCmdLine;
int nCmdShow;
public:
System (void);
System (HINSTANCE, LPSTR, int);
System (const System&);
~System (void);
void renderFrame (void);
};
#endif
system.cpp
#include "system.h"
//////////////////////////////////////////////////
// Class: System
// Private
//////////////////////////////////////////////////
void System::initD3D (void) {
this->d3d = Direct3DCreate9(D3D_SDK_VERSION);
ZeroMemory(&(this->d3dpp), sizeof(d3dpp));
this->d3dpp.Windowed = WINDOWED;
this->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
this->d3dpp.hDeviceWindow = this->window;
this->d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
this->d3dpp.BackBufferWidth = SCREEN_WIDTH;
this->d3dpp.BackBufferHeight = SCREEN_HEIGHT;
this->d3dpp.EnableAutoDepthStencil = TRUE;
this->d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
this->d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
this->window,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&(this->d3dpp),
&(this->d3ddev));
this->d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
this->d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
this->d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);
};
void System::cleanD3D (void) {
this->d3d->Release();
this->d3ddev->Release();
};
void System::setUpHWND (
HINSTANCE hInstance,
LPSTR lpCmdLine,
int nCmdShow) {
this->hInstance = hInstance;
this->lpCmdLine = lpCmdLine;
this->nCmdShow = nCmdShow;
ZeroMemory(&(this->windowClass), sizeof(WNDCLASSEX));
this->windowClass.cbSize = sizeof(WNDCLASSEX);
this->windowClass.style = CS_HREDRAW | CS_VREDRAW;
this->windowClass.lpfnWndProc = System::StaticWindowProc;
this->windowClass.hInstance = this->hInstance;
this->windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
this->windowClass.lpszClassName = "WindowClass";
RegisterClassEx(&(this->windowClass));
this->window = CreateWindowEx(NULL, "WindowClass", "The Direct3D Program",
WS_OVERLAPPEDWINDOW, SCREEN_X, SCREEN_Y, SCREEN_WIDTH, SCREEN_HEIGHT,
NULL, NULL, this->hInstance, NULL);
};
LRESULT CALLBACK System::StaticWindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
System *SystemPtr = (System*)GetWindowLong(hWnd, GWLP_USERDATA);
if(SystemPtr)
{
return SystemPtr->WindowProc(hWnd, message, wParam, lParam);
}
else
{
return DefWindowProc(hWnd, message, wParam, lParam);
}
};
LRESULT System::WindowProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
};
//////////////////////////////////////////////////
// Class: System
// Public
//////////////////////////////////////////////////
System::System (void) {
};
System::System (
HINSTANCE hInstance,
LPSTR lpCmdLine,
int nCmdShow) {
this->setUpHWND(hInstance, lpCmdLine, nCmdShow);
ShowWindow(this->window, this->nCmdShow);
this->initD3D();
};
System::System (const System &) {
};
System::~System (void) {
this->cleanD3D();
};
void System::renderFrame (void) {
// Update the camera here
// Update objects
// Clear objects
// FOR SOME REASON THERE IS AN ERROR HERE
this->d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 255, 0), 1.0f, 0);
this->d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
this->d3ddev->BeginScene();
// Draw objects
// Finish up
this->d3ddev->EndScene();
this->d3ddev->Present(NULL, NULL, NULL, NULL);
};
main.cpp
#include "system.h"
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
System MainSys;
MainSys = System(hInstance, lpCmdLine, nCmdShow);
// Enter the main loop
MSG msg;
while (TRUE)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (msg.message == WM_QUIT)
break;
MainSys.renderFrame();
}
// Clean up DirectX and the COM
//delete MainSys;
return msg.wParam;
};
I tried to compile your code and changed the following lines:
System MainSys;
MainSys = System(hInstance, lpCmdLine, nCmdShow);
into
System MainSys(hInstance, lpCmdLine, nCmdShow);
and it worked.
I admit I don't know exactly why it fails, but there's a lot of stuff in your System class and you are constructing two instances of it (once in both lines) and then assign one to the other. This is not a good idea in any case and unnecessary. I guess it has somethinig to do with Direct3D reference counting and you are not honoring it when the class gets copied to MainSys in the second line.
EDIT
I just noticed that the destructor of MainSys gets called after the class is constructed with System(hInstance, lpCmdLine, nCmdShow); So the just obtained device is Released() again.
I don't see anything imeediately wrong here but its easy to miss something.
I suggest checking the HRESULTS from every d3d api call to make sure something didn't fail, and assing assert(pointer != NULL) all over to try to catch the problem. Or step through with a debugger and look at the variables to determine when it starts to fail.
Also, if you've not done so, turn on the d3d9 debug version and look at the log. It often tells you what you've missed.
Related
In main.cpp:
#include "window.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
Window main_window(hInstance, nCmdShow);
main_window.Intitialize(CS_HREDRAW, NULL, LoadCursor(NULL, IDC_ARROW), (HBRUSH)(COLOR_WINDOW), (WIDE_CHAR) "Application", (WIDE_CHAR) "WindowName");
return main_window.Show();
}
In window.h:
#include <stdio.h>
#ifndef _WINDOW_H_
#define _WINDOW_H_
#include <windows.h>
typedef wchar_t* WIDE_CHAR;
typedef HINSTANCE INSTANCE;
typedef HWND HANDLE_WINDOW;
typedef tagWNDCLASSEXW WINDOW_CLASS;
LRESULT Procedure(HANDLE_WINDOW, UINT, WPARAM, LPARAM);
class Window {
private:
INSTANCE instance;
int show_command;
WINDOW_CLASS window_object;
HANDLE_WINDOW handle;
public:
Window(INSTANCE instance, int show_command) {
this->instance = instance;
this->show_command = show_command;
}
void Intitialize(UINT style, HICON icon, HCURSOR cursor, HBRUSH background, WIDE_CHAR class_name, WIDE_CHAR title) {
window_object.cbSize = sizeof(WINDOW_CLASS);
window_object.cbClsExtra = 0;
window_object.cbWndExtra = 0;
window_object.hInstance = instance;
window_object.lpfnWndProc = Procedure;
window_object.style = style;
window_object.hIcon = icon;
window_object.hCursor = cursor;
window_object.hbrBackground = background;
window_object.lpszMenuName = NULL;
window_object.lpszClassName = class_name;
window_object.hIconSm = NULL;
RegisterClassExW(&window_object);
printf("%lld", GetLastError());
handle = CreateWindowExW(WS_EX_CLIENTEDGE, class_name, title, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1080, 720, NULL, NULL, instance, NULL);
}
int Show() {
ShowWindow(handle, show_command);
UpdateWindow(handle);
MSG message;
while (GetMessageW(&message, NULL, 0, 0)) {
TranslateMessage(&message);
DispatchMessageW(&message);
}
return message.wParam;
}
};
LRESULT Procedure(HANDLE_WINDOW handle, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_CLOSE:
DestroyWindow(handle);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(handle, message, wParam, lParam);
break;
}
return 0;
}
#endif
I tried to wrap the Win32 interface and tried to make a window, but I always got stuck in some weird places, like the Unicode...
First of all, I can't fully understand the use and conversion of wide characters. I think a large part of the reason for the failure of window registration and window creation is in the use of wide and normal characters.
Secondly, I don't understand why I can't use the namespace "std", once I use it, even window registration fails.
You are passing (WIDE_CHAR) "Application" and (WIDE_CHAR) "WindowName" to Intitialize.
As you defined
typedef wchar_t* WIDE_CHAR;
the parameters are NARROW characters cast to WIDE characters. When CreateWindowExW tries to access them, it goes out-of-bounds (because wide string is twice as long as narrow), resulting in error:
ERROR_NOACCESS
998 (0x3E6)
Invalid access to memory location.
according to https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--500-999-
Do this instead:
main_window.Intitialize(CS_HREDRAW, NULL, LoadCursor(NULL, IDC_ARROW),
(HBRUSH)(COLOR_WINDOW), L"Application", L "WindowName");
I'm new to GDI+ and I've no idea what the problem is so I'll just post all of the code. I'm trying to simply draw an image but in my debugger I can see that graphics which I try to use in WM_PAINT is NULL. I've seen many people do pretty much the exact same thing which I'm trying to do so I'm pretty confused as to what's going on.
#include "stdafx.h"
#include "GUI.h"
#include <objidl.h>
#include <gdiplus.h>
#include <iostream>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// Initialize global strings
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadStringW(hInstance, IDC_GUI, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_GUI));
MSG msg;
// Main message loop:
while (GetMessage(&msg, nullptr, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_GUI));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_GUI);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassExW(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hInst = hInstance; // Store instance handle in our global variable
HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
break;
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
Graphics graphics(hdc);
Image image(L"C:\\light.png");
graphics.DrawImage(&image, 0, 0);
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
You are missing the calls to GdiplusStartup() and GdiplusShutdown().
From the reference of GdiplusStartup:
You must call GdiplusStartup before you create any GDI+ objects, and
you must delete all of your GDI+ objects (or have them go out of
scope) before you call GdiplusShutdown.
... and from GdiplusShutdown:
The GdiplusShutdown function cleans up resources used by Windows GDI+.
Each call to GdiplusStartup should be paired with a call to
GdiplusShutdown.
I'm using a RAII class like this to simplify the task:
class GdiPlusInit
{
public:
GdiPlusInit()
{
Gdiplus::GdiplusStartupInput startupInput;
Gdiplus::GdiplusStartup( &m_token, &startupInput, NULL );
// NOTE: For brevity I omitted error handling, check function return value!
}
~GdiPlusInit()
{
if( m_token )
Gdiplus::GdiplusShutdown( m_token );
}
// Class is non-copyable.
GdiPlusInit( const GdiPlusInit& ) = delete;
GdiPlusInit& operator=( const GdiPlusInit& ) = delete;
private:
ULONG_PTR m_token = 0;
};
Usage:
Create an instance of the class at the beginning of the scope where you want to use GDI+ functions (for performance reasons I wouldn't do that in a function that is called frequently). I usually create it as member variable of window classes or other classes that use GDI+ so clients of my code don't need to be told to initialize GDI+. It doesn't matter if clients already call GdiplusStartup() and GdiplusShutdown() on their own, because the calls can be nested, if they are properly paired.
In your case:
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
GdiPlusInit gdiplus; // calls GdiplusStartup() and stores the returned token
// ... remaining code of your application ...
// When the scope ends, the destructor of GdiPlusInit calls GdiplusShutdown(),
// passing the stored token.
}
I am looking for a method of placing a DXLinked window within a windowproc as a child window. This would allow for menus/Forms controls to be externally managed before input to the DX methods.
So far I have attempted to create two WNDCLASSEX and two HWND types, and ran both windowprocs in the main loop. This unfortunately doesn't seem to work.
A screen shot example of what I wish to accomplish.
http://clip2net.com/s/3jXUG2l - a well known modding tool that is used for Lua and C++ code attachments for objects.
Appreciate any feedback.
Relevant code I am currently using as a prototype:
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#pragma comment (lib, "d3d9.lib")
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;
void initD3D(HWND hWnd);
void render_frame(void);
void cleanD3D(void);
void init_graphics(void); // 3D declarations
struct CUSTOMVERTEX { FLOAT X, Y, Z, RHW; DWORD COLOR; };
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
//Main
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = L"WindowClass";
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL,
L"WindowClass",
L"DirectX Test",
WS_OVERLAPPEDWINDOW,
300, 300,
800, 600,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
initD3D(hWnd);
MSG msg;
while (TRUE)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if (msg.message == WM_QUIT)
break;
render_frame();
}
// clean up DirectX and COM
cleanD3D();
return msg.wParam;
}
// t
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
Sorry for the confusion, I made some incorrect assumptions.
Appreciate the feedback however.
I am following the MSDN tutorial for setting up a basic Windows application with C++, and it is not compiling properly in Code::Blocks. Similar questions have been asked here before, but I was unable to find any with a solution and I am able to provide a detail that I did not see any others providing.
For now I was able to get it working by converting their wWinMain function to WinMain, but I would like to know what is going on since my understanding is that WinMain is intended for 16-bit operating systems.
Their Code:
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
Working Code:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR pCmdLine, int nCmdShow)
And The Full Sample Code:
ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
L"Learn to Program Windows", // Window text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
);
if (hwnd == NULL)
{
return 0;
}
ShowWindow(hwnd, nCmdShow);
// Run the message loop.
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));
EndPaint(hwnd, &ps);
}
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
Tutorial URL: http://msdn.microsoft.com/en-us/library/windows/desktop/ff381409(v=vs.85).aspx
Thanks in advance for any assistance you can offer!
okay, so I have taken out the time to learn a but of the Win32 API to do with opening windows, and the code I came up with in the end I would think would work, but doesn't. I registered the window class, made all the things I have to, but when I run it, nothing happens... It would be a great help if someone could point out what I am doing wrong/missing.
#include <stdlib.h>
#include <iostream>
#include <Windows.h>
#pragma comment (lib, "wsock32.lib")
#define WNDCLASSNAME "wndclass"
bool quit = false;
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd)
{
WNDCLASSEX WCE;
WCE.cbSize = sizeof(WNDCLASSEX);
WCE.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC|CS_DBLCLKS;
WCE.lpfnWndProc = WndProc;
WCE.cbClsExtra = 0;
WCE.cbWndExtra = 0;
WCE.hInstance = hinstance;
WCE.hIcon = NULL;//LoadImage()
WCE.hCursor = NULL;//LoadCursor(NULL, IDC_CROSS);
WCE.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
WCE.lpszMenuName = NULL;
WCE.lpszClassName = "KyleWindow";
WCE.hIconSm = NULL;
RegisterClassEx(&WCE);
HWND WindowHandle;
WindowHandle = CreateWindowEx(WS_OVERLAPPEDWINDOW, "KyleWindow", "Xerus", WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, NULL, NULL, hinstance, NULL);
ShowWindow(WindowHandle, SW_SHOWNORMAL);
UpdateWindow(WindowHandle);
std::cout<<"'Opened' Window"<<std::endl;
MSG msg;
while(!quit)
{
if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
{
if(msg.message == WM_QUIT)
quit = true;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.lParam;
}
Use WS_EX_OVERLAPPEDWINDOW as the first parameter of your CreateWindowEx function (instead of WS_OVERLAPPEDWINDOW, which is not a valid extended window style).
instead of using WNDCLASSEX use WNDCLASS
change:
WNDCLASSEX WCE; to WNDCLASS WCE;
remove line:
WCE.cbSize = sizeof(WNDCLASSEX);
change:
RegisterClassEx(&WCE); to RegisterClass(&WCE);
The function int WINAPI WinMain must be before function LRESULT CALLBACK WndProc. Compilers read in order.