I'm pretty desperate here. I have created a halfway decent program that is short but useful. It loads a text file and displays the file contents line-by-line to a window. The problem is that my mouse icon, when in the window, after the window is displayed, displays a hollow circle that keeps spinning, as if the program is not finished performing a task yet. And when I hover over the edges of the window, so that I can resize them, and then move the mouse into the white area of the window where you should not have the horizontal or vertical resize mouse icons, they still appear there. I'm very sorry for posting this long code, but I really am getting into windows programming. I'm tired of not knowing the proper way to do things,
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = {};
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
L"Learn to Program Windows", // Window text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
);
if (hwnd == NULL)
{
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Run the message loop.
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static vector <wstring> strings;
static int cxChar, cxCaps, cyChar;
HDC hdc;
TEXTMETRIC tm;
PAINTSTRUCT ps;
RECT rect;
switch (msg)
{
case WM_CREATE:
{
wifstream junkFile("C:\\Users\\Lee\\Documents\\junk.txt");
if (!junkFile)
{
MessageBox(NULL, L"Couldn't open file", L"Error", MB_OK);
return 1;
}
std::wstring myString;
getline(junkFile, myString);
strings.push_back(myString);
while (!junkFile.eof())
{
getline(junkFile, myString);
strings.push_back(myString);
}
junkFile.close();
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cxCaps = (tm.tmPitchAndFamily & 1? 3: 2) * cxChar /2;
cyChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC(hwnd, hdc);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
case WM_PAINT:
{
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
FillRect(hdc, &rect, (HBRUSH) (COLOR_WINDOW + 1));
wstring temp;
for (int i = 0; i < (int)strings.size(); i++)
{
temp = strings;
TextOut(hdc, 0, cyChar*i, temp.c_str(), temp.size());
}
EndPaint(hwnd, &ps);
return 0;
}
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}