Zmiana rozdzielczości innej aplikacji

0

Witam,

przeszukalem forum i faq ale odpowiedzi na moj problem znaleŹĆ nie moge...

chodzi mi dokladnie o to bym mogl zmienic rozdzielczosc (wymiary) okna ktorego mam uchwyt.
program uruchamia sie w trybie pelno ekranowym w rozdzielczosci 1024x768 ale chce wymusic na nim zeby zmienil rozdzielczosc na 800x600. jak to zrobic? przy czym nie chce zmieniac rodzielczosci pulpitu.

0

A może zmienić w owym programie ustawienia, aby się uruchamiał w określonej rozdzielczości? Pewnie ma opcje zmiany ekranu.

0

no wlasnie w tym problem ze nie ma, uruchamia sie w trybie pelno ekranowym, i koniec... nie moge w zaden sposob zmienic rozdzielczosci wiec dlatego chcialem zrobic takie wymuszenie :P program dziala pod DXem

0

Można spróbować edycji zasobów programu. Jest do dego prosty programik ExeScope. Możesz założyć, że autor programu zadeklarował zmienną typu Boolean o nazwie FullScreen lub podobnej. Zmień wówczas FullScreen = False.

0

Poniżej zamiszczam kod napisany w API. Zobaczysz tam jak przystosowany jest kod do obsługi FullScreen. Chwilowo nic więcej nie mogę pomóc. Sorry.

PROGRAM GlDemo;

USES
  Windows, Messages, Variants, OpenGl, Texture, Code;

CONST
 WND_TITLE   = 'OpenGL Window';
 SC_WIDTH    = 800;
 SC_HEIGHT   = 600;
 FULLSCREEN  = FALSE;
 COLOR_DEPTH = 32;

  // Settings FOR the OpenGL window
  pfd : TPIXELFORMATDESCRIPTOR = (
    nSize:            SizeOf(TPIXELFORMATDESCRIPTOR); // Size OF This Pixel Format Descriptor
    nVersion:         1;                    // The version OF this data structure
    dwFlags:          PFD_DRAW_TO_WINDOW    // Buffer supports drawing TO window
                      OR PFD_SUPPORT_OPENGL // Buffer supports OpenGL drawing
                      OR PFD_DOUBLEBUFFER;  // Supports double buffering
    iPixelType:       PFD_TYPE_RGBA;        // RGBA color format
    cColorBits:       16;                   // OpenGL color depth
    cRedBits:         0;                    // Number OF red bitplanes
    cRedShift:        0;                    // Shift count FOR red bitplanes
    cGreenBits:       0;                    // Number OF green bitplanes
    cGreenShift:      0;                    // Shift count FOR green bitplanes
    cBlueBits:        0;                    // Number OF blue bitplanes
    cBlueShift:       0;                    // Shift count FOR blue bitplanes
    cAlphaBits:       0;                    // NOT supported
    cAlphaShift:      0;                    // NOT supported
    cAccumBits:       0;                    // No accumulation buffer
    cAccumRedBits:    0;                    // Number OF red bits IN a-buffer
    cAccumGreenBits:  0;                    // Number OF green bits IN a-buffer
    cAccumBlueBits:   0;                    // Number OF blue bits IN a-buffer
    cAccumAlphaBits:  0;                    // Number OF alpha bits IN a-buffer
    cDepthBits:       16;                   // Specifies the depth OF the depth buffer
    cStencilBits:     0;                    // Turn off stencil buffer
    cAuxBuffers:      0;                    // NOT supported
    iLayerType:       PFD_MAIN_PLANE;       // Ignored
    bReserved:        0;                    // Number OF overlay AND underlay planes
    dwLayerMask:      0;                    // Ignored
    dwVisibleMask:    0;                    // Transparent color OF underlay plane
    dwDamageMask:     0                     // Ignored
  );

VAR
  h_Wnd  : HWND;                     // Global window handle
  h_DC   : HDC;                      // Global device context
  h_RC   : HGLRC;                    // OpenGL rendering context
  keys   : ARRAY[0..255] OF Boolean; // Holds keystrokes


{$R *.RES}
{------------------------------------------------------------------}
{  Function to draw the actual scene                               }
{------------------------------------------------------------------}
PROCEDURE glDraw;
VAR x, y             : Integer;
    xf, xf2, yf, yf2 : glfloat;
