winapi mein erstes fenster

sumpfhuhn

Gesperrt
morgen,

hab mich mal bissel mit winapi auseinander gesetzt. das is mein erstes fenster. bloß gehts net. für was is stdafx.h den header hat vc++ erstellt.

Code:
#include "stdafx.h"
#include <windows.h>
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	WNDCLASS WndClass;
	WndClass.style = 0;
	WndClass.cbClsExtra = 0;
	WndClass.cbWndExra = 0;
	WndClass.1pfnWndProc = WndProc;
	WndClass.hInstance = hInstance;
	WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
	WndClass.hCursor = 0;
	WndClass.hIcon = 0;
	WndClass.1pszMenuName = 0;
	WndClass.lpszClassName = "Winproc";
	
	RegisterClass(&WndClass);
	HWND hWindow;
	hWindow = CreateWindow("Winproc","Fenster",
		WS_OVERLAPPEDWINDOW,
		0,0,400,400,NULL,NULL,
		hInstance, NULL);
	ShowWindow (hWindow, nCmdShow);
	UpdateWindow (hWindow);
	MSG Message;
	while (GetMessage(&Message, NULL, 0, 0))
	{
		DispatchMessage(&Message);
	}
	return (Message.wParam);
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage,
						  WPARM WPARAM wParam,LPARAM lParam)
{
	switch(uiMessage)
	{
	case WM_DESTROY:
		POSTQUITMESSAGE(0);
		return 0;
	default: 
		return DefWindowProc (hWnd, uiMessage,
			WParam, lParam);
	}
}
}

fehler beim compilieren:
neu1\neu1.cpp(2) : fatal error C1083: Cannot open precompiled header file: 'Debug/neu1.pch': No such file or directory

das is die header datei:

Code:
// stdafx.cpp : source file that includes just the standard includes
//	neu1.pch will be the pre-compiled header
//	stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

und ohne diesen header kommt das:

cpp(48) : fatal error C1010: unexpected end of file while looking for precompiled header directive

thx bye :)
 
Zuletzt bearbeitet:
Äh, jetzt muß ich aber schon fragen:
Das isn Scherz, oder?
Hast du das abgetippt oder per c&p reingesetzt??

Das sind so dermaßen viele Fehler drin (die man aber per Compilermeldung locker findet):
z.B:
In der Zeile "WndClass.1pszMenuName = 0;" steht nach dem Punkt eine 1 - muß aber ein l sein.
(kam noch öfter vor, wo ein l stehen sollte)

Deine WndProc mußt du natürlich als Prototypen bekannt geben oder komplett vor die WinMain setzen.

Dann hast du geschrieben
"LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage,
WPARM WPARAM wParam,LPARAM lParam)"

Was ist das: WPARM WPARAM ??? -> kann auch nicht gehen.
Außerdem war ne Klammer am Schluß zu viel...

Egal, habs jetzt einfach mal die Fehler soweit raus und einfach mal nur zum Laufen gebracht:

Code:
#include <windows.h>
LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage, WPARAM wParam,LPARAM lParam)
{
	switch(uiMessage)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	default: 
		return DefWindowProc (hWnd, uiMessage,
			wParam, lParam);
	}
}

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	WNDCLASS WndClass;
	WndClass.style = 0;
	WndClass.cbClsExtra = 0;
	WndClass.cbWndExtra = 0;
	WndClass.lpfnWndProc = WndProc;
	WndClass.hInstance = hInstance;
	WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
	WndClass.hCursor = 0;
	WndClass.hIcon = 0;
	WndClass.lpszMenuName = 0;
	WndClass.lpszClassName = "Winproc";
	
	RegisterClass(&WndClass);
	HWND hWindow;
	hWindow = CreateWindow("Winproc","Fenster",
		WS_OVERLAPPEDWINDOW,
		0,0,400,400,NULL,NULL,
		hInstance, NULL);
	ShowWindow (hWindow, nCmdShow);
	UpdateWindow (hWindow);
	MSG Message;
	while (GetMessage(&Message, NULL, 0, 0))
	{
		DispatchMessage(&Message);
	}
	return (Message.wParam);
}

btw: sonderlich schön ist das ja nicht gerade... (aber wenns das erste Fenster is... ;) )
 

Neue Beiträge

Zurück