Hej Udvikleren
Jeg har lige læst et kæmpe afsnit om c++ objekt orienteret programmering. Jeg er begyndt på Win32 API'et. Og det har givet en del Fejl. Jeg er 100% sikker på at koden er skrevet ligesom der står i den bog jeg lærer af. Jeg bruger Visual c++ til at compilere programmet.
BUILD LOG Build started: Project: Firstwin32, Configuration: Debug|Win32
Command Lines
Creating temporary file "c:\Users\Bruger\Desktop\c++ projekter\Firstwin32\Firstwin32\Debug\RSP00003B38529292.rsp" with contents
[
/Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc90.pdb" /W3 /c /ZI /TP ".\first.cpp"
]
Creating command line "cl.exe @"c:\Users\Bruger\Desktop\c++ projekter\Firstwin32\Firstwin32\Debug\RSP00003B38529292.rsp" /nologo /errorReport:prompt"
Output Window
Compiling...
first.cpp
c:\users\bruger\desktop\c++ projekter\firstwin32\firstwin32\first.cpp(15) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\bruger\desktop\c++ projekter\firstwin32\firstwin32\first.cpp(49) : error C2440: '=' : cannot convert from 'const char [15]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\bruger\desktop\c++ projekter\firstwin32\firstwin32\first.cpp(55) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [15]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\users\bruger\desktop\c++ projekter\firstwin32\firstwin32\first.cpp(58) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [22]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Results
Build log was saved at "file://c:\Users\Bruger\Desktop\c++ projekter\Firstwin32\Firstwin32\Debug\BuildLog.htm"
Firstwin32 - 4 error(s), 0 warning(s)
Koden er her:
#include <windows.h>
// Store handles to the main window and application
// instance globally.
HWND ghMainWnd = 0;
HINSTANCE ghAppInst = 0;
// Step 1: Define and implement the window procedure.
LRESULT CALLBACK
WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
// Handle left mouse button click message.
case WM_LBUTTONDOWN:
MessageBox(0, "WM_LBUTTONDOWN message.", "Msg", MB_OK);
return 0;
// Handle key down message.
case WM_KEYDOWN:
if( wParam == VK_ESCAPE )
DestroyWindow(ghMainWnd);
return 0;
// Handle destroy window message.
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
// Forward any other messages we didn't handle to the
// default window procedure.
return DefWindowProc(hWnd, msg, wParam, lParam);
}
// WinMain: Entry point for a Windows application.
int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR cmdLine, int showCmd)
{
// Save handle to application instance.
ghAppInst = hInstance;
// Step 2: Fill out a WNDCLASS instance.
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = ghAppInst;
wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
wc.hCursor = ::LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = "MyWndClassName";
// Step 3: Register the WNDCLASS instance with Windows.
RegisterClass( &wc );
// Step 4: Create the window, and save handle in globla
// window handle variable ghMainWnd.
ghMainWnd = ::CreateWindow("MyWndClassName", "MyWindow",
WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, 0, 0, ghAppInst, 0);
if(ghMainWnd == 0)
{
::MessageBox(0, "CreateWindow - Failed", 0, 0);
return false;
}
// Step 5: Show and update the window.
ShowWindow(ghMainWnd, showCmd);
UpdateWindow(ghMainWnd);
// Step 6: Enter the message loop and don't quit until
// a WM_QUIT message is received.
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
while( GetMessage(&msg, 0, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Return exit code back to operating system.
return (int)msg.wParam;
}