BEGIN
  glClear(GL_COLOR_BUFFER_BIT OR GL_DEPTH_BUFFER_BIT);    // Clear The Screen AND The Depth Buffer
  glLoadIdentity();                                       // Reset The View
  DrawScene();
END;
{------------------------------------------------------------------}
{  Initialise OpenGL                                               }
{------------------------------------------------------------------}
PROCEDURE glInit;
BEGIN
  glClearColor(0.0, 0.0, 0.0, 0.0); //czarne tlo
  glShadeModel(GL_SMOOTH);          //cieniowanie plaskie
  glClearDepth(1.0);                //bufor glebi
  glDepthFunc(GL_LESS);             //typ glebi
  glBlendFunc(GL_SRC_ALPHA,GL_ONE); //typ koloru przezroczystego
  // korekcja perspektywy
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  glColor4f(1.0,1.0,1.0,0.5);       // kolor przezroczysty
  glEnable(GL_BLEND);               // wlacz przezroczyste
//  glEnable(GL_DEPTH_TEST);          // wlacz tester glebi
  InitDemo();
END;

{------------------------------------------------------------------}
{  Handle window resize                                            }
{------------------------------------------------------------------}
PROCEDURE glResizeWnd(Width, Height : Integer);
VAR fAspect : GLfloat;
BEGIN
  IF (Height = 0) THEN                // prevent divide by zero exception
    Height := 1;
  glViewport(0, 0, Width, Height);    // SET the viewport FOR the OpenGL window
  fAspect := Width/Height;            // Calculate the aspect ratio OF the window
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0, fAspect, 1.0, 100.0);  // DO the perspective calculations. Last value = max clipping depth

  glMatrixMode(GL_MODELVIEW);         // Return TO the modelview matrix
  glLoadIdentity();
END;


{------------------------------------------------------------------}
{  Processes all the keystrokes                                    }
{------------------------------------------------------------------}
PROCEDURE ProcessKeys;
BEGIN
END;


{------------------------------------------------------------------}
{  Determines the application?s response to the messages received  }
{------------------------------------------------------------------}
FUNCTION WndProc(hWnd: HWND; Msg: UINT;  wParam: WPARAM;  lParam: LPARAM): LRESULT; STDCALL;
BEGIN
  CASE (Msg) OF
    WM_CREATE:
      BEGIN
        // Insert stuff you want executed when the PROGRAM starts
      END;
    WM_CLOSE:
      BEGIN
        PostQuitMessage(0);
        Result := 0
      END;
    WM_KEYDOWN:        // SET the pressed key (wparam) TO equal true so we can check IF its pressed
      BEGIN
        keys[wParam] := True;
        Result := 0;
      END;
    WM_KEYUP:         // SET the released key (wparam) TO equal false so we can check IF its pressed
      BEGIN
        keys[wParam] := False;
        Result := 0;
      END;
    WM_SIZE:          // Resize the window WITH the new width AND height
      BEGIN
        glResizeWnd(LOWORD(lParam),HIWORD(lParam));
        Result := 0;
      END;
    ELSE
    BEGIN
      Result := DefWindowProc(hWnd, Msg, wParam, lParam);
      Exit;
    END;
  END;
END;


{---------------------------------------------------------------------}
{  Properly destroys the window created at startup (no memory leaks)  }
{---------------------------------------------------------------------}
PROCEDURE glKillWnd(Fullscreen : Boolean);
BEGIN
  // Change back TO non fullscreen
  IF Fullscreen THEN
  BEGIN
    ChangeDisplaySettings(Tdevmode(NIL^), 0);
    ShowCursor(True);
  END;

  // Makes current rendering context NOT current, AND releases the device
  // context that IS used by the rendering context.
  IF (NOT wglMakeCurrent(h_DC, 0)) THEN
    MessageBox(0, 'Release of DC and RC failed!', 'Error', MB_OK OR MB_ICONERROR);

  // Attempts TO delete the rendering context
  IF (NOT wglDeleteContext(h_RC)) THEN
  BEGIN
    MessageBox(0, 'Release of rendering context failed!', 'Error', MB_OK OR MB_ICONERROR);
    h_RC := 0;
  END;

  // Attemps TO release the device context
  IF ((h_DC = 1) AND (ReleaseDC(h_Wnd, h_DC) <> 0)) THEN
  BEGIN
    MessageBox(0, 'Release of device context failed!', 'Error', MB_OK OR MB_ICONERROR);
    h_DC := 0;
  END;

  // Attempts TO destroy the window
  IF ((h_Wnd <> 0) AND (NOT DestroyWindow(h_Wnd))) THEN
  BEGIN
    MessageBox(0, 'Unable to destroy window!', 'Error', MB_OK OR MB_ICONERROR);
    h_Wnd := 0;
  END;

  // Attempts TO unregister the window CLASS
  IF (NOT UnRegisterClass('OpenGL', hInstance)) THEN
  BEGIN
    MessageBox(0, 'Unable to unregister window class!', 'Error', MB_OK OR MB_ICONERROR);
    hInstance := NULL;
  END;
