C/Visual C - pintar control EDIT

 
Vista:

pintar control EDIT

Publicado por guillermin (5 intervenciones) el 02/04/2007 18:59:15
hola amigos tengo un problema con este codigo esta primera parte no es el problema la ultima lo es en las ultimas lineas de codigo creo una clase y lo asocio con el customcontrol despues creo un control EDIT dentro del customcontrol el problema es que cuando pinto el customcontrol tambien se pinta el edit solucione parcialmente con el setwindowpos pero cuando escondo el dialogo se repinta de nuevo no se como repintar el control edit

//#include <windows.h>
#include<stdlib.h>
#include<stdio.h>
#include "TextBox.h"
#include "resource.h"
void IniciarControles(void);
HWND hwndEdit;
BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
break;
return false;
case WM_CLOSE:
EndDialog(hwnd, 0);
return TRUE;
}
return FALSE;
}

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nShowCmd)
{
IniciarControles();
DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), 0, DlgProc);
return 0;
}
void IniciarControles()
{
WNDCLASSEX WndClass,WndClass2;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = 0;
WndClass.lpfnWndProc = (WNDPROC)CTextBox::CTextBoxWndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = GetModuleHandle(NULL);
WndClass.hIcon = NULL;
WndClass.hIconSm = NULL;
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
WndClass.lpszMenuName = 0;
WndClass.lpszClassName = "CTextBox";
RegisterClassEx (&WndClass);
}
------------------------------------------------------------------------------------------------
class CTextBox
{
public:
void Crear(HWND vhWndParent, const char *vTexto, const int vX, const int vY, const int vAncho, const int vAlto, const int ID);
//const char *Texto(void);
//void Texto(const char *Txt);
static LRESULT CALLBACK CTextBoxWndProc(HWND hWnd, UINT vMsg, WPARAM wParam, LPARAM lParam);
CTextBox(void);
~CTextBox(void);
private:
HWND hWndTexto;
HWND wTexto;
void Pintar();
};

----------------------------------------------------------------------
#include "textbox.h"
LRESULT CALLBACK CTextBox::CTextBoxWndProc(HWND hWnd, UINT vMsg, WPARAM wParam, LPARAM lParam)
{
CTextBox *Texto = (CTextBox *)GetWindowLong(hWnd, GWL_USERDATA);
HWND W;
switch (vMsg)
{
case WM_NCCREATE:
Texto=(CTextBox*)malloc(sizeof(CTextBox));
if (Texto==NULL)return false;
Texto->hWndTexto=hWnd;

SetWindowLong(hWnd, GWL_USERDATA, (long)Texto);
Texto->wTexto=CreateWindow("EDIT", NULL, WS_CHILD | WS_VISIBLE | ES_LEFT, 0, 0, 30, 50, hWnd, (HMENU)122,(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
break;

case WM_LBUTTONDOWN :
case WM_RBUTTONDOWN :
case WM_MBUTTONDOWN :
break;
case WM_ACTIVATE:
break;
case WM_ERASEBKGND :
return 1;

case WM_PAINT :
Texto->Pintar();
break;
case WM_NCDESTROY:
free(Texto);
break;
}
return DefWindowProc(hWnd, vMsg, wParam, lParam);
}
void CTextBox::Pintar()
{
HBRUSH cBorde;
RECT RectaCliente;
RECT rEdit;
GetClientRect(hWndTexto, &RectaCliente);
HDC hDCVentana = GetDC(hWndTexto);
HDC hDC = CreateCompatibleDC(hDCVentana);
HBITMAP BmphDC = CreateCompatibleBitmap(hDCVentana, RectaCliente.right, RectaCliente.bottom);
HBITMAP BmpViejo = (HBITMAP)SelectObject(hDC, BmphDC);

cBorde=CreateSolidBrush(RGB(255,0,0));
Rectangle(hDC,0,0,RectaCliente.right,RectaCliente.bottom);
BitBlt(hDCVentana, 0, 0, RectaCliente.right, RectaCliente.bottom, hDC, 0, 0, SRCCOPY);
SelectObject(hDC, BmpViejo);
DeleteObject(BmphDC);
DeleteDC(hDC);
ReleaseDC(hWndTexto, hDCVentana);
SetWindowPos(wTexto,HWND_TOP,1,1,RectaCliente.right-2,20,SWP_SHOWWINDOW);
}

hola
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:pintar control EDIT

Publicado por Nelek (816 intervenciones) el 03/04/2007 15:22:01
Hola,

no me he puesto a mirar tu codigo, pero por lo que dices... si con el SetWindowPos lo apanyaste pero se fastidia al mover o esconder el dialogo, eso quiere decir que tu llamada de CDialog::OnPaint te reescribe por encima de las ultimas modificaciones que hiciste.

Yo he logrado evitar algunas de esas "putadillas" sobrecargando el OnPaint () para dejar AL FINAL todo lo que quiero que quede visible por encima de lo demas. O haciendo que ciertas cosas, solo se ejecuten dependiendo de una variable BOOL. Me explico con un ejemplo:

void CMyDialog::OnPaint ()
{
CPaintDC dc (this);

if (m_bJustOpened)
{
//hago todo lo necesario para dibujar una grafica que uso
}

UpdateDialogLabels ();
//Aqui modifico los labels con dc.TextOut (...); para que se queden por encima de
//la grafica. Tambien modifico el caption con SetWindowText (...); y cosas asi

//Aqui podrias meter la "solucion" a tu problema, para que se ejecute al final de
//todo lo demas y por consecuencia se quede arriba visible, a pesar de redibujar

return;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar