cwinapi messagebox mit passwortabfrage



  • In MsgBox password eingeben ? 😃 😃
    Mach dir eigenes Fenster für Password eingabe.





  • Mr C schrieb:

    für Anfang sollte reichen:
    https://latedev.wordpress.com/2011/10/08/simple-windows-dialogs-from-c-part-2/
    http://www.cplusplus.com/articles/E6vU7k9E/#WIN-e1

    Die Vorschläge sehen alle ok aus.

    Ein Dialog mit einem Edit-Control mit dem Style "ES_PASSWORD" würde wohl der
    gewünschten Lösung entsprechen.



  • Ich hatte da mal 'ne gute Bibliothek entdeckt, weiss nicht mehr wo und wie die genau hieß, war wohl von Trollsoft. Ich hatte den Eindruck die ist für Leute gemacht die noch nicht oft bis nie programmiert haben und die es sich gerne einfach machen. Ich fang gleich mal an zu suchen vieleicht find ich sie ja wieder, dann ich geb dir dann hier Bescheid und füg auch noch ein Codebeispiel mit dazu.



  • hi.kann mir mal einer erklaeren wieso der code nicht funkt.

    #include <windows.h>

    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

    /* Make the class name into a global variable */


    LPCTSTR Caption = L"Application Programming Interface";

    int WINAPI WinMain (HINSTANCE hThisInstance,
    HINSTANCE hPrevInstance,
    LPCTSTR lpszArgument,
    int nCmdShow)
    {

    MessageBox( NULL,
    L"Welcome to Win32 Application Development\n"
    L"You will learn about functions, classes, "
    L"communication, and other cool stuff\n"
    L"Are you ready to rumble!!!!!!!!!!!!!!",
    Caption,
    MB_YESNOCANCEL | MB_ICONQUESTION);

    return 0;

    HWND hwnd; /* This is the handle for our window /
    MSG messages; /
    Here messages to the application are saved /
    WNDCLASSEX wincl; /
    Data structure for the windowclass */

    /* The Window structure /
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure; /
    This function is called by windows /
    wincl.style = CS_DBLCLKS; /
    Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer /
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL; /
    No menu /
    wincl.cbClsExtra = 0; /
    No extra bytes after the window class /
    wincl.cbWndExtra = 0; /
    structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
    return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
    0, /* Extended possibilites for variation /
    szClassName, /
    Classname /
    "Code::Blocks Template Windows App", /
    Title Text /
    WS_OVERLAPPEDWINDOW, /
    default window /
    CW_USEDEFAULT, /
    Windows decides the position /
    CW_USEDEFAULT, /
    where the window ends up on the screen /
    544, /
    The programs width /
    375, /
    and height in pixels /
    HWND_DESKTOP, /
    The window is a child-window to desktop /
    NULL, /
    No menu /
    hThisInstance, /
    Program Instance handler /
    NULL /
    No Window Creation data */
    );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
    /* Translate virtual-key messages into character messages */
    TranslateMessage(&messages);
    /* Send message to WindowProcedure */
    DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
    }

    /* This function is called by the Windows function DispatchMessage() */

    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch (message) /* handle the messages /
    {
    case WM_DESTROY:
    PostQuitMessage (0); /
    send a WM_QUIT to the message queue /
    break;
    default: /
    for messages that we don't deal with */
    return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
    }

    compiler meldet cannot convert const wchar_t to const CHAR



  • hab jetzt den code und der compiler sagt 0 errors und warnings aber kompiliert nicht

    #include <windows.h>

    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

    /* Make the class name into a global variable */


    LPCTSTR Caption = "Application Programming Interface";

    int WINAPI WinMain (HINSTANCE hThisInstance,
    HINSTANCE hPrevInstance,
    LPCTSTR lpszArgument,
    int nCmdShow)
    {

    MessageBox( NULL,
    "Welcome to Win32 Application Development\n"
    "You will learn about functions, classes, "
    "communication, and other cool stuff\n"
    "Are you ready to rumble!!!!!!!!!!!!!!",
    Caption,
    MB_YESNOCANCEL | MB_ICONQUESTION);

    return 0;

    HWND hwnd; /* This is the handle for our window /
    MSG messages; /
    Here messages to the application are saved /
    WNDCLASSEX wincl; /
    Data structure for the windowclass */

    /* The Window structure /
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure; /
    This function is called by windows /
    wincl.style = CS_DBLCLKS; /
    Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer /
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL; /
    No menu /
    wincl.cbClsExtra = 0; /
    No extra bytes after the window class /
    wincl.cbWndExtra = 0; /
    structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
    return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
    0, /* Extended possibilites for variation /
    szClassName, /
    Classname /
    "Code::Blocks Template Windows App", /
    Title Text /
    WS_OVERLAPPEDWINDOW, /
    default window /
    CW_USEDEFAULT, /
    Windows decides the position /
    CW_USEDEFAULT, /
    where the window ends up on the screen /
    544, /
    The programs width /
    375, /
    and height in pixels /
    HWND_DESKTOP, /
    The window is a child-window to desktop /
    NULL, /
    No menu /
    hThisInstance, /
    Program Instance handler /
    NULL /
    No Window Creation data */
    );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
    /* Translate virtual-key messages into character messages */
    TranslateMessage(&messages);
    /* Send message to WindowProcedure */
    DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
    }

    /* This function is called by the Windows function DispatchMessage() */

    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch (message) /* handle the messages /
    {
    case WM_DESTROY:
    PostQuitMessage (0); /
    send a WM_QUIT to the message queue /
    break;
    default: /
    for messages that we don't deal with */
    return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
    }



  • Liegt an den fehlenden Codetags.



  • sean1612 schrieb:

    hab jetzt den code und der compiler sagt 0 errors und warnings aber kompiliert nicht

    Das widersricht sich ja schonmal selbst.

    LPCTSTR Caption = "Application Programming Interface";
    

    kommentiert VS mit:

    error C2440: 'Initialisierung': 'const char [34]' kann nicht in 'LPCTSTR' konvertiert werden.
    

    Wenn man Unicode (default=on) abschaltet, gehts (mit Schmerzen) weiter bis:

    error C2731: 'WinMain': Überladen der Funktion nicht möglich
    

    Was wohl an "LPCTSTR lpszArgument" liegt.

    Wenn man das ausbessert und mindestens das return auskommentiert kann man
    die Applikation starten und es kommt das erwartbare Ergebnis.

    Das man Code-Tags verwenden sollte wurde ja schon angemerkt.

    Wie man Zeichenketten UNICODE konform definiert solltest du dir ansehen.

    Soll der Code zur ursprünglichen Frage passen?



  • Beispiel für die ursprüngliche Frage:

    How to Create a Single Line Edit Control
    https://msdn.microsoft.com/de-de/library/windows/desktop/hh298434.aspx



  • Um dann jetzt doch einfach mal auf die Frage zu antworten: Die gesuchte Funktion heißt CredUIPromptForWindowsCredentials. Allerdings funktioniert nur die W Version. Nur mal für Spaß:

    #include <Windows.h>
    #include <tchar.h>
    #include <CommCtrl.h>
    #include <wincred.h>
    
    EXTERN_C int WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, int)
    {
        CREDUI_INFO ui = {};
        ULONG package = 0, size = 0;
        void* pBuffer = nullptr;
    
        ui.cbSize = sizeof(ui);
        ui.pszMessageText = TEXT("My MessageText");
        ui.pszCaptionText = TEXT("My CaptionText");
    
        InitCommonControls();
        if(ERROR_SUCCESS == CredUIPromptForWindowsCredentials(&ui, 0, &package, nullptr, 0, &pBuffer, &size, nullptr, CREDUIWIN_GENERIC))
        {
            SecureZeroMemory(pBuffer, size);
            CoTaskMemFree(pBuffer);
        }
    
        return(0);
    }
    

Anmelden zum Antworten