WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.


Control Manager

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Click a Button without Hanging

Keywords: cClickButton cPostMessage   

Use cPostMessage Rather than cClickButton Method:

I am working on a script that runs an app using control manager functions. There is a problem when I click a button to open a font selection window. Once I click the button using cClickButton, winbatch seems to stop doing anything until I (interactively)close the window out before executing the next statement. If I have debug on, the debug window disappears until the font window is closed.

When I close the font window the fontwnd=dllwhnd statement tries to execute and fails since the window has gone away.


  1. Download latest Control Manager extender.

  2. Instead of using cClickBtn to click the button, try using the method shown in the cPostMessage example. It shows how to click a button without hanging.

    Although the method used in cClickButton is the recommended procedure, we have found that indeed it hangs in certain places.

    With SendMessage, a message is sent and the program waits for a response for each message.

    With Postmessage it does not wait for a response, so if some program is not does not stop.

Related Question:

I have noticed a disturbing problem with cClickButton. On some buttons that cause a dialog box to be displayed when the button is clicked the cClickButton function will not return until the dialog has been closed.

The two situations where I have noticed this behaviour so far are the Add button on the 'Network' configuration dialog that brings up the 'Select Network Component type' dialog. and the chdir button on ws_ftp32. Both of these examples running on windows 95.

I would like to see cClickbutton returning normally after clicking the buttons. I might be able to use SendKeys to get around this temporarily, but I would not be a workable long-term solution.


Some dialogs are like this. Most dialogs seem to prefer the cClickButton the way we do it. However, if you look at the example for cPostMessage, it shows an alternate way of clicking the button that does not hang it up.

Question on Clicking Button in MS Access:

I'm having trouble getting around a message box from MS Access. I'm attaching Oracle tables in MS Access. When I get to the Attach Tables window, choose a table and click on Attach (all using WinBatch), I get a message saying that the attachment worked all right. This message box stalls the batch program until I hit the OK button. I've tried to get rid of this message box using the batch program, but since the batch program is halted, nothing I can think of will work. Do you have any suggestions?

A piece of what I was working on is below. I get stalled out at the "XXXX".

WinActivate("Attach Tables") ;an Access window

parentwnd=DLLHwnd("Attach Tables")
chldlistbox=cWndByClass(parentwnd,"ListBox") ;list of sql tables on oracle server

tabletoattach=ItemLocate("ACS.CENSUS", listresponse, @TAB) ;look for particular table (usually a var)

clickattach=cClickButton(chldatchbtn) ;XXXX click on Attach button

messagewnd=DLLHwnd("Microsoft Access") ;try to get "Attachment worked" message box handle
msgwndmsg=cWndBySeq(messagewnd,4) ;get actual message handle

If msgwndmsg=="Successfully attached 'ACS_CENSUS_G_ID'." ;kill message box
Pause("Attach Error","An error occurred while attaching!%@crlf%Continue Attaching other tables?")


Look up the cPostMessage function in later versions of the Control Manager extender. It shows a different way to click the button.

Thread continued:

You were right. Using the PostMessage(chldatchbtn,245,0,0) command let the batch file continue running and I was able to cancel the message box no problem. Thanks.

Question on Clicking Network Control Panel Button:

I'm using the following code:

;Open the Network Control Panel
Run("rundll32.exe", "shell32.dll,Control_RunDLL netcpl.cpl")

;Get a handle to the Network Control Panel

;Get a handle to the Configuration Tab
hwConfiguration= cWndByName(hNetworkCP,"Configuration")

;Click the Add button
hbAdd=cWndByName(hwConfiguration, "Add...")

cPostMessage(hbAdd,245,0,0)   ; 245 == BM_CLICKED
message("hello", "there")
The problem is that if you try to do *anything* to the dialog (Select Network Component Type), I keep getting the window not found error.

I've used every function I can think of and I CANNOT get a handle to this window.

When I use the next two lines to choose the window (Select Network Component Type) that comes up

I don't think the above two lines work because the Message always pops up 0 for the handle when I try to display the handle in a message statement:
Finally, this line then *ALWAYS* gives an error saying "parent window does not exist" which makes me think that DLLHwnd is not returning a valid handle on the statement:
	>hlbMCMN=cWndByID(hAddWindow, 504)
Help! I need a handle.


You have to work further on:


A note regarding tabbed dialogs:

You MUST select the tab before going after the control in question. The trick is that Windows does not even bring the controls into existence until the tab is clicked.

So use the ummm cSetTabItem function to select the tab, do a small TimeDelay, then go after the control.

Clicking Button in MS Outlook:

I'm using the following code. I've tried both the cClickButton and cPostMessage, but sometimes it works, and others it hangs.
If WinExistChild("Microsoft Outlook 97 Setup", "Product ID:")
  ParentWnd=DllHwnd("Microsoft Outlook 97 Setup")


It appears that my problem was being caused by my Winbatch and Outlooks Setup.EXE fighting too much for being the active window. My winbatch was updating the status bar and bringing the status bar to the foreground every second. Outlook's Setup also was bringing its window to the foreground very quickly. I modified my winbatch to come to the foreground every 5 seconds and everything seems to be working now.
Article ID:   W12508
Filename:   How to Click a Button without Hanging.txt
File Created: 2017:07:28:13:58:26
Last Updated: 2001:06:14:16:35:34