beginner program in Win32 help pls

I have this little 'note' window, But I need help to get it to stay on the foreground of your window.
I'm using the Dev-BloodShed C++ compiler. Version 4.9.9.2
this is the code:

1
2
3
4
5
6
7
8
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    LPSTR lpCmdLine, int nCmdShow)
{
    MessageBox(NULL, "You won't stay on the foreground!", "Note", MB_OK);
    return 0;
}


Look this is what I mean, If I mix C++ with Win32 the win32 will appear on the background, that way you can't see it unless the C++ program has ended.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
char yesno;
cout << "Would you like to vieuw a note window? [y/n] ";
cin >> yesno;
if (yesno == 'y') { goto popup;}
if (yesno == 'n') { goto exit;}

popup:
system("cls");

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    LPSTR lpCmdLine, int nCmdShow)
    
{
    MessageBox(NULL, "Stay on foreground!", "Note", MB_OK);
return 0;
}

exit:
system("cls");

Sleep(4000);
return 0;
}

Please help me find a way to let the window appear and stay on foreground.
Thanks in advance.
Last edited on
In order for a modal dialog box to stay on the foreground, it must be owned by the window having the focus, and your message boxes are orphans (first parameter of MessageBox).
Try to create a window for your application first.
Last edited on
ok, Thanks man.
Topic archived. No new replies allowed.