END;


{--------------------------------------------------------------------}
{  Creates the window and attaches a OpenGL rendering context to it  }
{--------------------------------------------------------------------}
FUNCTION glCreateWnd(Width, Height : Integer; Fullscreen : Boolean) : Boolean;
VAR
  wndClass : TWndClass;       // Window CLASS
  dwStyle : DWORD;            // Window styles
  dwExStyle : DWORD;          // Extended window styles
  dmScreenSettings : TDEVMODE; // Screen settings (fullscreen, etc...)
  PixelFormat : GLuint;       // Settings FOR the OpenGL rendering
  h_Instance : HINST;         // Current instance
BEGIN
  h_Instance := GetModuleHandle(NIL);       //Grab An Instance FOR Our Window
  ZeroMemory(@wndClass, SizeOf(wndClass));  // Clear the window CLASS structure

  WITH wndClass DO                    // SET up the window CLASS
  BEGIN
    style         := CS_HREDRAW OR    // Redraws entire window IF length changes
                     CS_VREDRAW OR    // Redraws entire window IF height changes
                     CS_OWNDC;        // Unique device context FOR the window
    lpfnWndProc   := @WndProc;        // SET the window PROCEDURE TO our func WndProc
    hInstance     := h_Instance;
    hCursor       := LoadCursor(0, IDC_ARROW);
    lpszClassName := 'OpenGL';
  END;

  IF (RegisterClass(wndClass) = 0) THEN  // Attemp TO REGISTER the window CLASS
  BEGIN
    MessageBox(0, 'Failed to register the window class!', 'Error', MB_OK OR MB_ICONERROR);
    Result := False;
    Exit
  END;

  // Change TO fullscreen IF so desired
  IF Fullscreen THEN
  BEGIN
    ZeroMemory(@dmScreenSettings, SizeOf(dmScreenSettings));
    WITH dmScreenSettings DO BEGIN              // SET parameters FOR the screen setting
      dmSize       := SizeOf(dmScreenSettings);
      dmPelsWidth  := Width;                    // Window width
      dmPelsHeight := Height;                   // Window height
      dmBitsPerPel := COLOR_DEPTH;              // Window color depth
      dmFields     := DM_PELSWIDTH OR DM_PELSHEIGHT OR DM_BITSPERPEL;
    END;

    // TRY TO change screen mode TO fullscreen
    IF (ChangeDisplaySettings(dmScreenSettings, CDS_FULLSCREEN) = DISP_CHANGE_FAILED) THEN
    BEGIN
      MessageBox(0, 'Unable to switch to fullscreen!', 'Error', MB_OK OR MB_ICONERROR);
      Fullscreen := False;
    END;
  END;

  // IF we are still IN fullscreen THEN
  IF (Fullscreen) THEN
  BEGIN
    dwStyle := WS_POPUP OR          // Creates a popup window
               WS_CLIPCHILDREN      // Doesn't draw within child windows
               or WS_CLIPSIBLINGS;  // Doesn't draw within sibling windows
    dwExStyle := WS_EX_APPWINDOW;   // Top level window
    ShowCursor(False);              // Turn OF the cursor (gets IN the way)
  END
  ELSE
  BEGIN
    dwStyle := WS_OVERLAPPEDWINDOW OR // Creates an overlapping window
               WS_CLIPCHILDREN OR     // Doesn't draw within child windows
               WS_CLIPSIBLINGS;       // Doesn't draw within sibling windows
    dwExStyle := WS_EX_APPWINDOW OR   // Top level window
                 WS_EX_WINDOWEDGE;    // Border WITH a raised edge
  END;

  // Attempt TO create the actual window
  h_Wnd := CreateWindowEx(dwExStyle,      // Extended window styles
                          'OpenGL',       // CLASS name
                          WND_TITLE,      // Window title (caption)
                          dwStyle,        // Window styles
                          0, 0,           // Window position
                          Width, Height,  // Size OF window
                          0,              // No parent window
                          0,              // No menu
                          h_Instance,     // Instance
                          NIL);           // Pass nothing TO WM_CREATE
  IF h_Wnd = 0 THEN
  BEGIN
    glKillWnd(Fullscreen);                // Undo all the settings we've changed
    MessageBox(0, 'Unable TO create window!', 'Error', MB_OK or MB_ICONERROR);
    Result := False;
    Exit;
  end;

  // Try to get a device context
  h_DC := GetDC(h_Wnd);
  if (h_DC = 0) then
  begin
    glKillWnd(Fullscreen);
    MessageBox(0, 'Unable TO get a device context!', 'Error', MB_OK or MB_ICONERROR);
    Result := False;
    Exit;
  end;

  // Attempts to find the pixel format supported by a device context that is the
  // best match to a given pixel format specification.
  PixelFormat := ChoosePixelFormat(h_DC, @pfd);
  if (PixelFormat = 0) then
  begin
    glKillWnd(Fullscreen);
    MessageBox(0, 'Unable TO find a suitable pixel format', 'Error', MB_OK or MB_ICONERROR);
    Result := False;
    Exit;
  end;

  // Sets the specified device context's pixel format TO the format specified by
  // the PixelFormat.
  IF (NOT SetPixelFormat(h_DC, PixelFormat, @pfd)) THEN
  BEGIN
    glKillWnd(Fullscreen);
    MessageBox(0, 'Unable to set the pixel format', 'Error', MB_OK OR MB_ICONERROR);
    Result := False;
    Exit;
  END;

  // Create a OpenGL rendering context
  h_RC := wglCreateContext(h_DC);
  IF (h_RC = 0) THEN
  BEGIN
    glKillWnd(Fullscreen);
    MessageBox(0, 'Unable to create an OpenGL rendering context', 'Error', MB_OK OR MB_ICONERROR);
    Result := False;
    Exit;
  END;

  // Makes the specified OpenGL rendering context the calling thread's current
  // rendering context
  if (not wglMakeCurrent(h_DC, h_RC)) then
  begin
    glKillWnd(Fullscreen);
    MessageBox(0, 'Unable TO activate OpenGL rendering context', 'Error', MB_OK or MB_ICONERROR);
    Result := False;
    Exit;
  end;

  // Settings to ensure that the window is the topmost window
  ShowWindow(h_Wnd, SW_SHOW);
  SetForegroundWindow(h_Wnd);
  SetFocus(h_Wnd);

  // Ensure the OpenGL window is resized properly
  glResizeWnd(Width, Height);
  glInit();

  Result := True;
