Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendMessage & TCM_GETCURSEL/TCM_SETCURSEL 1

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
Hi,

I am trying to locate a certain tabbed dialog, then get and set its' currently selected tab. I've successfully used FindWindow to get the handle of the dialog. And have tried to send a TCM_GETCURSEL message and it always returns zero, even when different tabs are selected. I'm doing this in Delphi but my code should be easy to read:
Code:
  hDialog := FindWindow('#32770', PChar(DialogName));
  if hDialog > 0 then
    ShowMessage(IntToStr(SendMessage(hDialog, TCM_GETCURSEL, 0, 0)));

Your help would be much appreciated!

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Hi Stretchwickster,

I think you have to find a child handle inside hDialog, which is TAB class control (SysTabControl32). Then send a message to hTab

Regards

-- AirCon --
 
I agree with AirCon, you do not have the right handle yet. You need to get a pointer to the tab control. If you designed the dialog, you probably already have assigned it a resource id. You can use this to get a pointer to the control.

Below I've included the Windows API function that you will use to get the handle that you will need.

****************************************
GetDlgItem
The GetDlgItem function retrieves a handle to a control in the specified dialog box.

HWND GetDlgItem(
HWND hDlg, // handle to dialog box
int nIDDlgItem // control identifier
);
Parameters
hDlg
[in] Handle to the dialog box that contains the control.
nIDDlgItem
[in] Specifies the identifier of the control to be retrieved.
Return Values
If the function succeeds, the return value is the window handle of the specified control.

If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control. To get extended error information, call GetLastError.

Remarks
You can use the GetDlgItem function with any parent-child window pair, not just with dialog boxes. As long as the hDlg parameter specifies a parent window and the child window has a unique identifier (as specified by the hMenu parameter in the CreateWindow or CreateWindowEx function that created the child window), GetDlgItem returns a valid handle to the child window.

Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.
****************************************


Hope this helps you.
 
Thanks for the replies guys. AirCon was the first to identify the problem so he gets the star. Thanks for the extra info bcravens but I didn't create the dialog.

Basically, I was trying to open the properties dialog of a specified file/folder and automatically select its' "Sharing" tab. I've got it to work with the following process:
- I invoked the properties dialog using ShellExecuteEx
- I used FindWindow to locate this dialog (as shown above)
- I then called FindWindowEx with 'SysTabControl32' as one of its parameters to find the tab control
- I then used TCM_SETCURSEL as a parameter of SendMessage to change the tab

But there's still one annoyance with it. I tried to use WaitForInputIdle to wait for the process to finish before changing the tab but I couldn't get this to work and ended up using a sleep command for 5 seconds which is a pretty inefficient way of doing it. The line I used was:
Code:
  WaitForInputIdle(hProcess, INFINITE);
where hProcess was obtained from the ShellExecuteInfo structure.

Any ideas?

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Another problem I have just noticed is that although the tab changes, the tab page does not. So the "Sharing" tab is selected but the "General" page is still displayed. Is there another message I need to send?

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
I don't play with tab control much. I have no idea why WaitForInputIdle failed. Just to remind you that hProcess from ShellExecuteEx can return a NULL value on some condition.

For the tab problem, the easy way to activate the corresponding windows for that tab, is send a CTRL-TAB key using keybd_event

VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // function options
ULONG_PTR dwExtraInfo // additional keystroke data
);

keybd_event(VK_CONTROL, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_TAB, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_CONTROL, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);

Perhaps someone can comeup with a better solution :)
Regards

-- AirCon --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top