windows fenster
-
Hi, bis jetzt habe ich die ganze Zeit "nur" Konsolen Programme geschreiben, nun möchte ich mal ein ganz kleines Programm schreiben mit GUI, wieso gehst dieser Code nicht (Ist von einem Buch)
#include <windows.h> void malen(HDC hdc) { TextOut(hdc, 50, 50, "Hallo, Welt!", 12); }
Danke schon mal für das durchlesen
cya
-
Das gehört nicht zu Standard-C++, sondern zu WinAPI.
Wieso geht das denn aber nicht, wie rufst du die Funktion denn auf? :->
-
hmmm hab kein Plan im Buch stehts so weiss auch nicht wie malen aufgerufen wird, ich weiss auch nicht für was die Biblithek windows.h gut ist. Ich compile das ganze mit Visual Studio 6.0
-
hm... wie sich das anhört, hast du nch kein Fenster erstellt
schau mal vorbei auf
www.win-api.de zB oder Goggle mal nach WinAPI Tutorial
-
So sieht Hallo Welt als Win32 Anwendung aus
/* HelloWin.c - Zeigt "Hello Windows" in seinem Anwendgunsbereichan */ #include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); static TCHAR AppName[] = TEXT ("HelloWin"); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hwnd; MSG msg; WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = AppName; if (!RegisterClass (&wndclass)) { MessageBox ( NULL, TEXT ("Programm arbeitet mit UNICODE und setzt WinNT vorraus"), AppName, MB_ICONERROR ); return 0; } hwnd = CreateWindow ( AppName, // Name der Fensterklasse TEXT ("Das erste echte Programm"), // Fenstertitel WS_OVERLAPPEDWINDOW, // Fensterstil CW_USEDEFAULT, // X-Position des Fensters CW_USEDEFAULT, // Y-Position des Fensters CW_USEDEFAULT, // Fensterbreite CW_USEDEFAULT, // Fensterhöhe NULL, // Übergeordnetes Fenster NULL, // Menü hInstance, // Programmkopiezähler (Porgramm-ID) NULL // zusätzliche Parameter ); ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; RECT rect; switch (message) { case WM_CREATE: MessageBox (NULL, TEXT ("Willkommen"), AppName, 0); case WM_PAINT: hdc = BeginPaint (hwnd, &ps); GetClientRect (hwnd, &rect); DrawText ( hdc, TEXT ("Hallo Windows"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER ); EndPaint (hwnd, &ps); return 0; case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam); }
-
Hi Danke für die Hilfe, hab mir dieses Tut hier mal durchgelesen: http://www.win-api.de/tut01.html hat mir geholfen !