Добавил:
Kaz
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лаба 1-6 Системное программирование для ОС Windows [Вариант отсутствует, общий] / Лаба 4 / osisp_laba4 / CreatingWindow
.cpp#include "stdafx.h"
#include "CreatingWindow.h"
#include "Resource.h"
#include "ButtonHandlers.h"
#include "LoadDatabase.h"
#pragma comment(lib, "UxTheme.lib")
#pragma comment(lib, "Comctl32.lib")
extern HINSTANCE hInst;
HWND g_hMainWindow;
HWND g_hListView;
HWND g_hLoadDatabaseButton;
HWND g_hSearchButton;
HWND g_hShowButton;
HWND g_hExitButton;
HWND g_hInputBox[8];
const int width_Mp = 7;
struct {
TCHAR *name;
int width;
} columns[] = {
{ TEXT("Номер телефона:"), PHONE_DB_PHONE_LEN*width_Mp },
{ TEXT("Фамилия:"), PHONE_DB_LASTNAME_LEN*width_Mp },
{ TEXT("Имя:"), PHONE_DB_NAME_LEN*width_Mp },
{ TEXT("Отчество:"), PHONE_DB_PATRONYM_LEN*width_Mp },
{ TEXT("Улица:"), PHONE_DB_STREET_LEN*width_Mp },
{ TEXT("Дом:"), PHONE_DB_HOUSE_LEN*width_Mp },
{ TEXT("Корпус:"), PHONE_DB_HOUSING_LEN*width_Mp },
{ TEXT("Квартира:"), PHONE_DB_APARTMENT_LEN*width_Mp }
};
const int cColumns = _countof(columns);
#define MAX_LOADSTRING 100
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
BOOL CreateMainWindow(int nCmdShow)
{
LoadString(hInst, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInst, IDC_OSISP_LABA4, szWindowClass, MAX_LOADSTRING);
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInst;
wcex.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_OSISP_LABA4));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(4);//(COLOR_DESKTOP);// COLOR_WINDOW-1
wcex.lpszMenuName = 0;//MAKEINTRESOURCE(IDC_OSISP_LABA4);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
RegisterClassEx(&wcex);
// Store instance handle in our global variable
// creating main window
int mwWidth = 30;
for (int i = 0; i < cColumns; i++)
mwWidth += columns[i].width+2;
g_hMainWindow = CreateWindow(
szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0,
mwWidth, 800,
NULL, NULL, hInst, NULL);
// creating List View
RECT mainWindowRect;
GetClientRect(g_hMainWindow, &mainWindowRect);
const int
listViewPosX = 0,
listViewPosY = 100;
g_hListView = CreateWindowEx(
WS_EX_STATICEDGE,
WC_LISTVIEW,
NULL,
WS_CHILD|WS_VISIBLE|LVS_REPORT|LVS_EDITLABELS,
0, 100,
mainWindowRect.right, mainWindowRect.bottom-100,
g_hMainWindow, NULL, hInst, NULL);
//adding columns
for (int i = 0; i < cColumns; i++) {
AddColumnToListView(g_hListView, columns[i].name, i, columns[i].width);
}
// creating Buttons
const int
loadButtonWidth = 150,
loadButtonHeigth = 40,
loadButtonPosX = 10,
loadButtonPosY = 10;
g_hLoadDatabaseButton = CreateWindow(
WC_BUTTON,
TEXT("Load DataBase"),
WS_CHILD|WS_VISIBLE,
loadButtonPosX, loadButtonPosY,
loadButtonWidth, loadButtonHeigth,
g_hMainWindow,
NULL,
hInst,
NULL);
//-------- show All
const int
showButtonWidth = 150,
showButtonHeigth = 40,
showButtonPosX = loadButtonPosX + loadButtonWidth + 250,
showButtonPosY = loadButtonPosY;
g_hShowButton = CreateWindow(
WC_BUTTON,
TEXT("Show All"),
WS_CHILD|WS_VISIBLE,
showButtonPosX, showButtonPosY,
showButtonWidth, showButtonHeigth,
g_hMainWindow,
NULL,
hInst,
NULL);
//-------- Search
const int
searchButtonWidth = 150,
searchButtonHeigth = 40,
searchButtonPosX = showButtonPosX + loadButtonWidth+250,
searchButtonPosY = loadButtonPosY;
g_hSearchButton = CreateWindow(
WC_BUTTON,
TEXT("Search"),
WS_CHILD|WS_VISIBLE,
searchButtonPosX, searchButtonPosY,
searchButtonWidth, searchButtonHeigth,
g_hMainWindow,
NULL,
hInst,
NULL);
// ------ box
int inputBoxPosX = loadButtonPosX,
inputBoxPosY = loadButtonPosY + loadButtonHeigth + 10,
inputBoxWidth = 150, inputBoxHeigth = 20;
for (int i = 0; i < cColumns; i++) {
inputBoxWidth = columns[i].width;
g_hInputBox[i] = CreateWindowEx(
0,
WC_EDIT,
0,
WS_VISIBLE | WS_CHILD | ES_LEFT,
inputBoxPosX, inputBoxPosY,
inputBoxWidth, inputBoxHeigth,
g_hMainWindow,
NULL, hInst, 0);
inputBoxPosX += columns[i].width + 2;
if (g_hInputBox[i] == NULL) {
MessageBox(0, TEXT("Can't Create Window!"), NULL, MB_OK);
exit(0);
}
}
ShowWindow(g_hMainWindow, nCmdShow);
UpdateWindow(g_hMainWindow);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case BN_CLICKED:
{
HWND hWnd = (HWND)lParam;
if (hWnd == g_hLoadDatabaseButton) {
LoadDB();
} else if (hWnd == g_hSearchButton) {
SearchDB();
} else if(hWnd == g_hShowButton) {
ShowDB();
}
}
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Соседние файлы в папке osisp_laba4