?
Solved

Win32 GUI application problem with dialog box.

Posted on 2003-03-13
14
Medium Priority
?
514 Views
Last Modified: 2008-02-01
I am useing -
     DialogBox(hInst, (LPCTSTR)IDD_Main, NULL , (DLGPROC)mainhandle);
to create a dialog box.
It works fine BUT if I try to put some types of controls on the dialog box resorce
It will not wrok. I can put buttons and text on the dialog but if I try to put a
tab control on the form it will not work. Why is this and how do I fix it?
Thank you for your time,
Arrummzen
0
Comment
Question by:Arrummzen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +3
14 Comments
 
LVL 5

Expert Comment

by:Kocil
ID: 8134712
Hi mate.

What is tab control ?
Please describe your 'not working' term. Does it cause the dialog to crash or just It can't respond to any input.

I'm not sure about the problem, because I did this maybe 5 years ago. I can't believe somebody is still doing this on C :)

0
 
LVL 1

Author Comment

by:Arrummzen
ID: 8136303
A tab Control is a control like a button. If you rite click on mycomputer and then from the drop down menue select Properties then you will see a tab control. You can click on differnt "tabs" to get differt kinds of information.
Basicly when I call -
     DialogBox(hInst, (LPCTSTR)IDD_Main, NULL , (DLGPROC)mainhandle);
on a from without a tab control on it the form shows, if I have a tab control on the form the form does not show. The form does not show and the program continues to execute as notmal.
Thank you for your time,
Arrummzen
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 8136497

Check the Tab Control's properties.  Make sure that the number of tabbed items (pages) is not zero.  Also make sure that the control actually fits on the DialogBox, etc.

Kdo
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:Nosfedra
ID: 8138105
You are not using correctly the template name parameter:
DialogBox(hInst, (LPCTSTR)IDD_Main, NULL , (DLGPROC)mainhandle);

This should be :
DialogBox(hInst, MAKEINTRESOURCE(IDD_Main), NULL , (DLGPROC)mainhandle);

I am not sure, but this could be the root of your problem.
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 8139622
A tab Control is a control like a button. If you rite click on mycomputer and then from the drop down menue select Properties then you will see a tab control. You can click on differnt "tabs" to get differt kinds of information.
Basicly when I call -
     DialogBox(hInst, (LPCTSTR)IDD_Main, NULL , (DLGPROC)mainhandle);
on a from without a tab control on it the form shows, if I have a tab control on the form the form does not show. The form does not show and the program continues to execute as notmal.
Thank you for your time,
Arrummzen
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 8139643
"Check the Tab Control's properties.  Make sure that the number of tabbed items (pages) is not zero.  Also make sure that the control actually fits on the DialogBox, etc."
The control fits. I dont know how to check the number of tabbed items, there is no "number of pages" property.
How do I set the number of pages (I am useing Visual Studio .NET).

"You are not using correctly the template name parameter:
DialogBox(hInst, (LPCTSTR)IDD_Main, NULL , (DLGPROC)mainhandle);

This should be :
DialogBox(hInst, MAKEINTRESOURCE(IDD_Main), NULL , (DLGPROC)mainhandle);

I am not sure, but this could be the root of your problem. "

I tryed it and it still does not work, any other ideas?
Thank you for your time,
Arrummzen
0
 
LVL 1

Expert Comment

by:Hermetic
ID: 8141713
Not sure about .NET, but in VC++6.0:
If the Tab Control is an ActiveX component, you need to call CoInitialize(NULL) when starting and CoUninitialize() when stopping the application.
0
 
LVL 3

Expert Comment

by:Nosfedra
ID: 8141758
CoInitialize and CoUninitialize are COM functions and they don't have much to do with tab controls! Not even in ActiveX.

Now, after getting really intrigued by Arrummzen's problem I decided to try it myself and indeed, nothing happens once I've added the tab controls.

I remembered that I was trying to do this with win32 API some distant past ago, when internet was -9 months old, but coulnd't get it to work.
That's because there are some funny things you have to do.


The reason I believe your dialog fails to load is because the tab control has no tabs in it.
Have you tried to add some?
You have to create some child dialog boxes and remeber their IDD_xxx. You make the dialog box a child by selecting the dialog->Properties->Styles->Style::Chose Child.

Then fill in a TCITEM structure with the needed data (basically the name of the tab) and send a TCM_INSERTITEM message.

For really handling the tab dialogs, try to get some info out of
http://203.157.250.93/win32asm/TabTutorial.txt.

This is really a win32asm stuff, but you might extract the meaning from there. It's helpful enough, believe me...

