Relative position of text box on window resize
I am trying to render a text box in the center of my program window. When I run the program, my text box is not centered in the window. But upon expanding the window, the textbox become centered, as expected. Please help me understand why my program doesn't center the text-box, until I expand the window. My goal is to keep the text-box centered, however the window is sized/resized. I really appreciate it.
Code:
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static int xwindow, ywindow;
static HRGN hrgn;
HDC hdc, MemDCExercising;
HWND hwnd2;
PAINTSTRUCT ps ;
HBITMAP bmpExercising;
switch (message)
{
case WM_CREATE:
SetTimer(hwnd, TIMER_1, 5000, NULL);
GetWindowRect (hwnd, &CurrentWindowSize);
parentwindowwidth = CurrentWindowSize.right - CurrentWindowSize.left;
parentwindowheight = CurrentWindowSize.bottom - CurrentWindowSize.top;
CreateWindow(TEXT("edit"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, .5 * parentwindowwidth, .5 * parentwindowheight, 500, 100, hwnd, NULL, NULL, hwnd2, NULL);
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
//SetTextColor(hdc, RGB(0,255,0));
//SetBkColor(hdc, 0);
bmpExercising = (HBITMAP) LoadImage(hInst, TEXT("notepad.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
// Load the bitmap from the resource
// bmpExercising = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_EXERCISING));
// Create a memory device compatible with the above DC variable
MemDCExercising = CreateCompatibleDC(hdc);
// Select the new bitmap
SelectObject(MemDCExercising, bmpExercising);
// Copy the bits from the memory DC into the current dc
StretchBlt(hdc, 0, 0, 64, 64, MemDCExercising, 0, 0, 64, 64, SRCCOPY);
// Restore the old bitmap
DeleteDC(MemDCExercising);
DeleteObject(bmpExercising);
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_TIMER:
InvalidateRect (hwnd, NULL, TRUE);
UpdateWindow(hwnd);
return 0;
case WM_SIZE:
xwindow = LOWORD (lParam);
ywindow = HIWORD (lParam);
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}