Windows/Windows API
윈도우 크기, 사이즈 조정 (WM_SIZE)
aucd29
2013. 10. 1. 18:54
#include <windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPSTR lpszClass="WmSize";
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance
,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst=hInstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=(WNDPROC)WndProc;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
while(GetMessage(&Message,0,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
#define ID_LISTBOX 100
char Items[][15]={"Apple","Orange","Melon","Grape","Strawberry"};
HWND hList;
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
int i;
RECT crt;
switch(iMessage) {
case WM_CREATE:
hList=CreateWindow("listbox",NULL,WS_CHILD | WS_VISIBLE | LBS_NOINTEGRALHEIGHT,
0,0,0,0,hWnd,(HMENU)ID_LISTBOX,g_hInst,NULL); // Create Listbox
for (i=0;i<5;i++)
SendMessage(hList,LB_ADDSTRING,0,(LPARAM)Items[i]); // Add string
return 0;
case WM_SIZE:
GetClientRect(hWnd, &crt); // Window의 top, left, bottom, right 값을 얻기
MoveWindow(hList, crt.left, crt.top, crt.right, crt.bottom, TRUE); // listbox의 size를 change
return 0;
case WM_SIZING: // Window의 size를 변경하고 있을때
/*
Parameters
wParam
Specifies which edge of the window is being sized. This parameter can be one of the following values.
WMSZ_BOTTOM
Bottom edge
WMSZ_BOTTOMLEFT
Bottom-left corner
WMSZ_BOTTOMRIGHT
Bottom-right corner
WMSZ_LEFT
Left edge
WMSZ_RIGHT
Right edge
WMSZ_TOP
Top edge
WMSZ_TOPLEFT
Top-left corner
WMSZ_TOPRIGHT
Top-right corner
lParam
Pointer to a RECT structure with the screen coordinates of the drag rectangle. To change the size or position of the drag rectangle, an application must change the members of this structure.
Return Value
An application should return TRUE if it processes this message.
*/
// 왼쪽변을 드래그 하고 있을 경우
// 50씩 윈도우를 축소, 확대 한다.
if (wParam==WMSZ_LEFT)
((RECT *)lParam)->left = ((RECT *)lParam)->left / 50 * 50;
return TRUE;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPSTR lpszClass="WmSize";
int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance
,LPSTR lpszCmdParam,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst=hInstance;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=(WNDPROC)WndProc;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
while(GetMessage(&Message,0,0,0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
#define ID_LISTBOX 100
char Items[][15]={"Apple","Orange","Melon","Grape","Strawberry"};
HWND hList;
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
int i;
RECT crt;
switch(iMessage) {
case WM_CREATE:
hList=CreateWindow("listbox",NULL,WS_CHILD | WS_VISIBLE | LBS_NOINTEGRALHEIGHT,
0,0,0,0,hWnd,(HMENU)ID_LISTBOX,g_hInst,NULL); // Create Listbox
for (i=0;i<5;i++)
SendMessage(hList,LB_ADDSTRING,0,(LPARAM)Items[i]); // Add string
return 0;
case WM_SIZE:
GetClientRect(hWnd, &crt); // Window의 top, left, bottom, right 값을 얻기
MoveWindow(hList, crt.left, crt.top, crt.right, crt.bottom, TRUE); // listbox의 size를 change
return 0;
case WM_SIZING: // Window의 size를 변경하고 있을때
/*
Parameters
wParam
Specifies which edge of the window is being sized. This parameter can be one of the following values.
WMSZ_BOTTOM
Bottom edge
WMSZ_BOTTOMLEFT
Bottom-left corner
WMSZ_BOTTOMRIGHT
Bottom-right corner
WMSZ_LEFT
Left edge
WMSZ_RIGHT
Right edge
WMSZ_TOP
Top edge
WMSZ_TOPLEFT
Top-left corner
WMSZ_TOPRIGHT
Top-right corner
lParam
Pointer to a RECT structure with the screen coordinates of the drag rectangle. To change the size or position of the drag rectangle, an application must change the members of this structure.
Return Value
An application should return TRUE if it processes this message.
*/
// 왼쪽변을 드래그 하고 있을 경우
// 50씩 윈도우를 축소, 확대 한다.
if (wParam==WMSZ_LEFT)
((RECT *)lParam)->left = ((RECT *)lParam)->left / 50 * 50;
return TRUE;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}