elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  Ejemplo de programa WinApi32 GUI
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ejemplo de programa WinApi32 GUI  (Leído 2,693 veces)
david_BS

Desconectado Desconectado

Mensajes: 99



Ver Perfil WWW
Ejemplo de programa WinApi32 GUI
« en: 2 Abril 2012, 00:08 am »

Un proyecto de un programa básico con interfáz gráfica de Windows. Está hecho con MSVC++ 6.0

proyecto
http://www.mediafire.com/?yd4vpb42j4p1pi6

winmain.cpp
Código:
//
// UTN FRGP
// 2011
// david_BS
// EMAIL: david_bs@live.com
//


//////////////////////////////////////////////////


//#define WINVER 0x0500 //WINVER as 0x0500 enables features specific to Win 98 and 2000
//#define VC_EXTRALEAN


#include <windows.h>
//gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib


/////////////////////////
// Globales


HWND EditControl1;
HWND EditControl2;
HWND EditControl3;
HWND StaticControl1;


const int ID_EDIT1=1, ID_EDIT2=2, ID_EDIT3=3, ID_EDIT4=4, ID_EDIT5=5;
const int ID_OK = 6;
const int ID_CANCEL = 7;
const int ID_LABEL1 = 0;


/////////////////////////////


void getCentradoGlobal(int vXY[2], int h, int w);


///////////////
// Controles de ventana


void RegistrarControlesDeVentanaPrincipal(HWND hWin)
{
    static char* t1 =  TEXT("Ingrese 3 numeros");
    


    unsigned long EstiloHijo1 = WS_VISIBLE | WS_CHILD;
    unsigned long EstiloHijo2 = WS_CHILD | WS_VISIBLE | WS_BORDER;
    unsigned long EstiloHijo3 = WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON;
    unsigned long EstiloHijo4 = WS_CHILD | WS_VISIBLE | LBS_NOTIFY | LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP;


    long editstyle =WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP;//|ES_AUTOHSCROLL;//|WS_TABSTOP;


    int offs = 30;
    int X=20;
    int Y=10;
    int W=80;
    int H=25;


    StaticControl1 = CreateWindow( TEXT("static"),
                                   t1,
                                   EstiloHijo1,
                                   20,10,180,20,
                                   hWin,
                                   (HMENU)ID_LABEL1,
                                   NULL,
                                   NULL);


    EditControl1 = CreateWindow( TEXT("Edit"),
                                 NULL,
                                 editstyle,
                                 X,
                                 Y+20,
                                 W,
                                 H,
                                 hWin,
                                 (HMENU)ID_EDIT1,
                                 NULL,
                                 NULL);


    EditControl2 = CreateWindow( TEXT("Edit"),
                                 NULL,
                                 editstyle,
                                 X,
                                 Y+20+(offs*1),
                                 W,
                                 H,
                                 hWin,
                                 (HMENU)ID_EDIT2,
                                 NULL,
                                 NULL);


    EditControl2 = CreateWindow( TEXT("Edit"),
                                 NULL,
                                 editstyle,
                                 X,
                                 Y+20+(offs*2),
                                 W,
                                 H,
                                 hWin,
                                 (HMENU)ID_EDIT3,
                                 NULL,
                                 NULL);




    CreateWindow( TEXT("button"),
                  TEXT("Sumar"),
                  EstiloHijo1,
                  X,130,60,H,
                  hWin,
                  (HMENU) ID_OK,
                  NULL,
                  NULL);


    CreateWindow( TEXT("button"),
                  TEXT("Salir"),
                  EstiloHijo1,
                  X+70,130,50,H,
                  hWin,
                  (HMENU)ID_CANCEL,
                  NULL,
                  NULL);
}


//////////
// CallBack


