g3RC4n
September 5th, 2007, 07:21 PM
how do i let me program resize the window through the menu.
this is for a minesweeper clone, where i've disabled user window resizing
i'm sure theres some sort of function like
windowResize(hWnd, &rect, x, y);
heres all the code if you nned it
// msclone.cpp : Defines the entry point for the application.
#include "stdafx.h"
#include "msclone.h"
#define MAX_LOADSTRING 100
//glabal varible of the gameboard xy size and number of mines
static int boardXsize = 9;
static int boardYsize = 9;
static int boardMines = 10;
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MSCLONE, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MSCLONE));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MSCLONE));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_MSCLONE);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
int buff;
int x = SQUARE;
buff = boardXsize;
x *= buff;
x += X_BOARDER;
int y = SQUARE;
buff = boardYsize;
y *= buff;
y += Y_BOARDER;
y += MENU_SIZE;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass,
szTitle,
(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX) ,
100,
100,
x,
y,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static ms* current;
static HBITMAP hBitmap[14];
int x = 0;
int y = 0;
int wmId;
int wmEvent;
int square;
static int cxClient;
static int cyClient;
static int iSelection = ID_SETTING_BEGGINER ;
HDC hdc;
RECT rect;
HDC hdcMem;
PAINTSTRUCT ps;
HINSTANCE hInstance;
HMENU hMenu;
static bool endGame = false;
switch (message)
{
case WM_COMMAND:
hMenu = GetMenu (hWnd);
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
case ID_FILE_NEWGAME:
delete current;
current = new ms(boardXsize,boardYsize,boardMines);
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
break;
case ID_SETTING_BEGGINER:
CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ;
iSelection = LOWORD (wParam) ;
CheckMenuItem (hMenu, iSelection, MF_CHECKED) ;
boardXsize = 9;
boardYsize = 9;
boardMines = 10;
delete current;
current = new ms(boardXsize,boardYsize,boardMines);
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
break;
case ID_SETTING_INTERMEDIATE:
CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ;
iSelection = LOWORD (wParam) ;
CheckMenuItem (hMenu, iSelection, MF_CHECKED) ;
boardXsize = 16;
boardYsize = 16;
boardMines = 40;
delete current;
current = new ms(boardXsize,boardYsize,boardMines);
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
break;
case ID_SETTING_EXPERT:
CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ;
iSelection = LOWORD (wParam) ;
CheckMenuItem (hMenu, iSelection, MF_CHECKED) ;
boardXsize = 30;
boardYsize = 16;
boardMines = 99;
delete current;
current = new ms(boardXsize,boardYsize,boardMines);
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint (hWnd, &ps) ;
hdcMem = CreateCompatibleDC (hdc) ;
SelectObject (hdcMem, hBitmap[0]);
square = SQUARE;
for(int ix = 0; ix < boardXsize; ix++)
{
for(int iy = 0; iy < boardYsize ; iy++)
{
if(current->userBoard[ix][iy] != 1)
{
if(current->userBoard[ix][iy] == _VOID_)
SelectObject (hdcMem, hBitmap[10]);
if(current->userBoard[ix][iy] == _FLAG_)
SelectObject (hdcMem, hBitmap[12]);
if(current->userBoard[ix][iy] == _MARK_)
SelectObject (hdcMem, hBitmap[13]);
}
else
SelectObject (hdcMem, hBitmap[current->mineBoard[ix][iy]]);
BitBlt(hdc, square*ix,square*iy,square,square, hdcMem, 0,0, SRCCOPY);
}
}
GetClientRect (hWnd, &rect) ;
DeleteDC (hdcMem) ;
EndPaint (hWnd, &ps) ;
return 0 ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_CREATE:
current = new ms(boardXsize,boardYsize,boardMines);
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
hBitmap[0] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_NULL"));
hBitmap[1] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_ONE"));
hBitmap[2] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_TWO"));
hBitmap[3] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_THREE"));
hBitmap[4] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_FOUR"));
hBitmap[5] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_FIVE"));
hBitmap[6] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_SIX"));
hBitmap[7] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_SEVEN"));
hBitmap[8] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_EIGHT"));
hBitmap[9] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_MINE"));
hBitmap[10] =LoadBitmap (hInstance, TEXT ("IDB_BITMAP_BUTTON"));
hBitmap[11] =LoadBitmap (hInstance, TEXT ("IDB_BITMAP_RMINE"));
hBitmap[12] =LoadBitmap (hInstance, TEXT ("IDB_BITMAP_FLAG"));
hBitmap[13] =LoadBitmap (hInstance, TEXT ("IDB_BITMAP_MARK"));
return 0;
case WM_LBUTTONDOWN :
x = LOWORD (lParam) / 17;
y = HIWORD (lParam) / 17;
if(endGame == false)
if(current->SelectSquare(x,y) == 1)
{
endGame = true;
}
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
return 0 ;
case WM_RBUTTONDOWN :
x = LOWORD (lParam) / 17;
y = HIWORD (lParam) / 17;
if(endGame == false)
{
if(current->userBoard[x][y] != 1)
{
switch(current->userBoard[x][y])
{
case _VOID_:
current->userBoard[x][y] = _FLAG_;
break;
case _FLAG_:
current->userBoard[x][y] = _MARK_;
break;
case _MARK_:
current->userBoard[x][y] = _VOID_;
break;
default:
break;
}
}
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
this is for a minesweeper clone, where i've disabled user window resizing
i'm sure theres some sort of function like
windowResize(hWnd, &rect, x, y);
heres all the code if you nned it
// msclone.cpp : Defines the entry point for the application.
#include "stdafx.h"
#include "msclone.h"
#define MAX_LOADSTRING 100
//glabal varible of the gameboard xy size and number of mines
static int boardXsize = 9;
static int boardYsize = 9;
static int boardMines = 10;
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MSCLONE, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MSCLONE));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MSCLONE));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_MSCLONE);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
int buff;
int x = SQUARE;
buff = boardXsize;
x *= buff;
x += X_BOARDER;
int y = SQUARE;
buff = boardYsize;
y *= buff;
y += Y_BOARDER;
y += MENU_SIZE;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass,
szTitle,
(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX) ,
100,
100,
x,
y,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static ms* current;
static HBITMAP hBitmap[14];
int x = 0;
int y = 0;
int wmId;
int wmEvent;
int square;
static int cxClient;
static int cyClient;
static int iSelection = ID_SETTING_BEGGINER ;
HDC hdc;
RECT rect;
HDC hdcMem;
PAINTSTRUCT ps;
HINSTANCE hInstance;
HMENU hMenu;
static bool endGame = false;
switch (message)
{
case WM_COMMAND:
hMenu = GetMenu (hWnd);
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
case ID_FILE_NEWGAME:
delete current;
current = new ms(boardXsize,boardYsize,boardMines);
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
break;
case ID_SETTING_BEGGINER:
CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ;
iSelection = LOWORD (wParam) ;
CheckMenuItem (hMenu, iSelection, MF_CHECKED) ;
boardXsize = 9;
boardYsize = 9;
boardMines = 10;
delete current;
current = new ms(boardXsize,boardYsize,boardMines);
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
break;
case ID_SETTING_INTERMEDIATE:
CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ;
iSelection = LOWORD (wParam) ;
CheckMenuItem (hMenu, iSelection, MF_CHECKED) ;
boardXsize = 16;
boardYsize = 16;
boardMines = 40;
delete current;
current = new ms(boardXsize,boardYsize,boardMines);
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
break;
case ID_SETTING_EXPERT:
CheckMenuItem (hMenu, iSelection, MF_UNCHECKED) ;
iSelection = LOWORD (wParam) ;
CheckMenuItem (hMenu, iSelection, MF_CHECKED) ;
boardXsize = 30;
boardYsize = 16;
boardMines = 99;
delete current;
current = new ms(boardXsize,boardYsize,boardMines);
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint (hWnd, &ps) ;
hdcMem = CreateCompatibleDC (hdc) ;
SelectObject (hdcMem, hBitmap[0]);
square = SQUARE;
for(int ix = 0; ix < boardXsize; ix++)
{
for(int iy = 0; iy < boardYsize ; iy++)
{
if(current->userBoard[ix][iy] != 1)
{
if(current->userBoard[ix][iy] == _VOID_)
SelectObject (hdcMem, hBitmap[10]);
if(current->userBoard[ix][iy] == _FLAG_)
SelectObject (hdcMem, hBitmap[12]);
if(current->userBoard[ix][iy] == _MARK_)
SelectObject (hdcMem, hBitmap[13]);
}
else
SelectObject (hdcMem, hBitmap[current->mineBoard[ix][iy]]);
BitBlt(hdc, square*ix,square*iy,square,square, hdcMem, 0,0, SRCCOPY);
}
}
GetClientRect (hWnd, &rect) ;
DeleteDC (hdcMem) ;
EndPaint (hWnd, &ps) ;
return 0 ;
case WM_SIZE:
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
return 0 ;
case WM_CREATE:
current = new ms(boardXsize,boardYsize,boardMines);
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
hBitmap[0] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_NULL"));
hBitmap[1] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_ONE"));
hBitmap[2] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_TWO"));
hBitmap[3] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_THREE"));
hBitmap[4] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_FOUR"));
hBitmap[5] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_FIVE"));
hBitmap[6] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_SIX"));
hBitmap[7] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_SEVEN"));
hBitmap[8] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_EIGHT"));
hBitmap[9] = LoadBitmap (hInstance, TEXT ("IDB_BITMAP_MINE"));
hBitmap[10] =LoadBitmap (hInstance, TEXT ("IDB_BITMAP_BUTTON"));
hBitmap[11] =LoadBitmap (hInstance, TEXT ("IDB_BITMAP_RMINE"));
hBitmap[12] =LoadBitmap (hInstance, TEXT ("IDB_BITMAP_FLAG"));
hBitmap[13] =LoadBitmap (hInstance, TEXT ("IDB_BITMAP_MARK"));
return 0;
case WM_LBUTTONDOWN :
x = LOWORD (lParam) / 17;
y = HIWORD (lParam) / 17;
if(endGame == false)
if(current->SelectSquare(x,y) == 1)
{
endGame = true;
}
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
return 0 ;
case WM_RBUTTONDOWN :
x = LOWORD (lParam) / 17;
y = HIWORD (lParam) / 17;
if(endGame == false)
{
if(current->userBoard[x][y] != 1)
{
switch(current->userBoard[x][y])
{
case _VOID_:
current->userBoard[x][y] = _FLAG_;
break;
case _FLAG_:
current->userBoard[x][y] = _MARK_;
break;
case _MARK_:
current->userBoard[x][y] = _VOID_;
break;
default:
break;
}
}
GetClientRect(hWnd, &rect);
InvalidateRect(hWnd, &rect, 0);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}