Ver Mensaje Individual
  #9 (permalink)  
Antiguo 05/09/2011, 11:29
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: Alinear texto [Win API]

Vale ya te entendí, pero lo he probado añadiendo lo que me ha comentado Munire para concatenar numeros y no me los suma, es decir, al presionar tres veces le botón "1" en este ejemplo, se imprime siempre "1.00000".

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

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