INT_PTR CALLBACK WinProc(HWND hWin, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_CREATE:
        {
            RegistrarControlesDeVentanaPrincipal(hWin);
        }
        break;


        case WM_KEYDOWN:
        {
            if(wParam==VK_TAB){
            }
        }
        break;


        case WM_COMMAND:
        {
            switch(LOWORD(wParam))
            {
                case ID_OK:
                {
                    char chBuffer1[128];
                    memset(chBuffer1,0,sizeof(chBuffer1));
                    GetDlgItemText( hWin,ID_EDIT1, chBuffer1, sizeof( chBuffer1 ) );
                    char chBuffer2[128];
                    memset(chBuffer2,0,sizeof(chBuffer2));
                    GetDlgItemText( hWin,ID_EDIT2, chBuffer2, sizeof( chBuffer2 ) );
                    int i_res = atoi(chBuffer1)+atoi(chBuffer2);
                    char ch_res[128];
                    itoa(i_res,ch_res,10);
                    HWND Edit3 =  GetDlgItem(hWin,ID_EDIT3);
                    SendMessage(Edit3 , WM_SETTEXT, 0, (LPARAM)ch_res);
                }
                break;


                case ID_CANCEL:
                {
                    SendMessage(hWin, WM_CLOSE, 0, 0);
                    return TRUE;
                }
                break;
            }
        }
        break;


        case WM_CLOSE:
        {
            DestroyWindow(hWin);
            return TRUE;
        }
        /////////////////////////////
        case WM_DESTROY:
        {
            PostQuitMessage(0);
            return TRUE;
        }


        default:
            return DefWindowProc(hWin,uMsg,wParam,lParam);


    }


    return 0;
    //return DefWindowProc(hWin,uMsg,wParam,lParam);
}


////////////
// Clase de ventana


void RegistrarClaseVentana(WNDCLASS* wc)
{
    //    HICON hIconImg = (HICON)LoadImage(NULL, "BS.ico", IMAGE_ICON, 542, 449, LR_LOADFROMFILE);


    wc->lpszClassName = TEXT("Window");
    wc->hInstance     = GetModuleHandle(NULL);
    //wc->hbrBackground = GetSysColorBrush(COLOR_3DFACE);
    wc->hbrBackground =  (HBRUSH)(COLOR_BTNFACE+1);
    wc->lpfnWndProc   = (WNDPROC)WinProc;
    wc->style         =  CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wc->cbClsExtra    =  0;
    wc->cbWndExtra    =  0;
    //wc->hIcon         =  LoadIcon(NULL,"IDI_ICON1");
    wc->hIcon         =  LoadIcon(NULL,"IDI_WINLOGO");
    wc->hCursor       =  LoadCursor(NULL,IDC_ARROW);
    wc->lpszMenuName  =  NULL;
    RegisterClass((struct tagWNDCLASSA *)wc);
}


//////////////
// Punto de entrada ('WinMain' : must be '__stdcall')


int WINAPI WinMain(HINSTANCE hInst, HINSTANCE h0, LPSTR lpCmdLine, int nCmdShow){




    HWND hWin;
    WNDCLASS wc = {0};


    RegistrarClaseVentana(&wc);


    int ancho=250;
    int alto=200;
    int dim[2];
    getCentradoGlobal(dim, ancho, alto);


    unsigned long Estilo1 = WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;




    hWin = CreateWindow( wc.lpszClassName,
                         "GUI32",
                         Estilo1,
                         dim[0],
                         dim[1],
                         ancho,
                         alto,
                         NULL,
                         NULL,
                         hInst,
                         NULL);


//    ShowWindow(hWin,nCmdShow);
    ShowWindow(hWin, SW_SHOWDEFAULT);


    //UpdateWindow(hWin);


    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0)>0) {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
    }


    return msg.wParam;
}




////////


void getCentradoGlobal(int vXY[2], int h, int w)
{
    RECT rcP;
    GetWindowRect(GetDesktopWindow(), &rcP);
    int centerX = (rcP.right/2)-(w/2)-(w/4);
    int centerY = (rcP.bottom/2)-(h/2)+(h/6);
    vXY[0]=centerX;
    vXY[1]=centerY;
}



« Última modificación: 3 Abril 2012, 03:18 am por david_BS » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines