Estoy haciendo la siguiente aplicación:
- Una Ventana Principal con un Menú.
- Dentro de ella dos ventanas que muestran textos que pueden cambiar de color de fondo y de escritura.
Estos últimos son ventanas que quiero crear he adaptado una clase que he visto por internet a mis especificaciones pero cuando termina sale:
Pero no me da ninguna información más. La clase es :
Código:
#include <windows.h>
#include <string>
using namespace std;
class CWinThunk
{
protected:
virtual LRESULT CALLBACK WindowProc(UINT, WPARAM, LPARAM)=0;
DWORD InitThunk(void* pThis){
// MOV [ESP+4], pThis
*(DWORD*)(_thunk + 0) = 0x042444C7;
*(DWORD*)(_thunk + 4) = (DWORD)pThis;
// JMP proc //salta a WindowProc
*(BYTE*) (_thunk + 8) = 0xe9;
*(DWORD*)(_thunk + 9) = **(DWORD**)this - ((int)_thunk + 13);
return (DWORD) _thunk;
}
private:
char _thunk[13];
};
class TSay: public CWinThunk
{
protected:
HWND m_hWnd;
WNDPROC m_lpOldProc;
LRESULT CALLBACK WindowProc(UINT, WPARAM, LPARAM);
LRESULT DefWindowProc(UINT, WPARAM, LPARAM);
public:
TSay(HINSTANCE,double, double, const char*, HWND, HFONT, COLORREF, COLORREF, double, double, int, int, HWND);
~TSay();
private:
HINSTANCE m_hIns;
double m_posX;
double m_posY;
const char* m_pint;
HWND m_vent;
HFONT m_letr;
COLORREF m_escr;
COLORREF m_fond;
double m_tamX;
double m_tamY;
int m_bord;
int m_alin;
HWND m_vHij;
void _Conectar(HWND);
static TSay *pCreando;
static LRESULT CALLBACK PrimerMensaje(HWND, UINT, WPARAM, LPARAM);
};
static const char* ClaseVentana = "ClaseTSay";
TSay::TSay(HINSTANCE hIns,double posX, double posY, const char* pint, HWND vent, HFONT letr, COLORREF escr, COLORREF fond, double tamX, double tamY, int bord, int alin, HWND vHij)
{
m_hIns = hIns;
m_posX = posX;
m_posY = posY;
m_pint = pint;
m_vent = vent;
m_letr = letr;
m_escr = escr;
m_fond = fond;
m_tamX = tamX;
m_tamY = tamY;
m_bord = bord;
m_alin = alin;
m_vHij = vHij;
m_lpOldProc = NULL;
m_hWnd = NULL;
WNDCLASS wc;
ATOM a;
ZeroMemory(&wc, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)TSay::PrimerMensaje;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = m_hIns;
wc.hIcon = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)CreateSolidBrush(m_fond);
wc.lpszClassName = ClaseVentana;
a = RegisterClass(&wc);
pCreando = this;
int x_posX = (int)m_posX;
int x_posY = (int)m_posY;
int x_tamX = (int)m_tamX;
int x_tamY = (int)m_tamY;
DWORD m_hPen;
if (m_bord == 1)
{
m_hPen = SS_LEFT | WS_BORDER | WS_CHILD| WS_VISIBLE;
}
else
{
m_hPen = SS_LEFT | WS_CHILD| WS_VISIBLE;
}
m_vHij = CreateWindow(
ClaseVentana,
"TSay",
m_hPen,
x_posY,
x_posX,
x_tamX,
x_tamY,
m_vent,
NULL,
m_hIns,
NULL);
if(m_vHij)
{
ShowWindow(m_vHij, 5);
UpdateWindow(m_vHij);
}
}
TSay::~TSay()
{
}
LRESULT CALLBACK TSay::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
HDC dc = GetDC(m_vHij);
PAINTSTRUCT ps;
RECT rc;
HRGN bgRgn;
HBRUSH hBrush;
HPEN hPen;
HGDIOBJ old;
int x_posX = (int)m_posX;
int x_posY = (int)m_posY;
int x_tamX = (int)m_tamX;
int x_tamY = (int)m_tamY;
switch(msg)
{
case WM_PAINT:
dc = BeginPaint (m_vHij, &ps);
SetRect (&rc, 0, 0, x_tamX, x_tamY);
bgRgn = CreateRectRgnIndirect(&rc);
hBrush = CreateSolidBrush(m_fond);
FillRgn(dc, bgRgn, hBrush);
SetBkMode (dc, m_fond);
SetTextColor (dc, m_escr);
// old = SelectObject(dc, m_letr);
switch (m_alin)
{
case 0:
DrawText(dc, m_pint, lstrlen(m_pint), &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
break;
case 1:
DrawText(dc, m_pint, lstrlen(m_pint), &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
break;
case 2:
DrawText(dc, m_pint, lstrlen(m_pint), &rc, DT_RIGHT | DT_VCENTER | DT_SINGLELINE);
break;
}
// SelectObject(dc, old);
// ReleaseDC(m_vHij, dc);
// DeleteObject(old);
DeleteObject(bgRgn);
DeleteObject(hBrush);
DeleteObject(hPen);
EndPaint (m_vHij, &ps);
SendMessage(m_vHij, WM_FONTCHANGE, (WPARAM)m_letr, 1);
RedrawWindow(m_vHij,NULL,NULL,RDW_INVALIDATE | RDW_INTERNALPAINT);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(msg, wp, lp);
}
return 0;
}
//------------------------
TSay * TSay::pCreando;
//------------------------
LRESULT CALLBACK TSay::PrimerMensaje(HWND m_vHij, UINT msg, WPARAM wp, LPARAM lp)
{
pCreando->_Conectar(m_vHij);
return pCreando->WindowProc(msg, wp, lp);
}
void TSay::_Conectar(HWND m_vHij)
{
DWORD dw;
m_hWnd = m_vHij;
dw = InitThunk(this);
::SetWindowLong(m_vHij, GWL_WNDPROC, dw);
}
LRESULT TSay::DefWindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
return m_lpOldProc ?
::CallWindowProc(m_lpOldProc, m_hWnd, msg, wp, lp) :
::DefWindowProc(m_hWnd, msg, wp, lp);
}
Y viene llamada desde la clase principal que es:
Código:
#include <windows.h>
#include <iostream>
#include <tlhelp32.h>
#include <string>
#include "CHSoft.h"
#include <ctype.h>
#include <stdio.h>
#include "procesos.h"
using namespace std;
LRESULT CALLBACK WinPro (HWND, UINT , WPARAM, LPARAM);
LRESULT CALLBACK WinPr2 (HWND, UINT , WPARAM, LPARAM);
LRESULT CALLBACK WinPr3 (HWND, UINT , WPARAM, LPARAM);
void InsertarMenu(HWND);
void Inicio(HWND);
bool Exists(CHAR* fname);
bool ProcessRunning( const char* name );
void Salida();
void Pantalla(HWND, HINSTANCE);
// int TSay(double, double, const char*, HWND, HFONT, COLORREF, COLORREF, double, double, int, int, HWND);
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
HWND oVentPrinc;
MSG msg;
WNDCLASSEX wincl;
// EXTERN HINSTANCE hInst;
wincl.hInstance = hInstance;
wincl.lpszClassName = "Principal";
wincl.lpfnWndProc = WinPro;
wincl.style = CS_HREDRAW | CS_VREDRAW;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (hInstance, "CHSIcono");
wincl.hIconSm = LoadIcon (hInstance, "CHSIcono");
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(255,255,255));
if(!RegisterClassEx(&wincl)) return 0;
wincl.hInstance = hInstance;
wincl.lpszClassName = "Hija";
wincl.lpfnWndProc = WinPr2;
wincl.style = CS_HREDRAW | CS_VREDRAW;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(150,150,150));
if(!RegisterClassEx(&wincl)) return 0;
wincl.hInstance = hInstance;
wincl.lpszClassName = "Hijo";
wincl.lpfnWndProc = WinPr3;
wincl.style = CS_HREDRAW | CS_VREDRAW;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(150,150,150));
if(!RegisterClassEx(&wincl)) return 0;
oVentPrinc = CreateWindowEx(
0,
"Principal",
wtex001,
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL | WS_MAXIMIZE,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
HWND_DESKTOP,
NULL,
hInstance,
NULL);
Inicio(oVentPrinc);
HWND oDlgVen;
oDlgVen = CreateWindowEx(
0,
"Hija",
wtex001,
WS_DLGFRAME | WS_CHILD | WS_VISIBLE,
100*TamPan,
20*TamPan,
1080*TamPan,
710*TamPan,
oVentPrinc,
NULL,
hInstance,
NULL);
HWND oDlgBro;
oDlgBro = CreateWindowEx(
0,
"Hijo",
wtex001,
WS_DLGFRAME | WS_CHILD | WS_VISIBLE,
100*TamPan,
20*TamPan,
1080*TamPan,
710*TamPan,
oVentPrinc,
NULL,
hInstance,
NULL);
SendMessage(oVentPrinc,WM_SETFONT,(WPARAM)oFont,MAKELPARAM(true,0));
Inicio(oVentPrinc);
InsertarMenu(oVentPrinc);
ShowWindow(oVentPrinc, SW_SHOWMAXIMIZED);
ShowWindow(oDlgVen, SW_SHOW);
ShowWindow(oDlgBro, SW_HIDE);
UpdateWindow(oVentPrinc);
Pantalla(oDlgVen, hInstance);
// RedrawWindow(m_vHij,NULL,NULL,RDW_INVALIDATE | RDW_INTERNALPAINT);
while(TRUE == GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinPro(HWND oVentPrinc, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case CYEENT:
MessageBox(oVentPrinc, wtex001, wtex022, MB_OK);
break;
case CYEMAN:
MessageBox(oVentPrinc, wtex002, wtex023, MB_OK);
break;
case CYELIC:
MessageBox(oVentPrinc, wtex003, wtex024, MB_OK);
break;
case CYEDEM:
MessageBox(oVentPrinc, wtex004, wtex025, MB_OK);
break;
case CYERES:
MessageBox(oVentPrinc, wtex005, wtex026, MB_OK);
break;
case NYSENT:
MessageBox(oVentPrinc, wtex006, wtex027, MB_OK);
break;
case NYSMAN:
MessageBox(oVentPrinc, wtex007, wtex028, MB_OK);
break;
case NYSLIC:
MessageBox(oVentPrinc, wtex008, wtex029, MB_OK);
break;
case NYSDEM:
MessageBox(oVentPrinc, wtex009, wtex030, MB_OK);
break;
case NYSRES:
MessageBox(oVentPrinc, wtex010, wtex031, MB_OK);
break;
case FYVENT:
MessageBox(oVentPrinc, wtex011, wtex032, MB_OK);
break;
case FYVMAN:
MessageBox(oVentPrinc, wtex012, wtex033, MB_OK);
break;
case FYVLIC:
MessageBox(oVentPrinc, wtex013, wtex034, MB_OK);
break;
case FYVDEM:
MessageBox(oVentPrinc, wtex014, wtex035, MB_OK);
break;
case FYVRES:
MessageBox(oVentPrinc, wtex015, wtex036, MB_OK);
break;
case PAGWEB:
MessageBox(oVentPrinc, wtex016, wtex037, MB_OK);
break;
case LICENC:
MessageBox(oVentPrinc, wtex017, wtex038, MB_OK);
break;
case COMUNI:
MessageBox(oVentPrinc, wtex018, wtex039, MB_OK);
break;
case CONSOL:
MessageBox(oVentPrinc, wtex019, wtex040, MB_OK);
break;
case AYUPRO:
MessageBox(oVentPrinc, wtex020, wtex041, MB_OK);
break;
case SALPRO:
Salida();
break;
}
break;
case WM_DESTROY:
Salida();
break;
default:
return DefWindowProc(oVentPrinc, msg, wParam, lParam);
case WM_SIZE:
{
RECT rWindow;
GetWindowRect( oVentPrinc, &rWindow );
int nHt = rWindow.right - rWindow.left;
int nWi = rWindow.bottom - rWindow.top;
if ((nHt > (1200*TamPan)) | (nWi >= (800*TamPan)))
ShowScrollBar(oVentPrinc, SB_BOTH, FALSE);
else
ShowScrollBar(oVentPrinc, SB_BOTH, TRUE);
}
}
return 0;
}
LRESULT CALLBACK WinPr2(HWND oDlgVen, UINT msg2, WPARAM wParam, LPARAM lParam)
{
HINSTANCE hInst;
switch (msg2)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(oDlgVen, msg2, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK WinPr3(HWND oDlgBro, UINT msg3, WPARAM wParam, LPARAM lParam)
{
switch (msg3)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(oDlgBro, msg3, wParam, lParam);
}
return 0;
}
void Salida()
{
PostQuitMessage(0);
}
void InsertarMenu(HWND oVent)
{
HMENU hMenu01, hMenu02, hMenu03, hMenu04;
hMenu01 = CreateMenu();
hMenu02 = CreateMenu();
hMenu03 = CreateMenu();
hMenu04 = CreateMenu();
switch (TipCyE)
{
case 1:
AppendMenu(hMenu02, MF_STRING, CYEENT, wtex015);
AppendMenu(hMenu02, MF_STRING, CYEMAN, wtex018);
AppendMenu(hMenu02, MF_STRING, CYELIC, wtex019);
break;
case 2:
AppendMenu(hMenu02, MF_STRING, CYEDEM, wtex039);
break;
case 3:
AppendMenu(hMenu02, MF_STRING, CYEDEM, wtex039);
AppendMenu(hMenu02, MF_STRING, CYERES, wtex048);
break;
}
switch (TipNyS)
{
case 1:
AppendMenu(hMenu03, MF_STRING, NYSENT, wtex015);
AppendMenu(hMenu03, MF_STRING, NYSMAN, wtex018);
AppendMenu(hMenu03, MF_STRING, NYSLIC, wtex019);
break;
case 2:
AppendMenu(hMenu03, MF_STRING, NYSDEM, wtex040);
break;
case 3:
AppendMenu(hMenu03, MF_STRING, NYSDEM, wtex040);
AppendMenu(hMenu03, MF_STRING, NYSRES, wtex048);
break;
}
switch (TipFyV)
{
case 1:
AppendMenu(hMenu04, MF_STRING, FYVENT, wtex015);
AppendMenu(hMenu04, MF_STRING, FYVMAN, wtex018);
AppendMenu(hMenu04, MF_STRING, FYVLIC, wtex019);
break;
case 2:
AppendMenu(hMenu04, MF_STRING, FYVDEM, wtex041);
break;
case 3:
AppendMenu(hMenu04, MF_STRING, FYVDEM, wtex041);
AppendMenu(hMenu04, MF_STRING, FYVRES, wtex048);
break;
}
AppendMenu(hMenu01, MF_STRING | MF_POPUP, (UINT)hMenu02, wtex002);
AppendMenu(hMenu01, MF_STRING | MF_POPUP, (UINT)hMenu03, wtex003);
AppendMenu(hMenu01, MF_STRING | MF_POPUP, (UINT)hMenu04, wtex004);
AppendMenu(hMenu01, MF_STRING , PAGWEB , wtex008);
AppendMenu(hMenu01, MF_STRING , LICENC , wtex009);
AppendMenu(hMenu01, MF_STRING , COMUNI , wtex010);
AppendMenu(hMenu01, MF_STRING , CONSOL , wtex011);
AppendMenu(hMenu01, MF_STRING , AYUPRO , wtex012);
AppendMenu(hMenu01, MF_STRING , SALPRO , wtex013);
SetMenu(oVent, hMenu01);
}
void Inicio(HWND oVentPrinc)
{
if (Exists("CHSoft2.exe"))
{
PostQuitMessage(0);
ShellExecute(GetDesktopWindow(), "open", "cambio.bat", NULL, NULL, SW_SHOWNORMAL);
}
else
{
if (ProcessRunning("CHSoft.exe"))
PostQuitMessage(0);
else
{
if (Exists("cyew32.exe"))
TipCyE = 1;
else
{
if (Exists("cyew32.res"))
TipCyE = 3;
else
TipCyE = 2;
}
if (Exists("nysw32.exe"))
TipNyS = 1;
else
{
if (Exists("nysw32.res"))
TipNyS = 3;
else
TipNyS = 2;
}
if (Exists("fyvw32.exe"))
TipFyV = 1;
else
{
if (Exists("fyvw32.res"))
TipFyV = 3;
else
TipFyV = 2;
}
if ((ych / 800) < (xch / 1280))
TamPan = ych / 800;
else
TamPan = xch / 1280;
TamLet = 18 * TamPan;
OSVERSIONINFO osv = { sizeof(OSVERSIONINFO) };
LPTSTR TipLet = TEXT("SEGOE UI");
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT && osv.dwMajorVersion >= 5)
{
TipLet = TEXT("Times New Roman");
}
oFont = CreateFont(TamLet , 0, 0, 0, 400, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TipLet);
oFon2 = CreateFont(TamLet , 0, 0, 0, 400, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TipLet);
oFon3 = CreateFont(TamLet+9, 0, 0, 0, 800, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TipLet);
}
}
}
bool Exists(CHAR* fname)
{
if(INVALID_FILE_ATTRIBUTES == GetFileAttributes(fname) && GetLastError()==ERROR_FILE_NOT_FOUND)
return false;
return true;
}
bool ProcessRunning( const char* name )
{
HANDLE SnapShot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
int siono = 0;
if( SnapShot == INVALID_HANDLE_VALUE )
return false;
PROCESSENTRY32 procEntry;
procEntry.dwSize = sizeof( PROCESSENTRY32 );
if( !Process32First( SnapShot, &procEntry ) )
return false;
do
{
if( strcmp( procEntry.szExeFile, name ) == 0 )
{
if (siono == 0)
{
siono = 1;
}
else
return true;
}
}
while( Process32Next( SnapShot, &procEntry ) );
return false;
};
void Pantalla(HWND oDlgVen, HINSTANCE hInst)
{
HWND oPant,oPan2,oPan4,oPan401,oPan402,oMenPan,oMenPan01,oMenPan02,oMenPan03,oMenPan04,oMenPan05,oMenPan06,oMenPan07,oMenPan08,oMenPan09;
TSay oSay = TSay(hInst, 10*TamPan, 30*TamPan, wtex000, oDlgVen, oFont, escri1, fondo2,1020*TamPan, 77*TamPan, 0, 1, oPan4);
oSay = TSay(hInst, 35*TamPan,340*TamPan, wtex000, oDlgVen, oFon3, escri1, fondo1, 630*TamPan, 30*TamPan, 1, 1, oPan401);
oSay = TSay(hInst, 36*TamPan,341*TamPan, wtex001, oDlgVen, oFon3, escri3, fondo1, 628*TamPan, 28*TamPan, 0, 1, oPan402);
oSay = TSay(hInst, 95*TamPan, 30*TamPan, wtex000, oDlgVen, oFont, escri3, fondo1, 245*TamPan,555*TamPan, 0, 0, oMenPan);
oSay = TSay(hInst,117*TamPan, 45*TamPan, wtex002, oDlgVen, oFont, escri1, fondo1, 243*TamPan, 28*TamPan, 0, 0, oMenPan01);
oSay = TSay(hInst,147*TamPan, 45*TamPan, wtex003, oDlgVen, oFont, escri1, fondo1, 243*TamPan, 28*TamPan, 0, 0, oMenPan02);
oSay = TSay(hInst,177*TamPan, 45*TamPan, wtex004, oDlgVen, oFont, escri1, fondo1, 243*TamPan, 28*TamPan, 0, 0, oMenPan03);
oSay = TSay(hInst,207*TamPan, 45*TamPan, wtex008, oDlgVen, oFont, escri1, fondo1, 243*TamPan, 28*TamPan, 0, 0, oMenPan04);
oSay = TSay(hInst,237*TamPan, 45*TamPan, wtex009, oDlgVen, oFont, escri1, fondo1, 243*TamPan, 28*TamPan, 0, 0, oMenPan05);
oSay = TSay(hInst,267*TamPan, 45*TamPan, wtex010, oDlgVen, oFont, escri1, fondo1, 243*TamPan, 28*TamPan, 0, 0, oMenPan06);
oSay = TSay(hInst,297*TamPan, 45*TamPan, wtex011, oDlgVen, oFont, escri1, fondo1, 243*TamPan, 28*TamPan, 0, 0, oMenPan07);
oSay = TSay(hInst,327*TamPan, 45*TamPan, wtex012, oDlgVen, oFont, escri1, fondo1, 243*TamPan, 28*TamPan, 0, 0, oMenPan08);
oSay = TSay(hInst,357*TamPan, 45*TamPan, wtex013, oDlgVen, oFont, escri1, fondo1, 243*TamPan, 28*TamPan, 0, 0, oMenPan09);
oSay = TSay(hInst, 95*TamPan,300*TamPan, wtex000, oDlgVen, oFont, escri1, fondo2, 750*TamPan,555*TamPan, 1, 0, oPant);
oSay = TSay(hInst,105*TamPan, 30*TamPan, wtex000, oDlgVen, oFont, escri1, fondo2, 280*TamPan, 25*TamPan, 1, 0, oPan2);
UpdateWindow(oDlgVen);
}
Todas las llamadas a la clase están al final del todo en Pantalla()
Me podéis ayudar para saber que error me está dando.
Un saludo
Carlos