Comunidad de diseño web y desarrollo en internet online

ayuda en C con API

Citar            
MensajeEscrito el 10 Sep 2005 03:48 am
Buenas aqui tengo dos ventanas y quiero q cuando yo cierre una por ejm la otra no se cierre
como podria modificar este codigo.
grax saludos

Código :

#include <windows.h>

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
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);
    }
    return 0;
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    WNDCLASSEX wc;
    HWND hwnd,hwnd1;
    MSG Msg;

    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    // Step 2: Creating the Window
    hwnd = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "hwnd",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 280, 120,
        NULL, NULL, hInstance, NULL);
     hwnd1 = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "hwnd1 ",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT, 280, 120,
        NULL, NULL, hInstance, NULL);


    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    ShowWindow(hwnd1, nCmdShow);
    UpdateWindow(hwnd1);
    // Step 3: The Message Loop
    while(GetMessage(&Msg, hwnd, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    return Msg.wParam;
}

Por juan_gv

108 de clabLevel



 

firefox
Citar            
MensajeEscrito el 10 Sep 2005 01:10 pm
Ok, ye revisé tu código en efecto, creas dos ventanas, pero si te fijas, nunca le dices que hacer con la segunda ventana, además usas para las dos el mismo HINSTANCE, y aunque en teoría eso funciona, deberías ponerle a cada quien su propio HINSTANCE, mi compilador se crashea de repente cuando compilo tu programa y es que estás usando un mismo recurso para dos ventanas diferentes, por eso al cerrar una, se cierran las dos

Ahora si te fijas aquí:

Código :

while(GetMessage(&Msg, hwnd, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    } 


Sólo estas enviando el handler de la primera ventana, por lo tanto, el compilador no abe que hacer con la segunda ventana y sólo te la muestra...

antes de ponerte a hacer este tipo de cosas, te recomiendo que leas un poco más sobre el funcionamiento de las ventanas, el manejo de los handlers, los recursos, etc. te servirá de mucho. Checate http://winapi.conclase.net

Por Aoyama

BOFH

6224 de clabLevel

6 tutoriales
12 articulos

Genero:Masculino   Anime Bloggers Bastard Operators From Hell

Webdesigner & Developer, en mis ratos libres bebo café por litros.

firefox
Citar            
MensajeEscrito el 10 Sep 2005 04:53 pm
:lol: :lol: :lol: aaaaaaaaaaaaahhh llege tarde a este post :twisted: .

Por choco

425 de clabLevel



Genero:Masculino  

Estado de México, México

firefox
Citar            
MensajeEscrito el 15 Sep 2005 02:59 am
holas grax pero si entiendo algo como seria el codigo dime podria crear otro winprock

Por juan_gv

108 de clabLevel



 

firefox
Citar            
MensajeEscrito el 18 Sep 2005 02:23 am
ya ps

Por juan_gv

108 de clabLevel



 

firefox
Citar            
MensajeEscrito el 19 Sep 2005 07:09 pm
ayundeme ps por fa si

Por juan_gv

108 de clabLevel



 

firefox
Citar            
MensajeEscrito el 19 Sep 2005 07:34 pm
Hola, en este momento algo ando ocupado, pero espero te sirva el siguiente enlace
click aquí

Por Aoyama

BOFH

6224 de clabLevel

6 tutoriales
12 articulos

Genero:Masculino   Anime Bloggers Bastard Operators From Hell

Webdesigner & Developer, en mis ratos libres bebo café por litros.

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.