Skip to content

Commit

Permalink
Fixed window creation behavior in Win32 Framebuffer
Browse files Browse the repository at this point in the history
It now creates the correct window size from the start and doesn't move the
window to (0,0) after showing it. This is much more natural and correct.

Also refactored and cleaned the related code somewhat.
  • Loading branch information
alexbudgh committed May 16, 2010
1 parent f24da5a commit f0146b9
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/framebuffer/fbw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ CWinDisplay::~CWinDisplay() {
// Comments :
void CWinDisplay::main() {
WNDCLASSEX wcex;
RECT clientRect,windowRect;
int nw,nh;
MSG msg;
const char *szPixieWndClass = "PixieWinDisplay";

hInst = (HINSTANCE) GetModuleHandle(NULL);

Expand All @@ -130,36 +129,37 @@ void CWinDisplay::main() {
wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "WinDisplay";
wcex.lpszClassName = szPixieWndClass;
wcex.hIconSm = LoadIcon(NULL,IDI_APPLICATION);

RegisterClassEx(&wcex);

// Make a non-resizable window style.
DWORD dwStyle = WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME | WS_MAXIMIZEBOX);

// Size of our desired client area.
RECT rc = { 0, 0, width, height };

// Compute the correct window size given our style.
AdjustWindowRect(&rc, dwStyle, FALSE);

// Create the window (non-resizable).
hWnd = CreateWindow("WinDisplay", name,
WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME | WS_MAXIMIZEBOX), CW_USEDEFAULT,
0, width, height, NULL, NULL, hInst, NULL);
hWnd = CreateWindow(szPixieWndClass, name,
dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left,
rc.bottom - rc.top, NULL, NULL, hInst, NULL);

if (!hWnd) {
active = FALSE;
return; // Nothing to do
}

// Associate a pointer to our instance with this window.
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)this);

// Show the window
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);

// Adjust the size of the window so that we display the entire picture
GetWindowRect(hWnd,&windowRect);
GetClientRect(hWnd,&clientRect);

nw = width + (windowRect.right - windowRect.left) - (clientRect.right - clientRect.left);
nh = height + (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top);

SetWindowPos(hWnd,NULL,0,0,nw,nh,SWP_SHOWWINDOW);

// Set up the bitmap
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biWidth = width;
Expand Down

0 comments on commit f0146b9

Please sign in to comment.