Ver Mensaje Individual
  #10 (permalink)  
Antiguo 01/09/2011, 11:47
Anonimo12
 
Fecha de Ingreso: abril-2009
Ubicación: En foros del web, normalmente en Web general, HTML y CSS.
Mensajes: 258
Antigüedad: 15 años
Puntos: 3
Respuesta: Dudas de principiante en Win Api

EDITO: Perfecto!, me ha funcionado de esta forma:

Código C++:
Ver original
  1. #include <windows.h>
  2. #include <tchar.h>
  3.  
  4. enum {ID_boton1 = 1000, ID_edit1};
  5.  
  6. /*  Declare Windows procedure  */
  7. LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
  8.  
  9. /*  Make the class name into a global variable  */
  10. char szClassName[ ] = "CodeBlocksWindowsApp";
  11.  
  12.  
  13. HINSTANCE estancia;
  14. HWND boton1;
  15. HWND edit1;
  16. HWND label;
  17.  
  18.  
  19. int WINAPI WinMain (HINSTANCE hThisInstance,
  20.                      HINSTANCE hPrevInstance,
  21.                      LPSTR lpszArgument,
  22.                      int nCmdShow)
  23. {
  24.     HWND hwnd;               /* This is the handle for our window */
  25.     MSG messages;            /* Here messages to the application are saved */
  26.     WNDCLASSEX wincl;        /* Data structure for the windowclass */
  27.  
  28.     estancia = hThisInstance;
  29.  
  30.     /* The Window structure */
  31.     wincl.hInstance = hThisInstance;
  32.     wincl.lpszClassName = szClassName;
  33.     wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  34.     wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  35.     wincl.cbSize = sizeof (WNDCLASSEX);
  36.  
  37.     /* Use default icon and mouse-pointer */
  38.     wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  39.     wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  40.     wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  41.     wincl.lpszMenuName = NULL;                 /* No menu */
  42.     wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  43.     wincl.cbWndExtra = 0;                      /* structure or the window instance */
  44.     /* Use Windows's default colour as the background of the window */
  45.     wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
  46.  
  47.     /* Register the window class, and if it fails quit the program */
  48.     if (!RegisterClassEx (&wincl))
  49.         return 0;
  50.  
  51.     /* The class is registered, let's create the program*/
  52.     hwnd = CreateWindowEx (
  53.            0,                   /* Extended possibilites for variation */
  54.            szClassName,         /* Classname */
  55.            "Code::Blocks Template Windows App",       /* Title Text */
  56.            WS_OVERLAPPEDWINDOW, /* default window */
  57.            CW_USEDEFAULT,       /* Windows decides the position */
  58.            CW_USEDEFAULT,       /* where the window ends up on the screen */
  59.            544,                 /* The programs width */
  60.            375,                 /* and height in pixels */
  61.            HWND_DESKTOP,        /* The window is a child-window to desktop */
  62.            NULL,                /* No menu */
  63.            hThisInstance,       /* Program Instance handler */
  64.            NULL                 /* No Window Creation data */
  65.            );
  66.  
  67.     /* Make the window visible on the screen */
  68.     ShowWindow (hwnd, nCmdShow);
  69.  
  70.     /* Run the message loop. It will run until GetMessage() returns 0 */
  71.     while (GetMessage (&messages, NULL, 0, 0))
  72.     {
  73.         /* Translate virtual-key messages into character messages */
  74.         TranslateMessage(&messages);
  75.         /* Send message to WindowProcedure */
  76.         DispatchMessage(&messages);
  77.     }
  78.  
  79.     /* The program return-value is 0 - The value that PostQuitMessage() gave */
  80.     return messages.wParam;
  81. }
  82.  
  83.  
  84.  
  85.  
  86. LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  87. {
  88.  
  89.     TCHAR texto [256];
  90.  
  91.     switch (message)
  92.     {
  93.         case WM_CREATE:
  94.         {
  95.  
  96.             label = CreateWindow(_T("static"), 0, WS_CHILD | WS_VISIBLE, 10, 10, 175, 25, hwnd, 0, estancia, 0);
  97.             boton1 = CreateWindow (_T("Button"), _T("Texto"), BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE, 80, 100, 70, 25, hwnd, (HMENU) ID_boton1, estancia, 0);
  98.             edit1 = CreateWindow (_T("Edit"), 0, WS_CHILD | WS_VISIBLE, 160, 100, 300, 20, hwnd, (HMENU) ID_edit1, estancia, 0);
  99.             break;
  100.         }
  101.  
  102.         case WM_COMMAND:
  103.         switch (wParam)
  104.         {
  105.             case ID_boton1:
  106.             GetWindowText(edit1, texto, 255);
  107.             SetWindowText(label, texto);
  108.         }
  109.  
  110.         break;
  111.  
  112.         case WM_DESTROY:
  113.             PostQuitMessage (0);
  114.             break;
  115.         default:
  116.             return DefWindowProc (hwnd, message, wParam, lParam);
  117.     }
  118.  
  119.     return 0;
  120. }

Ahora estoy intentando hacer varias cosas:

-Cambiar la estética del label (color, imagen de fondo, etc.).
-Situar el texto directamente sobre la ventana del programa sin el cuadradito de fondo (estilo TextOut).
-Ir añadiendo textos conforme se le vaya dando al botón, es decir, si escribes "hola" y le das al botón se imprime en el label, si luego escribes "mundo" y le das al botón que se sitúe alado de "hola" quedando "hola mundo", y asi sucesivamente.

Lo ire comentando aqui conforme vaya encontrando la forma de hacer lo que he mencionado por si a alguien le sirve.

Saludos!.
__________________
¿Por qué Anónimo?, porque como está el mundo no podemos considerarnos humanos...

Última edición por Anonimo12; 01/09/2011 a las 13:40