Ramilol
Ramilol

Reputation: 3462

c++ edit box goes behind main window

i created a edit box but it doesn't show on the window. it shows if the window is not full screen. if it is full screen the edit box goes behind it. here is the function for the edit box

HWND editbox=CreateWindowA("EDIT", NULL, 
                      WS_VISIBLE | WS_EX_TOPMOST | WS_BORDER | ES_LEFT, 
                      87, 81, 150, 17, 
                      hWnd, 
                      (HMENU)5, hInstance, NULL);

i don't know why it does that i set it to WS_EX_TOPMOST and it still goes behind it. i used directx 9 to make my program in full screen

Upvotes: 0

Views: 321

Answers (2)

Amit
Amit

Reputation: 13364

HWND editbox=CreateWindowA("EDIT", NULL, WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT, 87, 81, 150, 17, hWnd, (HMENU)5, hInstance, NULL);

WS_CHILD is required if you want to display the new control atop a window...

Upvotes: 2

rhino
rhino

Reputation: 13881

All WS_EX_** styles should be passed as the first argument of CreateWindowEx, not the third of CreateWindow. This probably causes the problem. Use CreateWindowExA instead. All the arguments in CreateWindowEx remain the same, there's just one additional parameter at the beginning.

HWND editbox=CreateWindowExA(WS_EX_TOPMOST, "EDIT", NULL, 
                  WS_VISIBLE | WS_BORDER | ES_LEFT, 
                  87, 81, 150, 17, 
                  hWnd, 
                  (HMENU)5, hInstance, NULL);



EDIT: I know what was wrong. You forgot the WS_CHILD style in the third argument. It is needed so Windows knows that this is a child window.

HWND editbox=CreateWindowA("EDIT", NULL,
              WS_VISIBLE | WS_CHILD | WS_BORDER | ES_LEFT,
              87, 81, 150, 17,
              hWnd,
              (HMENU)5, hInstance, NULL);

Upvotes: 2

Related Questions