Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/12/2006, 16:17
nostromo_
 
Fecha de Ingreso: diciembre-2004
Ubicación: Iquique, Chile
Mensajes: 150
Antigüedad: 21 años, 9 meses
Puntos: 0
Manejo Evento Paint en Win32

Holas;

Tengo la siguiente duda, manejo las funciones TextOut, FrameRect y fillRect, estos dos últimos los utilizo para el fondo a modo de presentación.

Tengo dos botnoes, en el primero escribo un string "123123" y el segundo borro ese string.

Ahora, luego de borrar, no es posible escribir nada en las coordenadas que especfico en RECT, les coloco el código para que vean lo que trato de hacer, perfectamente puedo utilizar static con SetBkMode a TRANSPARENT y ajustando su posición con el fondo de colores de acuerdo al tipo de resultado, pero quiero disminuir código hecho. Esta realizado con Dev-C++, SO XP.

Código PHP:
#include <windows.h>
//
    
HWND hwnd;
    
HINSTANCE inst;
//
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void fondo(HDC, HWND);
void ver(HDC, HWND);
void borrar(HDC, HWND);

char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    
HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
    
HWND hwnd; MSG messages; WNDCLASSEX wincl;
    
//
    
wincl.hInstance = hThisInstance;
    
wincl.lpszClassName = szClassName;
    
wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    
wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    
wincl.cbSize = sizeof (WNDCLASSEX);
    
//
    
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    
wincl.lpszMenuName = NULL;                 /* No menu */
    
wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    
wincl.cbWndExtra = 0;                      /* structure or the window instance */
    //
    
wincl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    if (!
RegisterClassEx (&wincl))
        return 
0;

    
/* The class is registered, let's create the program*/
    
hwnd = CreateWindowEx (
           
0,                   /* Extended possibilites for variation */
           
szClassName,         /* Classname */
           
"Windows App",       /* Title Text */
           
WS_VISIBLE|WS_SYSMENU|WS_CAPTION|WS_MINIMIZEBOX,
           
CW_USEDEFAULT,       /* Windows decides the position */
           
CW_USEDEFAULT,       /* where the window ends up on the screen */
           
544,                 /* The programs width */
           
375,                 /* and height in pixels */
           
HWND_DESKTOP,        /* The window is a child-window to desktop */
           
NULL,                /* No menu */
           
hThisInstance,       /* Program Instance handler */
           
NULL                 /* No Window Creation data */
           
);
    
ShowWindow (hwnd, nFunsterStil);
    while (
GetMessage (&messages, NULL, 0, 0))
    {
        
TranslateMessage(&messages);
        
DispatchMessage(&messages);
    }
    return 
messages.wParam;
}
//
    
HWND boton,goma,lbl; BOOL resp,eraser;
    
HBRUSH hbrush, hcuadro, hfondo1;
    
COLORREF cfondo1 = RGB(173,202,241);
    
COLORREF cfondo2 = RGB(221,236,255);
    
RECT rect3 = {170,249,404,269};
    
RECT rect31 = {171,250,403,268};
    
char *str = "123123";
    
RECT r = {172,251,402,267};
//
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (
message)
    {
        case 
WM_CREATE:
             
boton = CreateWindowEx(0,"button","Ver",WS_VISIBLE|WS_CHILD,10,10,
             
120,20,hwnd,(HMENU)100,inst,NULL);
             
goma = CreateWindowEx(0,"button","Borrar",WS_VISIBLE|WS_CHILD,140,10,
             
120,20,hwnd,(HMENU)120,inst,NULL);
             
/*lbl = CreateWindowEx(0,"static","",WS_VISIBLE|WS_CHILD,171,250,100,19,
             hwnd,(HMENU)0,inst,NULL);*/
             
break;
        case 
WM_COMMAND:
             switch (
LOWORD(wParam))
             {
                    case 
100:
                         
resp = true;
                         
GetClientRect(hwnd, &r);
                         
InvalidateRect(hwnd, &r, TRUE);
                         break;
                    case 
120:
                         
eraser = true;
                         
GetClientRect(hwnd,&r);
                         
InvalidateRect(hwnd,&r,TRUE);
                         break;
                    }
             break;
        case 
WM_PAINT:
             
HDC hdc; PAINTSTRUCT ps;
             
hdc = BeginPaint(hwnd,&ps);
                 
fondo(hdc,hwnd);
                 if(
resp) { ver(hdc,hwnd); }
                 if(
eraser) { borrar(hdc,hwnd); }
             
EndPaint(hwnd,&ps);
             break;
        case 
WM_DESTROY:
            
PostQuitMessage (0);
            break;
        default:
            return 
DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 
0;
}
/*----------------- FUNCIONES ----------------------------*/
void fondo(HDC hdc, HWND hwnd)
{
     
hbrush = CreateSolidBrush(RGB(151,190,245));
     
hcuadro = CreateSolidBrush(cfondo2);
     
hfondo1 = CreateSolidBrush(cfondo1);
     
//dibujar formas
     
FrameRect(hdc,&rect3,hbrush);
     
FillRect(hdc,&rect31,hfondo1);
     
SelectObject(hdc,hbrush); DeleteObject(hbrush);
     
SelectObject(hdc,hfondo1); DeleteObject(hfondo1);
     }
//------
void ver(HDC hdc, HWND hwnd)
{
     
SetTextColor(hdc,RGB(0,0,0));
     
SetBkMode(hdc,TRANSPARENT);
     
TextOut(hdc,172,251,str,strlen(str));
     }
//-------
void borrar(HDC hdc, HWND hwnd)
{
     
/*char *str1 = "             ";
     SetBkColor(hdc,cfondo2);
     TextOut(hdc,174,251,str1,strlen(str1));*/
     
hfondo1 = CreateSolidBrush(cfondo1);
     
FillRect(hdc,&rect31,hfondo1);
     
SelectObject(hdc,hfondo1); DeleteObject(hfondo1);
     } 
Les agradesco cualquier ayuda.