Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Hi Leute. Ich krieg die Krise. Das ist das erste Programm aus dem Buch "Win98 programmieren für Dummies" und es klappt nit. Es soll einfach ein Fenster erzeugt werden, in dem "Hello World " steht. Aber irgendwas geht bei CreateWindow schief. Hier ist das Programm



#include "windows.h"


int WINAPI WinMain(HINSTANCE hInstance,

                     HINSTANCE hPrevInstance,

                     LPSTR     lpCmdLine,

                     int       nCmdShow );



LRESULT CALLBACK WindowProc(HWND hWnd,

                            UINT uMsgId,

                            WPARAM wParam,

                            LPARAM lParam);




int WINAPI WinMain(HINSTANCE hInstance,

                     HINSTANCE hPrevInstance,

                     LPSTR     lpCmdLine,

                     int       nCmdShow )

{

    static char szAppName[]= "Prog1";

    HWND hWnd;

    MSG msg;

    WNDCLASSEX wndClass;


    wndClass.style=0;

    wndClass.lpfnWndProc=WindowProc;

    wndClass.cbClsExtra=0;

    wndClass.cbWndExtra=0;

    wndClass.hInstance=hInstance;

    wndClass.hIcon=LoadIcon(hInstance,szAppName);

    wndClass.hCursor=LoadCursor(NULL,IDC_ARROW);

    wndClass.hbrBackground= (HBRUSH) GetStockObject(WHITE_BRUSH);

    wndClass.lpszMenuName=NULL;

    wndClass.lpszClassName=szAppName;

    wndClass.hIconSm=wndClass.hIcon;


    if(RegisterClassEx(&wndClass)==0)

        return 0;


    hWnd=CreateWindow(szAppName,

                      szAppName,

                      WS_OVERLAPPEDWINDOW,

                      CW_USEDEFAULT,

                      CW_USEDEFAULT,

                      CW_USEDEFAULT,

                      CW_USEDEFAULT,

                      NULL,

                      NULL,

                      hInstance,

                      NULL);


    if(hWnd==NULL)

        return 0;


    ShowWindow(hWnd,nCmdShow);

    UpdateWindow(hWnd);


    while(GetMessage(&msg,NULL,0,0))

    {

        TranslateMessage(&msg);

        DispatchMessage(&msg);

    }

    return msg.wParam;

}



LRESULT CALLBACK WindowProc(HWND hWnd,

                            UINT uMsgId,

                            WPARAM wParam,

                            LPARAM lParam)


{

    static char *pszHello = " Hello World";


    switch(uMsgId)

    {

    case WM_PAINT:

        {

            HDC hDC;

            PAINTSTRUCT paintStruct;


            hDC =BeginPaint (hWnd,&paintStruct);


            TextOut(hDC,

                0,

                0,

                pszHello,

                lstrlen(pszHello));


            EndPaint(hWnd,&paintStruct);

        }

        break;


    case WM_DESTROY:

        PostQuitMessage(0);

        break;


    default: return DefWindowProc(hWnd,uMsgId,wParam,lParam);

    }




    return 0;

}

Ich wäre sehr dankbar,wenn mir jemand helfen könnte!

Ähm, ist das das erste was Du zum Programmieren lernst? Oder hast DU schon Grundkenntnisse?

Weil ich das als erstes Programm (was 'HalloWelt' meistens ist) schon ganz schön kompliziert finde!

Bine

Nee, ich hab schon ne weile reines C++ programmiert und will jetzt ein wenig in die reine Windows-Programmierung reinschnuppern, bevor ich mir MFC anschaue. ;)

Hast recht. Wundert mich nur, das das im Buch nicht da steht. Aber Danke für den Tip!!

hihihi, aller anfang ist schwer :D

hast du es inzwischen hingekriegt?

Nein, eben nicht. Das Programm wurde ohne Fehler und ohne Warnungen kompiliert. Und im Buch war diese Zeile

wndClass.cbSize = sizeof( WNDCLASSEX );

nicht im Listing. Hab extra 10 nachgeschaut.

Aber jetzt läuft es ja und ich kann (hoffentlich) ungehindert weiter lernen. Es gibt noch viel zu tun...

Das ist aber ein allgemeines Problem - nicht nur bei Listings aus Büchern. In meinen Büchern sind teilweise extrem viele Fehler. Spitzenreiter der ganz üblen Sorte war das "C++ in 21 Tagen" von Markt & Technik, welches aber abgesehen von den Fehlern sonst inhaltlich recht gut ist. Das ist der Grund, wieso ich von jedem Bereich mindestens 2 Bücher im Regal stehen habe um eventuelle logische oder getippte Fehler nochmal korrigieren zu können.

Original geschrieben von Woodstock

Weil ich das als erstes Programm (was 'HalloWelt' meistens ist) schon ganz schön kompliziert finde!

Bine

*lach*

Stimmt, aber kann "HelloWorld" noch viel mehr aufblähen siehe:

http://www.codeproject.com/com/HelloTutorial1.asp

Aber dient natürlich auch nur zum Lernen :OD

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.