Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3711
Number of posts: 9173

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Layout manager Posted by jasonleee on 1 Feb 2009 at 2:20 AM
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.

// link directily to winmm.lib
#include <windows.h>
#include <Mmsystem.h>
#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;
}

Report
Re: Layout manager Posted by cjr9968 on 1 Feb 2009 at 7:59 PM
You need to add a case statement under the message switch.

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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.