Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ problem closing

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Sun Nov 02, 2008 4:29 am    Post subject: C++ problem closing Reply with quote

so ive got this code im trying to test out :


Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>
#include <stdlib.h>


BOOL CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   UNREFERENCED_PARAMETER(lParam);
   switch(uMsg)
   {
   case WM_INITDIALOG:
      DWORD dwStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
                dwStyle = dwStyle | WS_EX_LAYERED;
                SetWindowLong(hWnd, GWL_EXSTYLE, dwStyle);
SetLayeredWindowAttributes(hWnd, 0, (255 * 70) / 100, LWA_ALPHA);

      return TRUE;

   }
   return FALSE;
}


void stuff(){
   for (;;) {
      Sleep(100);
   }
}

int main(void)
{

   // Generated by ResEdit 1.4.4.6
// Copyright (C) 2006-2008
// http://www.resedit.net

HINSTANCE hInst = GetModuleHandle(0);
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof wcex);
wcex.cbSize         = sizeof wcex;
wcex.hbrBackground  = (HBRUSH)(COLOR_3DFACE + 1);
wcex.lpszMenuName   = 0;


wcex.style          = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc    = DefWindowProc;
wcex.hInstance      = hInst;
wcex.hIcon          = LoadIcon(0, (LPCTSTR)IDI_APPLICATION);
wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
wcex.lpszClassName  = L"WndClass0";
RegisterClassEx(&wcex);

HFONT hfont0 = CreateFont(-11, 0, 0, 0, 0, FALSE, FALSE, FALSE, 1, 0, 0, 0, 0, L"Ms Shell Dlg 2");
HWND hwnd = CreateWindowEx(WS_EX_WINDOWEDGE, L"WndClass0", L"Test", WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_SYSMENU, 0, 0, 392, 224, 0, 0, hInst, 0);
HWND hCtrl0_0 = CreateWindowEx(0, TRACKBAR_CLASS, 0, WS_VISIBLE | WS_CHILD | WS_TABSTOP | TBS_BOTH | TBS_NOTICKS, 99, 67, 192, 62, hwnd, 0, hInst, 0);
SendMessage(hCtrl0_0, WM_SETFONT, (WPARAM)hfont0, FALSE);

CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)stuff, 0, 0, NULL);
return 0;
}


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                )
{
   switch (ul_reason_for_call)
   {
   case DLL_PROCESS_ATTACH:
         DisableThreadLibraryCalls(hModule);
         CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)main, hModule, 0, NULL);
         break;
   case DLL_THREAD_ATTACH:
   case DLL_THREAD_DETACH:
   case DLL_PROCESS_DETACH:
         break;
   }
   return TRUE;
}


and thats all it is

so why does it close the window as soon as it opens

i inject the dll, the window flashes, and then is gone

im guessing theres something really simple ive missed here, anyone know?

_________________
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Sun Nov 02, 2008 8:35 am    Post subject: Reply with quote

I don't see a message loop?
Replace the 'CreateThread(..., stuff, ...);' with a normal message loop.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sun Nov 02, 2008 9:04 am    Post subject: Reply with quote

Code:
   case WM_CLOSE:
      EndDialog(hWnd, 0);
      return TRUE;

   case WM_DESTROY:
      PostQuitMessage(0);
      return TRUE;


Try adding in those cases

Oh lord thats not right at all. I just noticed that your lpfnWndProc = DefWndProc yet you have DlgProc as the message loop. You should set the lpfnWndProc to DlgProc

_________________
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Mon Nov 03, 2008 2:09 am    Post subject: Reply with quote

ok, still doesnt work, not sure why still, now it doesnt show up at all

Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>
#include <stdlib.h>


LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   DWORD dwStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
   UNREFERENCED_PARAMETER(lParam);
   switch(uMsg)
   {
   case WM_INITDIALOG:
      //DWORD dwStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
                dwStyle = dwStyle | WS_EX_LAYERED;
                SetWindowLong(hWnd, GWL_EXSTYLE, dwStyle);
SetLayeredWindowAttributes(hWnd, 0, (255 * 70) / 100, LWA_ALPHA);

      return TRUE;

   case WM_CLOSE:
      EndDialog(hWnd, 0);
      return TRUE;

   case WM_DESTROY:
      PostQuitMessage(0);
      return TRUE;

   }
   return FALSE;
}


void stuff(){
   for (;;) {
      Sleep(100);
   }
}

BOOL main()
{
MSG Msg;

HINSTANCE hInst = GetModuleHandle(0);
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof wcex);
wcex.cbSize         = sizeof wcex;
wcex.hbrBackground  = (HBRUSH)(COLOR_3DFACE + 1);
wcex.lpszMenuName   = 0;


wcex.style          = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc    = WndProc;
wcex.hInstance      = hInst;
wcex.hIcon          = LoadIcon(0, (LPCTSTR)IDI_APPLICATION);
wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
wcex.lpszClassName  = L"WndClass0";
RegisterClassEx(&wcex);

HFONT hfont0 = CreateFont(-11, 0, 0, 0, 0, FALSE, FALSE, FALSE, 1, 0, 0, 0, 0, L"Ms Shell Dlg 2");
HWND hwnd = CreateWindowExW(WS_EX_WINDOWEDGE, L"WndClass0", L"Test", WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_SYSMENU, 0, 0, 392, 224, 0, 0, hInst, 0);
HWND hCtrl0_0 = CreateWindowEx(0, TRACKBAR_CLASS, 0, WS_VISIBLE | WS_CHILD | WS_TABSTOP | TBS_BOTH | TBS_NOTICKS, 99, 67, 192, 62, hwnd, 0, hInst, 0);
SendMessage(hCtrl0_0, WM_SETFONT, (WPARAM)hfont0, FALSE);

CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)stuff, 0, 0, NULL);


   ShowWindow( hwnd, SW_SHOW );

   UpdateWindow( hwnd );

   while( GetMessage( &Msg, NULL, 0, 0 ) > 0 )
   {
      TranslateMessage( &Msg );
      DispatchMessage( &Msg );
   }
   return Msg.wParam;
}


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                )
{
   switch (ul_reason_for_call)
   {
   case DLL_PROCESS_ATTACH:
         DisableThreadLibraryCalls(hModule);
         CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)main, hModule, 0, NULL);
         break;
   case DLL_THREAD_ATTACH:
   case DLL_THREAD_DETACH:
   case DLL_PROCESS_DETACH:
         break;
   }
   return TRUE;
}

_________________
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Nov 03, 2008 2:38 pm    Post subject: Reply with quote

attached my old valueReader app

learn from it



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.


_________________
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 969
Location: --->

PostPosted: Mon Nov 03, 2008 3:48 pm    Post subject: Reply with quote

i've already got it, and ive dont lots of createwindow GUIs, but this doesnt want to work
_________________
Back to top
View user's profile Send private message
BirdsEye
Advanced Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 94

PostPosted: Mon Nov 03, 2008 4:06 pm    Post subject: Reply with quote

What are you trying to do? Are you trying to make something from a dialog? Very confusing... It looks like you're trying to mix dialogs with Win32. You obviously exported the C++ source code from ResEdit so just use that to create your window.

This works for me.

Code:

#define WIN32_LEAN_AND_MEAN

#define ID_CTRL   100

#include <windows.h>
#include <commctrl.h>
#include <tchar.h>

HFONT hFont = CreateFont(-11, 0, 0, 0, 0, FALSE, FALSE, FALSE, 1, 0, 0, 0, 0, L"Ms Shell Dlg 2");
HINSTANCE hInst;
HWND hCtrl;

void stuff()
{
   for(;;Sleep(100));
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   DWORD dwStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
   UNREFERENCED_PARAMETER(lParam);

     switch(uMsg)
    {
      case WM_CREATE:
         dwStyle = dwStyle | WS_EX_LAYERED;
         SetWindowLong(hWnd, GWL_EXSTYLE, dwStyle);
         SetLayeredWindowAttributes(hWnd, 0, (255 * 70) / 100, LWA_ALPHA);

         hCtrl = CreateWindowEx(0, TRACKBAR_CLASS, 0, WS_VISIBLE | WS_CHILD | WS_TABSTOP | TBS_BOTH | TBS_NOTICKS, 99, 67, 192, 62, hWnd, (HMENU)ID_CTRL, hInst, 0);
         SendMessage(hCtrl, WM_SETFONT, (WPARAM)hFont, FALSE);
         CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)stuff, 0, 0, NULL);
      break;
      
      case WM_CLOSE:
         DestroyWindow(hWnd);
      break;
      
      case WM_DESTROY:
         PostQuitMessage(0);
      break;

      default:
            return DefWindowProc(hWnd, uMsg, wParam, lParam);
   }

   return FALSE;
}

int MainLoop()
{
   HWND hWnd;
   MSG Msg;
   WNDCLASSEX wcex;

   ZeroMemory(&wcex, sizeof(wcex));

   wcex.cbSize         = sizeof(wcex);
   wcex.hbrBackground  = (HBRUSH)(NULL_BRUSH);
   wcex.lpszMenuName   = 0;
   wcex.style          = CS_HREDRAW | CS_VREDRAW;
   wcex.lpfnWndProc    = WndProc;
   wcex.hInstance      = hInst;
   wcex.hIcon          = LoadIcon(0, (LPCTSTR)IDI_APPLICATION);
   wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
   wcex.lpszClassName  = L"WndClass0";

   if(!RegisterClassEx(&wcex))
   {
      MessageBox(NULL, _T("Class registration failed!"), _T("Error!"), MB_ICONWARNING | MB_OK);
      return 0;
   }
   
   hWnd = CreateWindowEx(WS_EX_WINDOWEDGE, L"WndClass0", L"Test", WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_SYSMENU, 0, 0, 392, 224, 0, 0, hInst, 0);
   
   if(hWnd == NULL)
   {
      MessageBox(NULL, _T("Window creation failed!"), _T("Error!"), MB_ICONWARNING | MB_OK);
   }

   ShowWindow(hWnd, SW_SHOW);
   UpdateWindow(hWnd);

   while(GetMessage(&Msg, NULL, 0, 0) > 0)
   {
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);
   }
   
   return Msg.wParam;
}


BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
   if(dwReason == DLL_PROCESS_ATTACH)
   {
      DisableThreadLibraryCalls(hModule);
      CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MainLoop, hModule, 0, NULL);
   }

   return TRUE;
}


EDIT:
If you want to add code, say to a button. In your windows procedure add the WM_COMMAND notification. And then a switch statement to wParam. Like so:

Code:

. . .
case WM_COMMAND:
     switch(wParam)
     {
           case CTRL_ID:
                //Code here
           break;
           . . .
     }
break;
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites