-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
114 lines (103 loc) · 2.87 KB
/
main.c
File metadata and controls
114 lines (103 loc) · 2.87 KB
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
// Custom Menu Program by Amash Shafi Jami
// main.c
#include "CustomMenu.h"
LRESULT CALLBACK fnWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow){
TCHAR szAppName[] = _TEXT("Custom Menu Program 1");
HWND hWnd;
MSG msg;
WNDCLASS wndClass;
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 = fnWinProc;
wndClass.lpszClassName = szAppName;
wndClass.lpszMenuName = NULL;
wndClass.style = CS_VREDRAW | CS_HREDRAW;
if (!RegisterClass(&wndClass)){
ERR_CHAR_RESERVE;
ERR_CHAR_FILL_1_VALUE(
"Cannot Register Window Class Of name \"%s\"",
wndClass.lpszClassName
);
MessageBox(
NULL,
ERR_CHAR,
_TEXT("ERROR : Cant Register Window Class"),
MB_ICONERROR | MB_APPLMODAL
);
return 0;
}
hWnd = CreateWindow(
szAppName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if (hWnd == NULL){
ERR_CHAR_RESERVE;
ERR_CHAR_FILL_1_VALUE(
"Cannot Create Window Of Window Name \"%s\"",
szAppName
)
MessageBox(NULL,ERR_CHAR,_TEXT("ERROR : Window Creation Failed"),MB_ICONERROR | MB_APPLMODAL);
return 0;
}
ShowWindow(hWnd,iCmdShow);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 1;
}
LRESULT CALLBACK fnWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
static int cxClient, cyClient;
HDC hdc;
PAINTSTRUCT ps;
switch (msg)
{
case WM_CREATE:{
fnCreateMenu(hWnd);
return 0;
}
case WM_SIZE:
cxClient = GET_X_LPARAM(lParam);
cyClient = GET_Y_LPARAM(lParam);
return 0;
case WM_PAINT:{
hdc = BeginPaint(hWnd,&ps);
const int iBuff = 256;
const int iPaddingCoord = 5;
TCHAR szBuff[iBuff];
StringCchPrintf(
szBuff,
iBuff,
_TEXT("Window Size (x : y) : %i : %i"),
cxClient,
cyClient
);
int cyPadding = iPaddingCoord + CY_MENU_ITEM;
int cxPadding = iPaddingCoord;
TextOut(hdc,cxPadding,cyPadding,szBuff,lstrlen(szBuff));
EndPaint(hWnd,&ps);
return 0;
}
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}