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
|
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
RECT rect = {100, 100, 200, 100};
InvalidateRect(hWnd, &rect, false);
switch (msg)
{
// Sent when the user selects a command item from a menu, when a control sends a notification message to its parent window,
// or when an accelerator keystroke is translated
case WM_COMMAND:
switch(wp)
{
case IDA_MENU_EXIT:
DestroyWindow(hWnd); // PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case IDA_MENU_ABOUT:
displayDialog(hWnd);
break;
case ID_FILL_TANK:
water_Level = 80;
SetWindowText(TextBox, "Filled");
InvalidateRect(hWnd, &rect, false);
Tank_Filled = true;
Tank_Empty = false;
Tank_Half_Filled = false;
break;
case ID_EMPTY_TANK:
water_Level = 525;
SetWindowText(TextBox, "Empty");
InvalidateRect(hWnd, &rect, false);
Tank_Empty = true;
Tank_Filled = false;
Tank_Half_Filled = false;
break;
case ID_HALF_FILL_TANK:
water_Level = 300;
SetWindowText(TextBox, "Half-Filled");
InvalidateRect(hWnd, &rect, false);
Tank_Half_Filled = true;
Tank_Filled = false;
Tank_Empty = false;
break;
case ID_AUTO_RUN:
break;
} // end inner switch
break;
// Sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function.
case WM_CREATE:
addControls(hWnd);
HMENU hMenu, hSubMenu;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
// File PopUp Menu
AppendMenu(hSubMenu,MF_STRING,IDA_MENU_EXIT,"Exit"); // Appends a new item to the end of the specified menu bar, drop-down menu, submenu, or shortcut menu.
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu,"File"); //
// About Menu
AppendMenu(hMenu,MF_STRING,IDA_MENU_ABOUT,"About"); //
SetMenu(hWnd, hMenu); // Assigns a new menu to the specified window.
break;
// Sent when a window is being destroyed.
case WM_DESTROY:
// DestroyWindow(g_hToolbar);
PostQuitMessage(0);
break;
default:
// The function DefWindowProcW calls the default window procedure to provide default processing for any window messages that an application does not process.
// This function ensures that every message is processed.
return DefWindowProcW(hWnd,msg,wp,lp);
} // end outer switch
} // end
LRESULT CALLBACK WindowProcedure2(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hdc; // handle to device context (DC)
PAINTSTRUCT ps; // paint data for Begin/EndPaint
int width,height; // Width and height of Client Area
switch (msg)
{
case WM_CREATE :
return 0;
case WM_SIZE :
width = LOWORD(lParam);
height = HIWORD(lParam);
case WM_PAINT :
hdc = BeginPaint(hWnd, &ps);
// draw_Tank_Status(hdc, width, height);
Tank_Initial_level = false;
if(Tank_Initial_level)
{
cout << "Initial Level" << endl;
draw_Tank_Status(hdc, width, height);
}
cout << Tank_Filled << endl;
if(Tank_Filled)
{
cout << "Filling" << endl;
water_Level = 80;
draw_Tank_Status(hdc, width, height);
}
cout << Tank_Empty << endl;
if(Tank_Empty)
{
cout << "Empty" << endl;
water_Level = 525;
draw_Tank_Status(hdc, width, height);
}
cout << Tank_Half_Filled << endl;
if(Tank_Half_Filled)
{
cout << "Half-Filled" << endl;
water_Level = 300;
draw_Tank_Status(hdc, width, height);
}
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
case WM_CLOSE :
PostQuitMessage(EXIT_SUCCESS);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
void draw_Tank_Status(HDC hdc, int width, int height)
{
HBRUSH hbrush;
HPEN hpen;
//draw a rectangle with color blue TANK
hpen = CreatePen(PS_SOLID, 4, RGB(0, 51, 51));
SelectObject(hdc, hpen);
Rectangle(hdc, 160, 80, width - 200, height - 20);
DeleteObject(hpen);
// Water
// Full - 80
// Half - 300
// Empty - 525
hpen = CreatePen(PS_SOLID, 4, RGB(51, 255, 255));
hbrush = CreateSolidBrush(RGB(51, 255, 255));
SelectObject(hdc, hpen);
SelectObject(hdc, hbrush);
Rectangle(hdc, 165, water_Level, width - 205, height - 25);
DeleteObject(hbrush);
DeleteObject(hpen);
}
| |