Results 1 to 6 of 6

Thread: How to handle the changing of resolution under windows?

  1. #1
    Member Contributor
    Join Date
    Jun 2003
    Location
    Hamilton,On,Canada
    Posts
    55

    How to handle the changing of resolution under windows?

    Hi! I wrote a program with Delphi under windows, and put some error checking routine in it.

    If I run the program, then change the resolution of windows desktop. The error message pops up.

    Is there any mechanism to handle this?

    Thank you!

  2. #2
    Member Contributor
    Join Date
    Jul 2003
    Location
    va beach
    Posts
    63

    Re: How to handle the changing of resolution under windows?

    Not sure if this helps but here you go. I would add some code that changes the users settings then resets after the program is terminated. It would take care of that error message, and allow your program to run without error.

  3. #3
    Member Contributor
    Join Date
    Jun 2003
    Location
    Hamilton,On,Canada
    Posts
    55

    Re: How to handle the changing of resolution under windows?

    Sorry, I don't quite understand.

    After running the program, if I right click on desktop and use "desktop property" to change the resolution from 800*600 to 1024*768, then error message will pop up.

    Following is a simple program with this problem. Can you tell me what to do with it?

    Thank you!

    Code :
    unit First1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,OpenGL;
     
    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure FormPaint(Sender: TObject);
      private
        GLContext: HGLRC;
        glDC: HDC;
        errorCode: GLenum;
        openGLReady: boolean;
      public
        { Public declarations }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.DFM}
     
    procedure TForm1.FormCreate(Sender: TObject); 
    var
      pfd: TPixelFormatDescriptor;
      FormatIndex: integer;
    begin
      fillchar(pfd,SizeOf(pfd),0);
      with pfd do
      begin
        nSize      := SizeOf(pfd);
        nVersion   := 1; {The current version of the desccriptor is 1}
        dwFlags    := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
        iPixelType := PFD_TYPE_RGBA;
        cColorBits := 24; {support 24-bit color}
        cDepthBits := 32; {depth of z-axis}
        iLayerType := PFD_MAIN_PLANE;
      end; {with}
      glDC := getDC(handle);
      FormatIndex := ChoosePixelFormat(glDC,@pfd);
      if FormatIndex=0 then
        raise Exception.Create('ChoosePixelFormat failed '+
          IntToStr(GetLastError)); 
     
      if not SetPixelFormat(glDC,FormatIndex,@pfd) then
        raise Exception.Create('SetPixelFormat failed '+
          IntToStr(GetLastError));
     
      GLContext := wglCreateContext(glDC);
      if GLContext=0 then
        raise Exception.Create('wglCreateContext failed '+
          IntToStr(GetLastError)); 
     
      if not wglMakeCurrent(glDC,GLContext) then
        raise Exception.Create('wglMakeCurrent failed '+
          IntToStr(GetLastError));
     
      OpenGLReady := true;
    end; {FormCreate}
     
    procedure TForm1.FormDestroy(Sender: TObject);
    begin
      OpenGLReady := false;
      wglMakeCurrent(glDC,0);
      wglDeleteContext(GLContext);
    end;
     
    procedure TForm1.FormPaint(Sender: TObject);
    begin 
      if not openGLReady then
        exit;
      {background}
      glClearColor(0.0,0.4,0.0,0.0);
      glClear(GL_COLOR_BUFFER_BIT);
     
      {error checking} 
      errorCode := glGetError;
      if errorCode<>GL_NO_ERROR then
        raise Exception.Create('Error in Paint'#13+
          gluErrorString(errorCode));
    end;
     
    end.

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

    Re: How to handle the changing of resolution under windows?

    I never heard of a program that is able to track and still run when the user changes the visual properties.

    however, you can eliminate the error message from popping up by not checking it . If your program still draws what it is supposed to, I guess it's fine. Otherwise, I guess you must restart your program with a new rc, as the user could also change the color depth etc.

    Jan

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Aug 2001
    Location
    Italy
    Posts
    625

    Re: How to handle the changing of resolution under windows?

    I don't know delphi, but changing resolution usually destroys every openGL context so, I feel this is correct.

    Users should not mess up their pc while playing.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Feb 2002
    Location
    Hamburg, Germany
    Posts
    413

    Re: How to handle the changing of resolution under windows?

    Originally posted by Obli:
    I don't know delphi, but changing resolution usually destroys every openGL context so, I feel this is correct.

    Users should not mess up their pc while playing.
    a well written application should handle such cases. if your app does not support a feature that the OS provides (ie.resoultion change during programm execution) then you have to make sure, that the user can't mess up with this feature. it is very easy to say "the user shouldn't do this anyway", but actually its your fault, when your application crashes in such cases. Because you are the one who ignores the application-specs for win32-applications, not the user.
    most comecial games are able to handle this. one method is to track the WM_SETFOCUS and WM_KILLFOCUS messages and to delete the gl context everytime the app loses focus and recreate the context when it gets the focus back. or simply block this messages, so apps can't lose their focus at all.
    some apps switch even form fullscreen-res to destop-res back when they lose their focus.

    ofcourse it's also a good idea not to ingnore the WM_DISPLAYCHANGE message, which is send everytime the resolution has changed(just guess why this message exists..).

Similar Threads

  1. Changing resolution
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-28-2006, 10:08 AM
  2. Changing Resolution
    By Andrew Jameson in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-30-2003, 10:21 AM
  3. changing screen resolution
    By Julien Cayzac in forum OpenGL: Linux
    Replies: 0
    Last Post: 12-09-2001, 04:00 AM
  4. Changing resolution
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-08-2000, 09:01 AM
  5. Changing resolution
    By David in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-11-2000, 11:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean