I'm having trouble with this windows program its in Visual C++ and it's my first time
really using and type of windows console.
I'm trying to get the program to where the program starts up there is nothing on the screen but then the user left clicks a 'X' appears and the user can click on the screen and make multiple X's on the screen.
// menu item
//#define IDM_LEFT 101
//#define IDM_RIGHT 102
//#define IDM_UP 103
//#define IDM_DOWN 104
#define IDM_RESET 107
#define IDM_QUIT 108
#define IDM_CLEAR 109
#define IDM_LINE 110
#define IDM_POLYNOMIAL 111
// trim the excess fat from Windows
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdlib.h>
const int
xmin = 0, xmax = 330, xstart = 150,
ymin = 0, ymax = 205, ystart = 100;
int x = xstart, y = ystart;
void draw(HDC hDC) {
TCHAR str[256];
wsprintf(str, TEXT("X"), x, y);
//SetTextColor(hDC, COLORREF(0x000000FF)); // 00BBGGRR
SetTextColor(hDC, RGB(0xFF, 0x40, 0x80)); // RRGGBB
//SetBkColor(hDC, RGB(0x00, 0x00, 0x00)); // RRGGBB
SetBkMode(hDC,TRANSPARENT);
TextOut(hDC, x, y, str, (int)wcslen(str));
}
void createMenu(HWND hwnd) {
// menu without a resourse file
HMENU hMenu, hSubMenu; // local variable
hMenu = CreateMenu();
// submenu
hSubMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, TEXT("&File"));
AppendMenu(hSubMenu, MF_STRING, IDM_RESET, TEXT("R&eset"));
AppendMenu(hSubMenu, MF_SEPARATOR, 0, 0);
AppendMenu(hSubMenu, MF_STRING, IDM_QUIT, TEXT("&Quit"));
// no submenu
//AppendMenu(hMenu, MF_STRING, IDM_LEFT, TEXT("&Left"));
//AppendMenu(hMenu, MF_STRING, IDM_RIGHT, TEXT("&Right"));
//AppendMenu(hMenu, MF_STRING, IDM_UP, TEXT("&Up"));
//AppendMenu(hMenu, MF_STRING, IDM_DOWN, TEXT("&Down"));
AppendMenu(hMenu, MF_STRING, IDM_LINE, TEXT("&Line"));
AppendMenu(hMenu, MF_STRING, IDM_POLYNOMIAL, TEXT("&Polynomial"));
AppendMenu(hMenu, MF_STRING, IDM_CLEAR, TEXT("&Clear"));
SetMenu(hwnd, hMenu);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
switch(msg)
{
case WM_CREATE:
createMenu(hwnd); //commented out
break;
case WM_PAINT:
hDC = BeginPaint(hwnd,&ps);
draw(hDC);
EndPaint(hwnd,&ps);
break;
case WM_LBUTTONDOWN: // mouse
x = LOWORD(lParam);
y = HIWORD(lParam);
InvalidateRect(hwnd, NULL, TRUE); // call WM_PAINT
break;
case WM_RBUTTONDOWN: // mouse
break;
case WM_COMMAND: // menu
switch(LOWORD(wParam)) {
case IDM_RESET:
x = xstart;
y = ystart;
InvalidateRect(hwnd,NULL,TRUE); // call WM_PAINT
break;
case IDM_QUIT:
PostQuitMessage(0);
break;
case IDM_CLEAR:
x = 0;
y = 0;
InvalidateRect(hwnd,NULL,TRUE);
break;
}
break;
case WM_KEYDOWN: // key
{
switch(wParam) {
case 'Q':
case VK_ESCAPE:
PostQuitMessage(WM_QUIT);
break;
default:
break;
}
break;
}
case WM_DESTROY:
PostQuitMessage(WM_QUIT);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG msg;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = TEXT("Example");
wc.hInstance = hInstance;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hbrBackground = (HBRUSH)(BLACK_BRUSH);
//wc.lpszMenuName = NULL;
wc.lpszMenuName = TEXT(" Draw Lines"); // changed from NULL
// Window color
//wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
//wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
//wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
//wc.hbrBackground = CreateSolidBrush(RGB(0xFF, 0xC0, 0x80)); // RRGGBB
wc.hbrBackground = CreateSolidBrush(COLORREF(0x00C0FFE0)); // 00BBGGRR
RegisterClassEx(&wc);
//if (!RegisterClassEx(&wc)) return -1;
// not using CreateWindowEx(...)
hwnd = CreateWindow(
TEXT("Example"), TEXT(" Draw Lines"),
WS_OVERLAPPEDWINDOW ,
0, 0, 400, 300,
NULL, NULL, hInstance, NULL);
//if (!hwnd) return -1;
ShowWindow(hwnd, nCmdShow); // this is required
//UpdateWindow(hwnd);
while (true)
{ if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == 0) continue;
if (msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}