ERLEDIGT
NEIN
NEIN
ANTWORTEN
3
3
ZUGRIFFE
553
553
EMPFEHLEN
-
16.08.10 23:11 #1
- Registriert seit
- Aug 2007
- Beiträge
- 328
Hi,
ich habe angefangen mich mit C++ und der Windows API zu beschäftigen. Ich hab einige Tutorials gefunden, um ein einfaches Fenster zu erzeugen. Leider bekomm ich bei allen Tutorials den gleichen Fehler:
Hier mein Quellcode
Code cpp: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
#include <windows.h> LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); const char *lpszAppName = "AppName"; const char *lpszTitle = "Meine erste Applikation"; int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hWnd; MSG msg; WNDCLASSEX wc; wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL,IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszClassName = lpszAppName; wc.lpszMenuName = lpszAppName; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if( RegisterClassEx(&wc) == 0) return 0; hWnd = CreateWindowEx(NULL, lpszAppName, lpszTitle, WS_OVERLAPPEDWINDOW, 0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); if( hWnd == NULL) return 0; ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT umsg, WPARAM wParam, LPARAM lParam) { switch (umsg) { case WM_DESTROY: { PostQuitMessage(0); return 0; } } return DefWindowProc(hWnd, umsg, wParam, lParam); }
Die Fehlermeldung ist immer:
Kann mir jemand weiterhelfen?1>c:\users\roman\documents\visual studio 2008\projects\mapeditorv2\mapeditorv2\main.cpp(22) : error C2440: '=' : cannot convert from 'const char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\roman\documents\visual studio 2008\projects\mapeditorv2\mapeditorv2\main.cpp(23) : error C2440: '=' : cannot convert from 'const char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Ich bin zeimlicher Anfänger was C++ angeht. Wenn jemand Lust hat mir ab und zu bei Problemen weiterzuhelfen, kann sich ja mal im ICQ bei mir melden. Meine Nummer ist 70143741
Gruß
-
Hallo,
anhand der Fehlermeldung gehe ich davon aus, dass du mit Visual Studio programmierst. Hier werden alle Projekte standardmäßig mit Unicode-Unterstützung angelegt. Da gibt es für dich jetzt zwei Möglichkeiten:
1. In den Projekteinstellungen bei "Konfigurationseigenschaften" und "Allgemein" bei Zeichensatz von Unicode auf Multi-Byte umstellen.
2. Statt "char" "TCHAR" verwenden und für alle Zeichenkettendefinitionen das "_T" - Makro verwenden, z.B:
GrußCode cpp:1
const TCHAR *lpszAppName = _T("AppName");
MCoder"The three chief virtues of a programmer are: Laziness, Impatience and Hubris."
--- Larry Wall
-
Hey,
ich programmiere auch WinAPI, aber ich hab bei meinen szAppName's kein * dran.
Versuche es mal ohne:
Code :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
LRESULT CALLBACK MainProc(HWND, UINT, WPARAM, LPARAM); //Hauptfenster const char szMainname[] = "Beispielprogramm"; int iWindowX = 320; int iWindowY = 640; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { WNDCLASS wc; HWND hWnd; MSG msg; hGlobalInstance = hInstance; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = MainProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, "Icon.ico"); //Falls kein Icon da: IDI_APPLICATION wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0)); wc.lpszClassName = szMainname; wc.lpszMenuName = NULL; RegisterClass(&wc); hWnd = CreateWindow(szMainname, szMainname, WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, GetSystemMetrics(SM_CXSCREEN) / 2 - iWindowX / 2, GetSystemMetrics(SM_CYSCREEN) / 2 - iWindowY / 2, iWindowX, iWindowY, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; }
Viel Spaß noch...
Wenn meine Antwort nützlich bzw. hilfreich war, würde ich mich sehr über eine Bewertung bzw. ein Danke sehr freuen.
Danke euch
Programmiere in C, C++ auf Windows XP, Vista und Windows 7
Spezialisiert auf Netzwerkprogrammierung, WinAPI uvm.
-
27.08.10 16:37 #4
Du verwendest LPCWSTR!! Das heisst Unicode, deshalb musst du statt const char LPCWSTR schreiben
Damit müsste es gehen, da du keinen Cast von const char zu LPCWSTR machen kannstMein System: Windows 7 64bit, Visual Studio 2010 C++, Ubuntu 10.04, Anjuta (Ich programmiere vorwiegend in Windows)
Programmiersprache: C
Wenn mein Beitrag geholfen oder sonst gut war, freue ich mich immer über eine Bewertung oder ein Danke!
Meine Homepage
Ähnliche Themen
-
Anfänger-Problem
Von IFIllusion im Forum C/C++Antworten: 13Letzter Beitrag: 13.05.07, 20:01 -
php anfänger problem
Von vekTorbln im Forum PHPAntworten: 6Letzter Beitrag: 17.01.06, 00:46 -
Anfänger I/O-problem
Von zwob im Forum C/C++Antworten: 8Letzter Beitrag: 05.04.05, 08:49 -
Windows XP Home Edition und Windows 2000 Netzwerk Problem
Von Flap im Forum Microsoft WindowsAntworten: 8Letzter Beitrag: 18.11.04, 22:34 -
Anfänger > windows.h
Von drere im Forum VisualStudio & MFCAntworten: 12Letzter Beitrag: 18.03.04, 16:31





Zitieren
Login





