I have two windows, one smaller on top of other bigger. The window created first will always be on top. Neither BringWindowToTop(hWnd)
nor SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
do nothing! I also have been trying HWND_TOPMOST
and HWND_BOTTOM
.
あるウィンドウを他のウィンドウの上に作成する唯一の方法は、正しい作成順序であるようです。しかし、これは私が必要とするものではありません。その場で順序を変更する必要があります。誰がこれを引き起こす可能性があるか知っていますか? CreateWindow()
これらは、どちらも同じ親を持つ単純な古いインスタンスです。インターネットで検索しても何も得られません。専門家の助けが必要です!
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
HWND make_child(HWND Parent, int x, int y, int color) {
HINSTANCE hInstance = 0;
MSG msg = {0};
WNDCLASS wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = CreateSolidBrush(color);//(HBRUSH)(COLOR_WINDOWFRAME);
wc.lpszClassName = (LPCSTR)L"mychildwin";
RegisterClass(&wc);
return CreateWindow("edit",(LPCSTR)"child", WS_BORDER|WS_CHILD|WS_VISIBLE, x,y,100,100,Parent,0,hInstance,NULL);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){
MSG msg = {0};
WNDCLASS wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = CreateSolidBrush(0xff8080);
wc.lpszClassName = (LPCSTR)L"minwindowsapp";
if (!RegisterClass(&wc)) return 1;
HWND W = CreateWindow(wc.lpszClassName,(LPCSTR)L"Minimal Windows Application", WS_OVERLAPPEDWINDOW|WS_VISIBLE, 0,0,640,480,0,0,hInstance,NULL);
HWND A = make_child(W, 10, 10, 0x88ff00);
HWND B = make_child(W, 70, 70, 0x8888ff);
BringWindowToTop(B);
SetWindowPos(B, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
//REAL PROBLEM WAS HERE: A second call to SetWindowPos
SetWindowPos(handle, 0, 0, 0, new_width, new_height,
SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
// adding SWP_NOZORDER fixed it..
while(GetMessage(&msg, NULL, 0, 0) > 0) DispatchMessage(&msg);
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch(message) {
case WM_CLOSE: PostQuitMessage(0); break;
default: return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}