Hier der Beispiel Code fuer ein kleines Dialog Programm. Ich selber bin vor geraumer Zeit auf die MFC umgestiegen, weil sie doch wesentlich bequemer ist. Allerdings habe ich beim Win32 API Programmieren vieles gebraucht was ich immer mal wieder gebrauchen kann. Der Code ist so nicht lauffaehig, er braeuchte noch ein Resource Header File (resource.h), und ausserdem muesste eine Resourcedatei (*.rc) mit im Projekt sein welches Dialoge und Menues definiert. Allerdings kannst du den Krempel auch erst einmal herausnehmen, aber dann hast du wirklich nur ein Fenster. Ich glaube du musst eine Win32 Console Application erstellen.:
#define STRICT
#include
#include
#include
#include
#include "resource.h"
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsgId, WPARAM wParam, LPARAM lParam );
BOOL CALLBACK DlgProc( HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
HINSTANCE globalHInstance;
int WINAPI WinMain(
HINSTANCE hInstance, // Handle der aktuellen Instanz
HINSTANCE hPrevInstance, // Handle der vorher gehenden Instanz (?allways zero?)
LPSTR pszCmdLine, // pointer to command line (if prog was started over a command line)
int nCmdShow // Fensterstatus
)
{
static char szAppName[] = "TimerTest";
HWND hWnd;
MSG msg;
WNDCLASSEX wndClass;
globalHInstance = hInstance;
// zuerst die Fensterklasse registrieren
wndClass.cbSize = sizeof(wndClass);
wndClass.style = 0 ;
wndClass.lpfnWndProc = WndProc;
// Rückruf-Funktion (Callback-Funktion)
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = 0;
wndClass.hCursor = 0;
wndClass.hbrBackground = (HBRUSH\_\_ \*)GetStockObject (WHITE\_BRUSH); //don't know why I have to
//cast that
wndClass.lpszMenuName = MAKEINTRESOURCE( MENUNAME ); //here the identifier of the Menu that should be used, set to NULL if you don't want a menu yet
//menu must be in a resource file
wndClass.lpszClassName = szAppName;
wndClass.hIconSm = 0;
if ( !RegisterClassEx(&wndClass) ) return 0;
// Nun das Fenster der Anwendung erzeugen
hWnd = CreateWindow(
szAppName, // name of the windowclass!! this must be a registerd one
szAppName, // Fenstertitel
WS\_OVERLAPPEDWINDOW,// Fensterstil
CW\_USEDEFAULT, // initiale X- und...
CW\_USEDEFAULT, // ...Y-Position CW\_USEDEFAULT
CW\_USEDEFAULT, // Fenstergröße in vertikaler
CW\_USEDEFAULT, // und horizontaler Ausrichtung
NULL, // Handle des Elternfensters
NULL, // Handle für das Menü
hInstance,// Handle der Programminstanz
NULL); // Parameter für die Erzeugung
if ( hWnd == NULL ) return 0;
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
while ( GetMessage(&msg, NULL, 0, 0) ) // message processing queue
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(
HWND hWnd, // Handle des Fensters
UINT uMsgId, // Nachrichtenkennung
WPARAM wParam, // Erster Parameter
// der Nachricht
LPARAM lParam) // Zweiter Parameter
{
switch ( uMsgId )
{
// Abarbeiten
case WM\_LBUTTONDOWN:
{
DialogBox(globalHInstance, MAKEINTRESOURCE(DIALOG\_NAME), hWnd, DlgProc);
//this create a dialog from a template that must be given in a resource file, remove this if you don't to do this on a left click (was only for testing for myself)
break;
}
case WM\_PAINT:
{
HDC hDC;
PAINTSTRUCT paintStruct;
hDC = BeginPaint( hWnd, &paintStruct );
EndPaint( hWnd, &paintStruct );
break;
}
case WM\_DESTROY:
PostQuitMessage(0);
break;
default:
// Windows die Abarbeitung aller anderen
// Nachrichten überlassen
return DefWindowProc(hWnd, uMsgId, wParam, lParam);
}
return( 0 );
}
// is only needed for the Dialog
BOOL CALLBACK DlgProc( HWND hWndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam,// first message parameter
LPARAM lParam)// second message parameter
{
switch(uMsg)
{
case WM\_COMMAND:
switch(wParam)
{
case IDOK:
EndDialog(hWndDlg, 1);
break;
case IDCANCEL:
EndDialog(hWndDlg, 1);
break;
default
return FALSE;
}
break;
default:
return FALSE;
}
return TRUE;
}
Falls du noch fragen hast melde dich noch einmal.
Gruss Ben