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 


creating tabs for windows ....

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
kot1990
Expert Cheater
Reputation: 1

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Tue Apr 06, 2010 8:51 pm    Post subject: creating tabs for windows .... Reply with quote

I have a nightmare here with creating tabs for a window. I couldn't get it work, when I change to another tab the function CreateDialogIndirect() fails and the program crashes.

Here's the code

Code:
DLGTEMPLATE *apRes1;
   DLGTEMPLATE *apRes2;

   HRSRC hrsrc = FindResource(dahak,MAKEINTRESOURCE(IDD_TAB1),RT_DIALOG);
   HGLOBAL hglb = LoadResource((HINSTANCE)hInstance, hrsrc);
   apRes1 = (DLGTEMPLATE*)LockResource(hglb);

   hrsrc = FindResource(dahak,MAKEINTRESOURCE(IDD_TAB2),RT_DIALOG);
   hglb = LoadResource((HINSTANCE)hInstance, hrsrc);
   apRes2 = (DLGTEMPLATE*)LockResource(hglb);

   RECT rcClient;
   GetClientRect(mainDialog, &rcClient);

   InitCommonControls();

   tab = CreateWindow(WC_TABCONTROL, "",
        WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
        0, 0, rcClient.right, rcClient.bottom,
        mainDialog, NULL, (HINSTANCE)hInstance, NULL);

   TCITEM tabItem;

   tabItem.mask = TCIF_TEXT | TCIF_IMAGE;
   tabItem.iImage = -1;
   tabItem.pszText = "tab1";

   TabCtrl_InsertItem(tab,0,&tabItem);
   tabItem.pszText = "tab2";
   TabCtrl_InsertItem(tab,1,&tabItem);

   tab1 = GetDlgItem(mainDialog, IDD_TAB1);
   tab2 = GetDlgItem(mainDialog, IDD_TAB2);

   currTab = tab1;


Ok, the tab thing is created in a dialog (mainDialog), I got the 2 tabs visible with labels "tab1" and "tab2" as they supposed to be. The mainDialog procedure for the tab is this:

Code:
case WM_NOTIFY:
         switch (((LPNMHDR)lParam)->code)
         {
            case TCN_SELCHANGE:
               iSel = TabCtrl_GetCurSel(tab);
               if(iSel == 1)
               {
                  DestroyWindow(currTab);
                  currTab = CreateDialogIndirect((HINSTANCE)hInstance, apRes2, mainDialog, childDlgProc2);
                  
               }
            break;
         }
      break;


I made this just for testing, when iSel == 1 then the second tab has just been selected, the one with the label "tab2", then the CreateDialogIndirect() executes and the program crashes. If I comment out this function nothing crashes, I eved tried to put a messagebox there and it shows.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Apr 07, 2010 8:40 am    Post subject: Reply with quote

I'm not sure you should use DestroyWindow() for ending a dialog, instead use EndDialog(). If you could post more of your code it would help..
Back to top
View user's profile Send private message
kot1990
Expert Cheater
Reputation: 1

Joined: 06 Sep 2009
Posts: 131
Location: Greece

PostPosted: Thu Apr 08, 2010 9:35 pm    Post subject: Reply with quote

thx, but I already found my way to do it. I played a little bit with ShowWindow() setting it true or false, so the dialog just hides. The DestroyWindow() destroys completely the window and then CreateDialogIndirect() creates another window with different handles everytime. I don't want this to happen and lose the controls. So I did like this:

Code:

DLGTEMPLATE * WINAPI DoLockDlgRes(LPCSTR lpszResName)
{
    HRSRC hrsrc = FindResource(dahak, lpszResName, RT_DIALOG);
    HGLOBAL hglb = LoadResource(dahak, hrsrc);
    return (DLGTEMPLATE *) LockResource(hglb);
}

void createTabs()
{
   RECT rcClient;
   GetClientRect(mainDialog, &rcClient);

   InitCommonControls();

   tab = CreateWindow(WC_TABCONTROL, "",
        WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
        0, 0, rcClient.right, rcClient.bottom,
        mainDialog, NULL, (HINSTANCE)hInstance, NULL);

   TCITEM tabItem;

   tabItem.mask = TCIF_TEXT | TCIF_IMAGE;
   tabItem.iImage = -1;
   tabItem.pszText = "attack";

   TabCtrl_InsertItem(tab,0,&tabItem);
   tabItem.pszText = "items";
   TabCtrl_InsertItem(tab,1,&tabItem);

   apRes1 = DoLockDlgRes(MAKEINTRESOURCE(IDD_TAB_ATTACK));
   apRes2 = DoLockDlgRes(MAKEINTRESOURCE(IDD_TAB_ITEMS));

   attack_tab_hwnd = CreateDialogIndirect((HINSTANCE)hInstance, apRes1, mainDialog, childDlgProc);
   items_tab_hwnd = CreateDialogIndirect((HINSTANCE)hInstance, apRes2, mainDialog, childDlgProc2);
   SetWindowPos(attack_tab_hwnd,HWND_TOP,0,30,0,0,SWP_NOSIZE);

   SetDlgItemText(attack_tab_hwnd,EDIT_FARMR,"1000");
}

HWND findCorrectTabHide(int lastTab)
{
   if(lastTab == 0)
      return attack_tab_hwnd;
   else if(lastTab == 1)
      return items_tab_hwnd;
}


and the process

Code:

case WM_NOTIFY:
         switch (((LPNMHDR)lParam)->code)
         {
            case TCN_SELCHANGE:
               tabSel = TabCtrl_GetCurSel(tab);
               if(tabSel == 0)
               {
                  ShowWindow(findCorrectTabHide(lastTabSel),SW_HIDE);
                  lastTabSel = tabSel;
                  ShowWindow(attack_tab_hwnd,SW_SHOW);
                  SetWindowPos(attack_tab_hwnd,HWND_TOP,0,30,0,0,SWP_NOSIZE);
                  
               }
               else if(tabSel == 1)
               {
                  ShowWindow(findCorrectTabHide(lastTabSel),SW_HIDE);
                  lastTabSel = tabSel;
                  ShowWindow(items_tab_hwnd,SW_SHOW);
                  SetWindowPos(items_tab_hwnd,HWND_TOP,0,30,0,0,SWP_NOSIZE);
               }
            break;
         }
      break;


EDIT: the crash was happening because apRes1 and apRes2 were declares locally but I had also global apRes1 and apRes2 and they were null when CreateDialogIndirect() executed.
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