end;

{--------------------------------------------------------------------}
{  Main message loop for the application                             }
{--------------------------------------------------------------------}
function WinMain(hInstance : HINST; hPrevInstance : HINST;
                 lpCmdLine : PChar; nCmdShow : Integer) : Integer; stdcall;
var
  msg : TMsg;
  finished : Boolean;
begin
  finished := False;
  // Perform application initialization:
  pfd.cColorBits := COLOR_DEPTH;
  if not glCreateWnd(SC_WIDTH, SC_HEIGHT, FULLSCREEN) then
  begin
    Result := 0;
    Exit;
  end;

  // Main message loop:
  while not finished do
  begin
    if (PeekMessage(msg, 0, 0, 0, PM_REMOVE)) then // Check if there is a message for this window
    begin
      if (msg.message = WM_QUIT) then     // If WM_QUIT message received then we are done
        finished := True
      else
      begin                               // Else translate and dispatch the message to this window
  	TranslateMessage(msg);
        DispatchMessage(msg);
      end;
    end
    else
    begin
      glDraw();
      SwapBuffers(h_DC);
      // If ESC key is pressed the user wants to quit
      if (keys[VK_ESCAPE]) then
        finished := True;
      // Add additional key stuff here
      ProcessKeys;
    end;
  end;
  glKillWnd(False);
  Result := msg.wParam;
end;

begin
  WinMain( hInstance, hPrevInst, CmdLine, CmdShow );
end.
0
Oleksy Adam napisał(a)

Można spróbować edycji zasobów programu. Jest do dego prosty programik ExeScope. Możesz założyć, że autor programu zadeklarował zmienną typu Boolean o nazwie FullScreen lub podobnej. Zmień wówczas FullScreen = False.

:| eeee.... zmienna? w exescope?
niby jak, bo sam jestem ciekaw, jak bys to zrobil...?

1 użytkowników online, w tym zalogowanych: 0, gości: 1