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
//#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


0