If you still want/have to do it, let me know how its working on...
This is 1000 times easier when done with MFC, if this is an option at all.
0
 
LVL 1

Expert Comment

by:Hermetic
ID: 8141806
Wow, Nosfedra, I didn't realize this was a news group and allowed bashing of the participants.  I must remember to keep my simple musings to myself in light of your obvious expertise.
0
 
LVL 3

Expert Comment

by:Nosfedra
ID: 8141858
I didn't mean to "bash" anybody so don't feel insulted by my post.
After all, "reasonable people have been known to disagree", right?

From time to time I get my round of mistakes as well and I don't mind people telling me so.
It's all for the progress, as I see it, so feel free to "bash" me if I am making mistakes, I don't mind.

0
 
LVL 1

Author Comment

by:Arrummzen
ID: 8144942
I wish I could do this with MFC but I need to be able to directly interprit the event loop.

"Then fill in a TCITEM structure with the needed data (basically the name of the tab) and send a TCM_INSERTITEM message."
How do I give the TCITEM struct the name of the child tab I want? My documentation lists only the following members -
TCIF_IMAGE The iImage member is valid.  
TCIF_PARAM The lParam member is valid.
TCIF_RTLREADING  The string pointed to by pszText will be displayed in the direction opposite to the text in the parent window.
TCIF_STATE Version 4.70. The dwState member is valid.
TCIF_TEXT The pszText member is valid.
Thank you for your time,
Arrummzen
0
 
LVL 1

Expert Comment

by:cybeonix
ID: 8147329
Be sure to call InitCommonControls() prior to using any windows objects, the class may not be initialized for your application.
0
 
LVL 3

Accepted Solution

by:
Nosfedra earned 1000 total points
ID: 8150682
Ok here goes...
As cybeonix pointer, you should be calling InitCommonControlsEx to initialize the tab control class for the application. I would simply reproduce what MSDN has to say about that so please take a look to that function.

You should do:
INITCOMMONCONTROLSEX inc;
  inc.dwICC = ICC_TAB_CLASSES ;
  InitCommonControlsEx(&inc);
 
Watch out, as for other controls you have to add the other control flags of dwICC as well, according to the controls you want to use... Or, as a hack, try setting 0xFFFFFFFF; to idc.dwICC, to select all the controls to be loaded from the commctl32 DLL.

Now, in your WM_INITDIALOG portion of your program, you should try to initialize your tab control. Create a function that simply does that: adds the tabs to your tab control. You could pass the pointer of the window containing the tab control to the function or the tab itself.

If you pass the parent handle, just get the tab control handle with GetDlgItem and the use SendMessage(TCM_INSERTITEM...) to this very window.
You can use also the provided macro TabCtrl_InsertItem, which is more convenient.

Try to get inspired by the following code, I wrote it and it works. For the handling of the Tab Controls, try the reference I wrote you or try to see the MSDN for:
"Tab Controls".

HTH:

void InsertChildTabs(HWND wnd)
{
     HWND tab = GetDlgItem(wnd,IDC_TAB1);
     if (tab)
     {
          TCITEM tc;
          tc.mask = TCIF_TEXT;
          tc.pszText = _T("TAB one");
          TabCtrl_InsertItem(tab,0,&tc);

          tc.mask = TCIF_TEXT;
          tc.pszText = "TAB Two";
          TabCtrl_InsertItem(tab,1,&tc);
         
          tc.mask = TCIF_TEXT;
          tc.pszText = "TAB Three";
          TabCtrl_InsertItem(tab,2,&tc);
     }
}

BOOL CALLBACK EditDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
  char szText[BUFFER_SIZE];

  switch(Message)
  {
     case WM_INITDIALOG:
        InsertChildTabs(hwnd);
     return TRUE;
     case WM_COMMAND:
           case IDCANCEL:
              EndDialog(hwnd, IDCANCEL);
           return TRUE;
        }
     break;
  }
  return FALSE;
}



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  LPSTR lpCmdLine, int nCmdShow)
{
  int ret;
  INITCOMMONCONTROLSEX inc;
  inc.dwICC = 0xFFFFFFFF;
  InitCommonControlsEx(&inc);
  ret = DialogBox(hInstance, MAKEINTRESOURCE(AHAHA), NULL, EditDlgProc);
  /* all kind of groovy stuff here */
}

Regards,
--Razvan
0
 
LVL 1

Author Comment

by:Arrummzen
ID: 8296477
Thank you, With a little tinkering I got it to work, sory I took so long to respond, I am very bussy lately.
Thank you for your time,
Arrummzen
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question