Ver Mensaje Individual
  #5 (permalink)  
Antiguo 30/08/2011, 05:46
Avatar de Munire
Munire
 
Fecha de Ingreso: julio-2010
Ubicación: en el ciberdespacio (España)
Mensajes: 150
Antigüedad: 13 años, 9 meses
Puntos: 4
Respuesta: Dudas de principiante en Win Api

Se te ha olvidado poner el case WM_CREATE:



Código:
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 
     HWND boton1 = CreateWindowEx (0,"BUTTON", "Texto", WS_CHILD|WS_VISIBLE|WS_TABSTOP, 100, 100, 100, 20, hwnd, 0, miinstance, NULL);
 
    switch (message)                  /* handle the messages */
    {

       case WM_CREATE:
            SendMessage( boton1, WM_SETFONT, (WPARAM) hFont, true);
            break;

       case WM_COMMAND:
            if((HWND)lParam==boton1)
            {
                MessageBox (NULL, "Esto es un texto", "Título", MB_OK | MB_ICONEXCLAMATION);
            }
            break;
 
        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;
}
una cosa importante: los textos en estas funciones (p.e MessageBox o CreateWindowEx) no se ponen como const char es decir "texto const char", se ponen como tipo LPCTSTR. esto supone añadir _T antes del texto.

_T("texto del tipo LPCTSTR")

las funciones quedarian asi:

Código C++:
Ver original
  1. CreateWindowEx(0,_T("BUTTON"), _T("Nuestro boton"), WS_CHILD|WS_VISIBLE|WS_TABSTOP, 300, 300, 100, 20, hWnd, 0, miinstance, NULL);
  2. MessageBox(hWnd, _T("Hola Mundo"), _T("Title"), MB_OK);


¿como se sabe esto? pues por que en la declaracion de la funcion no pone

funcion(..., char * texto,...)

si no

funcion(..., LPCTSTR texto, ...)


por ejemplo la declaracion de MessageBox

int WINAPI MessageBox(
__in_opt HWND hWnd,
__in_opt LPCTSTR lpText,
__in_opt LPCTSTR lpCaption,
__in UINT uType
);

http://msdn.microsoft.com/en-us/library/ms645505




Cita:
Puedo crear varios textos sin necesidad de crear más "hdc" ni "paintstruct", es mas, he eliminido el EndPaint (hwnd, &ps) y no he encontrado ningún problema (¿por qué se debe finalizar la impresión?).
yo no lo eliminaria, si está es por algo, no crees?