-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwindow.cpp
138 lines (119 loc) · 3.39 KB
/
twindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
TWINDOW.CPP
Copyright (c) 1994 Shawn Halpenny
All rights reserved.
Source code module for TWindow class.
*/
#ifndef __WOLF_H
#include <wolf.h>
#endif
//done
TWindow::TWindow(PTWindowObject pParent, LPCSTR lpszTitle, int nID) : TWindowObject(pParent, lpszTitle, nID)
{
WndClass.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW | CS_BYTEALIGNWINDOW; //default window style
WndClass.lpfnWndProc = TWindow::StandardWndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = pApplication->hInstance;
WndClass.hIcon = LoadIcon(0, IDI_APPLICATION); //use default app icon
WndClass.hCursor = LoadCursor(0, IDC_ARROW); //default cursor
WndClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); //nice white backgnd
WndClass.lpszMenuName = NULL; //default no menu
WndClass.lpszClassName = NULL; //class name isn't known yet
SetDimensions(CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT);
SetStyle(WS_OVERLAPPEDWINDOW, 0); //default overlapped window
} //TWindow::TWindow
TWindow::~TWindow()
{
//can always try to unregister the window class, since the function fails without error
//if windows still exist that are using the window class
if (!IsFlagSet(WB_SYSTEMCLASS))
UnregisterClass(WndClass.lpszClassName, pApplication->hInstance);
} //TWindow::~TWindow
//done
LRESULT CALLBACK _export TWindow::StandardWndProc(HWND hWindow, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
TMessage Msg;
Msg.hWindow = hWindow;
Msg.wMsg = wMsg;
Msg.wParam = wParam;
Msg.lParam = lParam;
Msg.lResult = 0;
return UMP(Msg);
} //TWindow::StandardWndProc
//done
void TWindow::AssignMenu(int nMenuID)
{
AssignMenu(MAKEINTRESOURCE(nMenuID));
} //TWindow::AssignMenu
//done
void TWindow::AssignMenu(LPCSTR lpszMenu)
{
if (!hWindow)
WndClass.lpszMenuName = lpszMenu;
else
{
HMENU hMenu = GetMenu(hWindow);
SetMenu(hWindow, LoadMenu(pApplication->hInstance, lpszMenu));
DrawMenuBar(hWindow);
if (hMenu)
DestroyMenu(hMenu);
}
} //TWindow::AssignMenu
//done
void TWindow::AssignIcon(int nIconID)
{
AssignIcon(MAKEINTRESOURCE(nIconID));
} //TWindow::AssignIcon
//done
void TWindow::AssignIcon(LPCSTR lpszIcon)
{
HICON hNewIcon = LoadIcon(pApplication->hInstance, lpszIcon);
if (!hWindow)
WndClass.hIcon = hNewIcon;
else
{
HICON hIcon = (HICON) GetClassWord(hWindow, GCW_HICON);
SetClassWord(hWindow, GCW_HICON, (WORD) hNewIcon);
DestroyIcon(hIcon);
}
} //TWindow::AssignIcon
//done
void TWindow::AssignCursor(int nCursorID)
{
AssignCursor(MAKEINTRESOURCE(nCursorID));
} //TWindow::AssignCursor
//done
void TWindow::AssignCursor(LPCSTR lpszCursor)
{
HCURSOR hNewCursor = LoadCursor(pApplication->hInstance, lpszCursor);
if (!hWindow)
WndClass.hCursor = hNewCursor;
else
{
HCURSOR hCursor = (HCURSOR) GetClassWord(hWindow, GCW_HCURSOR);
SetClassWord(hWindow, GCW_HCURSOR, (WORD) hNewCursor);
DestroyCursor(hCursor);
}
} //TWindow::AssignCursor
//done
void TWindow::WMCreate(RTMessage)
{
//create the child windows whose WB_AUTOCREATE flags are set
if (CreateChildren())
//all children must exist for transfer to take place
DoTransfer(TF_SET);
} //TWindow::WMCreate
//done
void TWindow::WMPaint(RTMessage)
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint(hWindow, &ps);
Paint(hDC, ps);
EndPaint(hWindow, &ps);
} //TWindow::WMPaint
//done
void TWindow::Paint(HDC, PAINTSTRUCT&)
{
//do nothing if programmer does not supply a Paint
} //TWindow::Paint