c++ - Windows function ChoosePixelFormat returns ERR_OLD_WIN_VERSION on windows 7 -
i'm trying teach myself win32 api making window , attaching opengl context it. in order fetch appropriate pixel format call choosepixelformat must made should return pixel format system supports , best meets needs. when check errors goes smoothly until function called stops execution , logs error 1150-err_old_win_version supposed mean version of windows not support function. not case , msdn confirms function runs on versions of windows since windows 2000. right i'm running windows 7 x64 on desktop , made sure video driver , os updated. lots of people seem have had trouble pixel format functions have not found problem decided post here help. here full code; have not tested on machines other own.
winmain.cpp (the non-default msvc lib linked opengl32.lib)
#include"display.h" #include<iostream> #include<fstream> msg message; dword error; int status; lresult callback wndproc(hwnd hwindow, uint message, wparam wparam, lparam lparam) { switch(message) {case wm_create: return 0; case wm_destroy: postquitmessage(0); return 0; case wm_keydown: switch(wparam) {case vk_escape: postquitmessage(0); return 0;}} return defwindowproc(hwindow, message, wparam, lparam);} int mainloop(display d) { while((status = peekmessage(&message, d.hwindow, 0, 0, pm_remove)) != 0) { if (status == -1) { return -1; } dispatchmessage(&message); } return 0; } int callback winmain(hinstance hinstance, hinstance hprevinstance, lpstr lpcmdline, int ncmdshow) { std::ofstream file("log.txt", std::ios::trunc); display window("test", hinstance, wndproc, 50, 50, 50, 50, null, null); if(window.status == -1) { error = getlasterror(); file << error; return 1;} showwindow(window.hwindow, sw_shownormal); enablewindow(window.hwindow, true); mainloop(window); return 0; }
display.h (problem occurs in class constructor)
#include <windows.h> class display {public: display(const char*, hinstance, wndproc, int, int, int, int, dword, dword); ~display(); hwnd hwindow; int status; private: wndclassex data; hdc hdevicecontext; hglrc hglcontext; pixelformatdescriptor pfd; int x, y, width, height;}; display::display(const char* title, hinstance instancehandle, wndproc windowprocedure, int screenpositionx, int screenpositiony, int windowwidth, int windowheight, dword styleflags, dword extendedstyleflags) { data.cbsize = sizeof(wndclassex); data.style = cs_owndc; data.lpfnwndproc = windowprocedure; data.cbclsextra = 0; data.cbwndextra = 0; data.hinstance = instancehandle; data.hicon = null; data.hcursor = null; data.hbrbackground = null; data.lpszmenuname = null; data.lpszclassname = "win1"; data.hiconsm = null; registerclassex(&data); hwindow = createwindowex(extendedstyleflags, data.lpszclassname, title, styleflags | ws_clipsiblings | ws_clipchildren, x = screenpositionx, y = screenpositiony, width = windowwidth, height = windowheight, null, null, instancehandle, null); pfd.nsize = sizeof(pixelformatdescriptor); pfd.nversion = 1; pfd.ipixeltype = pfd_type_rgba; pfd.ilayertype = pfd_main_plane; pfd.dwvisiblemask = 0; pfd.dwlayermask = 0; pfd.dwdamagemask = 0; pfd.dwflags = pfd_draw_to_window | pfd_doublebuffer | pfd_support_opengl; pfd.cauxbuffers = 0; pfd.breserved = 0; pfd.ccolorbits = 24; pfd.caccumbits = 0; pfd.cdepthbits = 32; pfd.cstencilbits = 0; pfd.calphabits = 0; pfd.caccumalphabits = 0; pfd.calphashift = 0; pfd.cbluebits = 0; pfd.caccumbluebits = 0; pfd.cblueshift = 0; pfd.cgreenbits = 0; pfd.caccumgreenbits = 0; pfd.cgreenshift = 0; pfd.credbits = 0; pfd.caccumredbits = 0; pfd.credshift = 0; hdevicecontext = getdc(hwindow); int pf = choosepixelformat(hdevicecontext, &pfd); //throws error 1150, next 3 throw error 2000 because of failing setpixelformat(hdevicecontext, pf, &pfd); hglcontext = wglcreatecontext(hdevicecontext); wglmakecurrent(hdevicecontext, hglcontext); if(getlasterror() != error_success) {status = -1;} else {status = 0;} return;} display::~display() { wglmakecurrent(null, null); wgldeletecontext(hglcontext); destroywindow(hwindow); unregisterclass(data.lpszclassname, data.hinstance);}
after have tried mentioned solutions still had same problem err_old_win_version after choosepixelformat. in case problem graphics card driver:
the system i'm working on uses evga card gtx 770 gpu , yesterday installed driver version 331.65. after got same problems questioner. installing current version 337.88 fixed issue in case. err_old_win_version seams lead in wrong direction.
Comments
Post a Comment