Hey everybody new to the forum. If anybody could help me with this question it would be super.
I have 3 buttons in my program and I need them to re size when the parent window re sizes I looked up WM_SIZE and SetWindowPos but im not sure how to implement it. my code is below thanks for any help.
[code]
// link directily to winmm.lib
#include #include #define WIN32_LEAN_AND_MEAN
#define BUTTON_A 1
#define BUTTON_B 2
#define BUTTON_C 3
#pragma comment(lib,"winmm.lib") // for visual c++ winmm.lib
static HINSTANCE hInstance = NULL;
char szClassName[] = "My Prog";
const char *ClsName = "BitmapAsBackground";
const char *WndName = "Load a bitmap as background!";
// A function to create a button
HWND CreateButton(char* tempText, int x, int y, int width, int height, int identifier, HWND hwnd)
{
HWND hButtonTemp;
hButtonTemp = CreateWindowEx(
0,
"BUTTON",
tempText,
WS_CHILD | WS_VISIBLE,
x, y,
width, height,
hwnd, (HMENU)identifier, hInstance, NULL);
return hButtonTemp;
}
// The window procedure
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// Control handles
static HWND hwndEdit;
static HWND hwndStatic;
static HWND hwndButton;
static HWND hwndCheck;
switch (message)
{
case WM_CREATE:
// Creates a button labeled "Click me!"
hwndButton = CreateButton("It's Akira.", 10, 25, 100, 25, BUTTON_A, hwnd);
hwndButton = CreateButton("Alone.", 130, 25, 100, 25, BUTTON_B, hwnd);
hwndButton = CreateButton("Bad.", 250, 25, 100, 25, BUTTON_C, hwnd);
break;
case WM_COMMAND:
// If a button is clicked...
if(HIWORD(wParam) == BN_CLICKED)
{
switch(LOWORD(wParam))
{
// ...And the button is the one with the
// identifier IDC_BUTTON...
case BUTTON_A:
PlaySound(TEXT("akira.wav"), NULL, SND_ALIAS | SND_APPLICATION);
break;
case BUTTON_B:
PlaySound(TEXT("alone.wav"), NULL, SND_ALIAS | SND_APPLICATION);
break;
case BUTTON_C:
PlaySound(TEXT("bad.wav"), NULL, SND_ALIAS | SND_APPLICATION);
break;
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
LOGBRUSH background;
wincl.hInstance = hInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof(WNDCLASSEX);
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) GetStockObject(GRAY_BRUSH);
// We want to laod a bitmap in memory
background.lbStyle = BS_PATTERN;
// Load the image
background.lbHatch = (long) LoadImage(hInstance,"Akira1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
// create the brush.
wincl.hbrBackground = CreateBrushIndirect(&background);
if(!RegisterClassEx(&wincl)) return 0;
hwnd = CreateWindowEx(
0,
szClassName,
"Akira Soundboard",
// can also use WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, which will let it
// minimize but the size will always be the same.
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
605,
520,
HWND_DESKTOP,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd, nFunsterStil);
while(GetMessage(&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}[/code]
Comments
case WM_SIZE:
....
break;
Under that case statement you should use the SetWindowPos function to resize any of the windows.
The MSDN info on the function is here:
http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx