Staram się użyć w programie struktury, kłopot mam z VisualStudio19.
static const struct {
TCHAR *pszText;
int cx;
}
columnMap[] = {
{ _T("Tytul1"), 150 },
{ _T("Tytul2"), 60 },
{ _T("Tytul3"), 120 },
{ 0 }
};
static const struct {
TCHAR *pszName;
TCHAR *pszPriority;
int iProgress;
}
taskMap[] = {
{ _T("Zmienna1"), _T("Zmienna2"), 15 },
{ 0 }
};
Błąd który otrzymuje:
Error (active) E0144 a value of type "const wchar_t *" cannot be used to initialize an entity of type "TCHAR *" Przyklad E:\Programowanie\VisualStudio\VC2019-Projekty\Przyklad\Source\WinApplication.cpp 43
Nie mam problemu z tym kawałkiem kodu w CodeBuilder.
Mam wrażenie że muszę coś ustawić we właściwościach projektu.
Zmieniałem Character Set z 3 opcjami, ale nie zaskoczyło.
Cała moja piaskownica:
#include <Windows.h>
#include <tchar.h>
#include <commctrl.h>
#include <string.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
using namespace std;
/*
static struct {
TCHAR* pszText;
int cx;
}
columnMap[] = {
{ _T("Tytul1"), 150 },
{ _T("Tytul2"), 60 },
{ _T("Tytul3"), 120 },
{ 0 }
};
static const struct {
TCHAR* pszName;
TCHAR* pszPriority;
int iProgress;
}
taskMap[] = {
{ _T("Zmienna1"), _T("Zmienna2"), 15 },
{ 0 }
};
*/
class Plik
{
private:
fstream fileStream;
string SciezkaDoPliku;
streampos RozmiarPliku;
streampos WczytanychBajtow;
public:
Plik(const std::string _SciezkaDoPliku)
: SciezkaDoPliku{ _SciezkaDoPliku },
RozmiarPliku{ 0 },
WczytanychBajtow{ 0 }
{
this->SciezkaDoPliku = _SciezkaDoPliku;
fstream fileStream(SciezkaDoPliku.c_str());
}
~Plik() {
if (fileStream.is_open()) {
Close();
}
}
void Close() //Zamkniecie lacza z plikiem.
{
if (fileStream.is_open())
fileStream.clear();
fileStream.close();
}
int Open(HWND hwnd)
{
fileStream.open(SciezkaDoPliku.c_str(), ios::in | ios::binary | ios::ate);
if (!fileStream.is_open()) {
SetWindowText(hwnd, TEXT("Nie udalo sie otworzyc pliku.\r\n"));
return 1;
}
return 0;
}
};
static HWND button;
static HWND textBoxOutput;
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int nCmdShow)
{
HWND hMainWindow;
WNDCLASS wc = {};
wc.lpfnWndProc = WindowProc;
wc.lpszClassName = L"Main window class";
wc.hInstance = hInstance;
RegisterClass(&wc);
hMainWindow = CreateWindow(wc.lpszClassName, L"Append text main window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 400, NULL, NULL, hInstance, NULL);
if (hMainWindow == NULL) return 1;
button = CreateWindowEx(WS_EX_CLIENTEDGE, L"Button", L"Append", WS_CHILD | WS_VISIBLE | ES_CENTER, 10, 41, 75, 30, hMainWindow, NULL, NULL, NULL);
textBoxOutput = CreateWindowEx(WS_EX_CLIENTEDGE, L"Edit", TEXT(""), WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY, 10, 81, 450, 150, hMainWindow, NULL, NULL, NULL);
ShowWindow(hMainWindow, SW_SHOW);
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
if ((HWND)lParam == button)
{
Plik p1("d:\\test1.txt");
p1.Open(textBoxOutput);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
Zakomentowałem wstawione struktury które mi nie działają.