jasonleee
January 31st, 2009, 01:41 AM
I'm using visual c++ everything compiles fine I just need to be pointed in the right direction when i run the program and maximize the window or do any resizing at all the buttons stay in same position and the image won't resize. thanks for the help code is below.
// link directily to winmm.lib
#include <windows.h>
#include <Mmsystem.h>
#define WIN32_LEAN_AND_MEAN
#define BUTTON_A 1
#define BUTTON_B 2
#pragma comment(lib,"winmm.lib") // for visual c++ winmm.lib
static HINSTANCE hInstance = NULL;
char szClassName[] = "my program";
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:
hwndButton = CreateButton("Buttonname", 10, 25, 100, 25, BUTTON_A, hwnd);
hwndButton = CreateButton("Buttonname.", 130, 25, 100, 25, BUTTON_B, 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("mysoundwave"), NULL, SND_ALIAS | SND_APPLICATION);
break;
case BUTTON_B:
PlaySound(TEXT("mysoundwave"), 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,
"My program",
// 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;
}
// link directily to winmm.lib
#include <windows.h>
#include <Mmsystem.h>
#define WIN32_LEAN_AND_MEAN
#define BUTTON_A 1
#define BUTTON_B 2
#pragma comment(lib,"winmm.lib") // for visual c++ winmm.lib
static HINSTANCE hInstance = NULL;
char szClassName[] = "my program";
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:
hwndButton = CreateButton("Buttonname", 10, 25, 100, 25, BUTTON_A, hwnd);
hwndButton = CreateButton("Buttonname.", 130, 25, 100, 25, BUTTON_B, 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("mysoundwave"), NULL, SND_ALIAS | SND_APPLICATION);
break;
case BUTTON_B:
PlaySound(TEXT("mysoundwave"), 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,
"My program",
// 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;
}