Go Premium for a chance to win a PS4. Enter to Win


How do i show Run dialog from C code?

Posted on 2009-03-30
Medium Priority
Last Modified: 2013-12-14
How do i show Run dialog from cpp code? I couldn't find a solution on internet :(
Question by:Shershen
LVL 46

Expert Comment

by:Kent Olsen
ID: 24020603
Hi Shershen,

If you really are using C++ Builder, simply drop any of the dialog box controls onto your form.  Then from within the C code, execute that box.

  TDiaglog *MyDialog = new ....;
  MyDialog->Execute ()


Author Comment

ID: 24020648
Yes, I'm using c++ builder, but I need to show Run dialog from Start menu.
LVL 46

Expert Comment

by:Kent Olsen
ID: 24020696
It sounds like a communications issue.

By "Start menu" do you mean the "file" menu or something else?

For most any place that you want to show the dialog box, the code is the same.  You simply need to execute it.

Note that dialog boxes are modal, meaning that the user can not access other parts of the application until the dialog box closes.  If you put the dialog box as part of the application's startup code, the user will always have to complete the dialog box before the application can resume.

Independent Software Vendors: 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!

LVL 39

Expert Comment

ID: 24021982
>>>> By "Start menu" do you mean the "file" menu or something else?

Probably the Windows Start menu.

I don't know whether there is an Active-X available for Run Dialog, but you easily could make your own using the resource editor, create a dialog instance and call execute member function. and invoke the command entered by the user via ShellExecute.

  TDialog * ptrRunDialog = new MyRunDialog();
  ptrRunDialog->Execute ();


Author Comment

ID: 24023030
Seems my english is quite bad :)

Press Win+R - I need to show this dialog from my program, using some API function or interface or rundll32 or something else.
LVL 46

Expert Comment

by:Kent Olsen
ID: 24023655
Ok.  If I get this correct...

The application's main form (just like any other form) traps a bunch of events that you can process.

Create an OnKeyPress event handler for the main form.  (In the "Object Inspector", click the "Events" tab, then double click OnKeyPress.  The IDE will create the method and put you into the editor within the new method.

Within the handler, check to see if the value of Key is what you want.  (I have no idea what the Win+R key combination is.)  If it is your key, open the dialog box as shown above and set the value of Key to 0 (zero) before the method exits.  If the value of Key is not a keypress that you want to handle, simply leave it alone

Good Luck,

void fastcall TMainForm::FormKeyPress (TObject *Sender, char &Key)
  if (Key == 'R')  // Key on 'R' (as an example)
    TDiaglogBox *Dialog = new TDialogBox (this);
    if (Dialog->Execute ())
//      Do Something
    Key = 0;

Open in new window


Accepted Solution

Shershen earned 0 total points
ID: 24023695
Solved by this code:

Variant V;
V = CreateOleObject("Shell.Application");
LVL 49

Expert Comment

ID: 24023865
Shershen, Good job, You have solved this yourself!  Click the "Accept As Solution" button in your above answer.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

926 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