ShellExecute at the start of my program

Ok, I put ShellExecute in my code here:

1
2
3
4
5
ShowWindow (hwnd, nFunsterStil);
    while (GetMessage (&messages, NULL, 0, 0))
    {
    
   ShellExecute(NULL, "Open", "C:\\Program Files\\My Prgram\\Data.txt", NULL, NULL, SW_SHOWNORMAL);


And I compiled it and...over 50 notepads came up :( my computer lagged like crazy.

So, where is the proper place to put it? (I had Dev C++ generate code for the window)

Is this in the right place? I'm a rather new to C++, is this a question for the beginner forum?
Last edited on
closed account (o3hC5Di1)
Hi there,

Not too familiar with Dev C++ and it's GUI capabilities, but you definitely want to take the execute out of the while loop as such:

1
2
3
4
ShowWindow (hwnd, nFunsterStil);
   ShellExecute(NULL, "Open", "C:\\Program Files\\My Prgram\\Data.txt", NULL, NULL, SW_SHOWNORMAL);
    while (GetMessage (&messages, NULL, 0, 0))
    {


If not, the while loop keeps opening notepad until the GetMessage() function returns false.

Hope that helps.

All the best,
NwN
OK, I moved it and it works perfectly:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    hwnd = CreateWindowEx (
           0,                   
           szClassName,
           "My Program",
           WS_SYSMENU,
           CW_USEDEFAULT,
           CW_USEDEFAULT,
           544,
           375, 
           HWND_DESKTOP,
           NULL,
           hThisInstance,
           NULL
           );


     ShellExecute(NULL, "Open", "C:\\Program Files\\My Program\\Data.txt", NULL, NULL, SW_SHOWNORMAL);

ShowWindow (hwnd, nFunsterStil);
Last edited on
closed account (o3hC5Di1)
Supposedly in your main() function.

Make sure you don't put it into a while loop or other control structure (if/else) though.

If this would be a bad idea for a GUI application someone please do correct me.

All the best,
NwN
Topic archived. No new replies allowed.