Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

WinApi Okno Dialogowe

Ostatnio zmodyfikowano 2015-03-28 12:10
Autor Wiadomość
Kalol
Temat założony przez niniejszego użytkownika
WinApi Okno Dialogowe
» 2015-03-19 10:59:41
Mam taki kod :

C/C++
#include <windows.h>
#define ID_PRZYCISK1 501
#define EXIT 502

HWND g_hPrzycisk;
HWND hButton2;
HWND hText;
HWND hText1;
HWND hText3;
HWND hText4;
HWND hText5;
HWND hText6;

/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc( HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam ) {
   
    switch( Message ) {
       
        /* Upon destruction, tell the main thread to stop */
    case WM_DESTROY: {
            PostQuitMessage( 0 );
        case WM_COMMAND:
            switch( wParam )
            {
            case ID_PRZYCISK1:
                MessageBox( hwnd, NULL, "Dane osobowe", MB_ICONINFORMATION );
               
                break;
            case EXIT:
                PostQuitMessage( 0 );
                break;
               
            }
            break;
           
        }
       
        /* All other messages (a lot of them) are processed using default procedures */
        default:
        return DefWindowProc( hwnd, Message, wParam, lParam );
    }
    return 0;
}

/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {
    WNDCLASSEX wc; /* A properties struct of our window */
    HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
    MSG Msg; /* A temporary location for all messages */
   
    /* zero out the struct and set the stuff we want to modify */
    memset( & wc, 0, sizeof( wc ) );
    wc.cbSize = sizeof( WNDCLASSEX );
    wc.lpfnWndProc = WndProc; /* This is where we will send messages to */
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
   
    /* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
    wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 );
    wc.lpszClassName = "WindowClass";
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); /* Load a standard icon */
    wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION ); /* use the name "A" to use the project icon */
   
   
    if( !RegisterClassEx( & wc ) ) {
        MessageBox( NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK );
        return 0;
    }
   
    hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, "WindowClass", "Kartoteka osobowa", WS_VISIBLE | WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, /* x */
    CW_USEDEFAULT, /* y */
    550, /* width */
    430, /* height */
    NULL, NULL, hInstance, NULL );
   
    g_hPrzycisk = CreateWindowEx( 0, "BUTTON", "Dane osobowe", WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
    10, 50, 505, 100, hwnd, NULL, hInstance, NULL );
   
    g_hPrzycisk = CreateWindowEx( 0, "BUTTON", "Adres", WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
    10, 200, 505, 100, hwnd, NULL, hInstance, NULL );
   
    HWND hText = CreateWindowEx( 0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 150, 80, 350, 20,
    hwnd, NULL, hInstance, NULL );
   
    HWND hText1 = CreateWindowEx( 0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 150, 105, 350, 20,
    hwnd, NULL, hInstance, NULL );
   
    hText4 = CreateWindowEx( 0, "EDIT", "Imie:", WS_CHILD | WS_VISIBLE,
    50, 80, 80, 30, hwnd, NULL, hInstance, NULL );
   
    hText5 = CreateWindowEx( 0, "EDIT", "Nazwisko:", WS_CHILD | WS_VISIBLE,
    50, 105, 80, 30, hwnd, NULL, hInstance, NULL );
   
   
   
    HWND hText3 = CreateWindowEx( 0, "EDIT", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 150, 245, 350, 20,
    hwnd, NULL, hInstance, NULL );
   
    HWND hText6 = CreateWindowEx( 0, "EDIT", "Miejscowość:", WS_CHILD | WS_VISIBLE,
    50, 245, 85, 30, hwnd, 0, hInstance, NULL );
   
    HWND hButton1 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "Akceptuj", WS_CHILD | WS_VISIBLE |
    WS_BORDER, 10, 320, 150, 30, hwnd,( HMENU ) ID_PRZYCISK1, hInstance, NULL );
   
    hButton2 = CreateWindowEx( WS_EX_CLIENTEDGE, "BUTTON", "Anuluj", WS_CHILD | WS_VISIBLE |
    WS_BORDER, 365, 320, 150, 30, hwnd,( HMENU ) EXIT, hInstance, NULL );
   
    DWORD dwdlugosc;
    LPSTR Bufor;
   
    dwdlugosc = GetWindowTextLength( hText6 );
    Bufor =( LPSTR ) GlobalAlloc( GPTR, dwdlugosc + 1 );
    GetWindowText( hText6, Bufor, dwdlugosc + 1 );
   
   
    if( hwnd == NULL ) {
        MessageBox( NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK );
        return 0;
    }
    /*
        This is the heart of our program where all input is processed and
        sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
        this loop will not produce unreasonably high CPU usage
        */
   
    while( GetMessage( & Msg, NULL, 0, 0 ) > 0 ) { /* If no error is received... */
        TranslateMessage( & Msg ); /* Translate key codes to chars if present */
        DispatchMessage( & Msg ); /* Send it to WndProc */
       
       
    }
   
    return Msg.wParam;
   
}

Mam taki problem bo nie wiem jak zrobić tak że gdy wpisze coś w pole tekstowe i potem nacisne "Akceptuj" (przycisk) to żeby później wyświetliło mi to w nowym oknie informacyjnym to co tam wpiisałem.
P-128770
sppmacd
ODPOWIEDŹ
» 2015-03-28 11:44:22
Gdzie ty masz obsługę zdarzeń
C/C++
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
    case WM_CLOSE:
        DestroyWindow( hwnd );
        break;
       
    case WM_DESTROY:
        PostQuitMessage( 0 );
        break;
       
        default:
        return DefWindowProc( hwnd, msg, wParam, lParam );
    case WM_COMMAND:
        switch( wParam )
        {
        case ID_PRZYCISK1:
            ...
            break;
           
        case EXIT:
            ...
           
            break;
        }
        break;
    }
}
P-129308
pekfos
» 2015-03-28 12:10:57
C/C++
case WM_DESTROY: {
Usuń te nawiasy klamrowe.
P-129311
« 1 »
  Strona 1 z 1