-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1.c
218 lines (187 loc) · 7.17 KB
/
p1.c
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include <windows.h>
#include <stdio.h>
#include "ui.h"
#define SIMPLE 1
#define MY_BACKGOUND_COLOR RGB(0,245,0)
#define MY_EDIT_ML_BKCOLOR RGB(0,235,235)
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
WNDCLASSEX class_;
COLORREF backColor;
char attivo;
HWND hWnd;
HFONT hf;
int font_h;
void app_thread(void *dummy);
// int /*WINAPI*/ myWinMain(int size_x, int size_y) // (HINSTANCE __hInstanciaAct, HINSTANCE __hInstanciaPrev, LPSTR __IpCmdLine, int __iCmdShow)
int create_main_win(int size_x, int size_y)
{
AllocConsole();
freopen("CONIN$", "r",stdin);
freopen("CONOUT$","w",stdout);
freopen("CONOUT$","w",stderr);
// __hInstanciaAct = 0;
// __iCmdShow = 1;
class_.cbSize = sizeof(WNDCLASSEX);
class_.cbWndExtra = 0;
class_.cbClsExtra = 0;
class_.style = CS_HREDRAW|CS_VREDRAW;
class_.lpfnWndProc = WndProc;
class_.hInstance = 0; //__hInstanciaAct;
class_.hIcon = LoadImage(NULL, "icoff.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
class_.hIconSm = LoadImage(NULL, "icoff.ico", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE);
class_.hCursor = LoadCursor(NULL, IDC_ARROW);
class_.lpszClassName = "MYCLASS";
class_.lpszMenuName = NULL;
class_.hbrBackground = SIMPLE ?
(HBRUSH)(COLOR_WINDOW) :
CreateSolidBrush(MY_BACKGOUND_COLOR);
if(!RegisterClassEx(&class_))
{
MessageBox(NULL, "NON", "ERROR", MB_ICONERROR);
return EXIT_FAILURE;
}
hWnd = CreateWindowEx(0,
"MYCLASS",
"Title",
WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT,
size_x, size_y, HWND_DESKTOP, NULL, 0/*__hInstanciaAct*/, NULL);
if(hWnd == NULL)
{
MessageBox(NULL, "NON2", "ERROR", MB_ICONERROR);
return EXIT_FAILURE;
}
// HBRUSH brush = CreateSolidBrush(RGB(140, 140, 140));
// SetClassLongPtr(hWnd, GCLP_HBRBACKGROUND, (LONG_PTR)brush);
ShowWindow(hWnd, 1/*__iCmdShow*/);
hf = CreateFont(/*size=*/15, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "MS Sans Serif");
SendMessage(hWnd, WM_SETFONT, (WPARAM)hf, 0);
// TEXTMETRIC tm;
// GetTextMetrics(GetDC(hWnd), &tm);
// font_h = (tm.tmHeight + tm.tmExternalLeading) + 14;
// GetDeviceCaps(GetDC(hWnd), LOGPIXELSY) / 72;
// (10*15+9)/10; // +2; // FM.tmHeight+10;
// DWORD nExStyles = GetWindowLongPtr(hWnd, GWL_EXSTYLE);
// if(nExStyles & WS_EX_CLIENTEDGE)
// font_h += GetSystemMetrics(SM_CYEDGE) * 2;
// if(nExStyles & WS_EX_STATICEDGE)
// font_h += GetSystemMetrics(SM_CYBORDER) * 2;
}
void main_loop(void)
{
MSG msg;
// create_widget();
SendMessage(hWnd, WM_CHANGEUISTATE, (WPARAM)(0x10001),(LPARAM)(0));
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
break;
}
case WM_COMMAND:
{
// switch(LOWORD(wParam))
// {
int j;
// static int cnt;
// printf("%5d WM_COMMAND %d %d\n", cnt++, LOWORD(wParam), HIWORD(wParam));
for (j = 0; j < N; j++)
{
if (LOWORD(wParam) == j)
{
switch (dialog[j].type)
{
case TYPE_CHECKBOX:
case TYPE_BUTTON:
if (dialog[j].fn)
{
dialog[j].fn(j);
}
break;
case TYPE_EDITBOX:
if (HIWORD(wParam) == EN_CHANGE)
{
if (dialog[j].fn)
{
dialog[j].fn(j);
}
}
break;
case TYPE_LISTBOX:
if (HIWORD(wParam) == LBN_SELCHANGE)
{
if (dialog[j].fn)
{
dialog[j].fn(j);
}
}
break;
case TYPE_COMBOBOX:
if (HIWORD(wParam) == CBN_SELCHANGE)
{
if (dialog[j].fn)
{
dialog[j].fn(j);
}
}
break;
}
}
}
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
#if SIMPLE == 0
/* Colore text box EDITABILE */
case WM_CTLCOLOREDIT:
{
HDC hdc = (HDC)wParam;
if (/*attivo &&*/ (HANDLE)lParam==dialog[E1].hwnd)
{
// printf("ECCOLO1\n");
SetTextColor(hdc, RGB(0,100,255)); // yourColor is a WORD and it's format is 0x00BBGGRR
SetBkColor(hdc, RGB(255,255,0)); // yourColor is a WORD and it's format is 0x00BBGGRR
return (LRESULT)CreateSolidBrush(RGB(255,255,0));
}
return (LRESULT) GetStockObject(DC_BRUSH); // return a DC brush.
}
/* Bordo bottoni */
case WM_CTLCOLORBTN:
{
HDC hdc = (HDC)wParam;
SetBkColor(hdc, MY_BACKGOUND_COLOR);
return (LRESULT)CreateSolidBrush(MY_BACKGOUND_COLOR); // GetSysColorBrush(COLOR_WINDOW);/* (LRESULT)hBrushColor;*/
}
/* Etichetta checkbox */
/* Edit Multiline READ ONLY */
case WM_CTLCOLORSTATIC:
{
// if ((HANDLE)lParam==dialog[E1].hwnd)
// {
HDC hdc = (HDC)wParam;
printf("ECCOLO\n");
SetBkColor(hdc, MY_EDIT_ML_BKCOLOR);
// return (LRESULT) CreateSolidBrush(MY_EDIT_ML_BKCOLOR); //GetStockObject(DC_BRUSH); // return a DC brush.
// }
return (LRESULT)CreateSolidBrush(MY_EDIT_ML_BKCOLOR); // GetSysColorBrush(COLOR_WINDOW);/* (LRESULT)hBrushColor;*/
}
#endif
default:
{
return DefWindowProc(hWnd, msg, wParam, lParam);
}
}
return 0;
}