I want to be able to resize my controls when the user resizes my form. I tried:
How do I get this to work?Code:case WM_SIZE:
if ((HWND)lParam == hwnd)
{
MessageBox(hwnd, "You resized", "Resize", MB_OK | MB_ICONINFORMATION);
}
Printable View
I want to be able to resize my controls when the user resizes my form. I tried:
How do I get this to work?Code:case WM_SIZE:
if ((HWND)lParam == hwnd)
{
MessageBox(hwnd, "You resized", "Resize", MB_OK | MB_ICONINFORMATION);
}
I think the best way would be to catch all the WM_SIZE messages that are sent to your main window. Then have a procedure that can make the proper sizing calculations based on the current size of the main window. These calculations are then applied to each control within the main window. Perhaps you can use enumeration to cycle through all the controls...
I know what I have to do, but I don't know how. With my source in the previous post, the MessageBox doesn't fire when being resized. Why?
Try this...
PHP Code:#include <windows.h>
int fwSizeType=0;
int nWidth=0;
int nHeight=0;
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{ //Run through messages that window receives
switch (uMsg)
{
case WM_SIZE:
fwSizeType = wParam; // resizing flag
nWidth = LOWORD(lParam); // width of client area
nHeight = HIWORD(lParam); // height of client area
MessageBox(hWnd, "You resized", "Resize", MB_OK | MB_ICONINFORMATION);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hWnd, uMsg, wParam, lParam));
}
return(0L);
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
{ //Create the Window
MSG msg;
HWND hWnd;
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(GRAY_BRUSH-1);
wc.lpszMenuName = "TEST";
wc.lpszClassName = "TEST";
if (!RegisterClass(&wc))
return(0L);
hWnd = CreateWindow("TEST",
"TEST",
DS_CENTER | WS_OVERLAPPEDWINDOW,
10, 10, 750, 500,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}