Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: josue9243 en 31 Diciembre 2018, 21:51 pm



Título: Sobre Crear pestañas CreateWindowExA etc
Publicado por: josue9243 en 31 Diciembre 2018, 21:51 pm
Hola, queria saber porque tengo un problemita a la hora de utilizar CreateWindowExA.

Resulta que yo estaba creando una DLL que crea botones DENTRO de un programa externo, y lo hago de la siguiente forma:

El tema es que al CREAR este nuevo boton en el programa, resulta que ESTE BOTON UTILIZA EL WNDPROC DE EL PROGRAMA Y EXPLOTA TODO Y NO USA EL DE MI DLL, queria saber si alguien sabe como realizar esto que quiero de la forma correcta.

(CABE DESTACAR QUE EL BOTON SE CREA TODO, PERO AL APRETARLO EXPLOTA T2)

Código:
HWND hwnd;
LRESULT CALLBACK WndProc(HWND hwndMain, UINT uMsg, WPARAM wParam, LPARAM lParam);

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
)
{
if (ul_reason_for_call)
{
DisableThreadLibraryCalls(hModule);
DbgPrint("Injected1");
hwnd = FindWindowA( NULL, "MiProgramaExterno");
WNDCLASSEX windowClass;
windowClass.lpszClassName = L"Main Class";
windowClass.cbClsExtra = NULL;
windowClass.cbWndExtra = NULL;
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(240,240,240));
windowClass.hCursor = LoadCursor(NULL,IDC_ARROW);
windowClass.hIcon = LoadIconA(hModule, "ICONO");
windowClass.hIconSm = LoadIconA(hModule, "ICONO");
windowClass.hInstance = hModule;
windowClass.lpfnWndProc = WndProc;
windowClass.lpszMenuName = NULL;
windowClass.style = CS_VREDRAW | CS_HREDRAW;
RegisterClassEx(&windowClass);
//(HINSTANCE)GetWindowLongW(hwnd, GWL_HINSTANCE)


/*HWND Main = CreateWindowExW(NULL,L"Main Class",L"nuevapestañaaldope",
  WS_OVERLAPPEDWINDOW | WS_VISIBLE,
  100,100,500,500,
  NULL,NULL,hModule,NULL);*/

MSG msg;
while(GetMessageW(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}
return TRUE;
}


LRESULT CALLBACK WndProc(HWND ahwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
{
HWND hwndButton = CreateWindowW( L"BUTTON", L"ok", WS_CHILD | WS_VISIBLE,10,10,100,100,hwnd,(HMENU)1,hModule, NULL);
}
break;
case WM_COMMAND:
{
if(LOWORD(wParam) == 1)
{
MessageBoxA( ahwnd, "qwe", 0, 0 );
}
}
case WM_PAINT:
{
PAINTSTRUCT Ps;
HDC hdc;
hdc= BeginPaint(ahwnd,&Ps);
// SetBkColor(hdc,RGB(0,0,0));
//SetTextColor(hdc,RGB(0,0,0));
// TextOut(hdc,200,150,L"Hello World!",12);

EndPaint(ahwnd,&Ps);
}
break;
case WM_CLOSE:
{
PostQuitMessage(WM_QUIT);
}
break;
default:
return(DefWindowProc(ahwnd,message,wParam,lParam));
}

return(0);
}


Título: Re: Sobre Crear pestañas CreateWindowExA etc
Publicado por: fary en 1 Enero 2019, 19:35 pm
Intenta con SubClassing  :)

https://docs.microsoft.com/en-us/windows/desktop/winmsg/about-window-procedures