Ver Mensaje Individual
  #1 (permalink)  
Antiguo 03/09/2011, 15:37
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
Alinear texto [Win API]

Buenas:

He estado mirando en 9283982 sitios pero no encuentro cómo hacer para alinear el texto en un edit, static, etc. conforme se vaya ingresando. Por ejemplo, teniendo este código:

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

Cuando presionas el botón 1 llama a la función SetWindowText e imprime en el edit el número "1", sin embargo cada vez que le das al botón borra lo que hay en el edit antes de escribir un "1". Lo que yo busco es que por ejemplo, si pulsas tres veces 1, en el edit debería aparecer "111".

He probado con la librería string pero no consigo que se ejecute con las funciones de Win API.

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