How to make the top of the window child friendly (C ++ win32 SDK)

I am trying to write a very simple graphic designer like most of the popular IDEs, for example: enter image description here

How do I implement these 8 dots around the widget? My idea is to create a transparent static control (called a ghost), with 8 dots around it, overriding it to the same widget size that spans the widgets. The question is how to make a ghost in front of another control?

I am writing a small test, a button and a static control, I want the static to always be at the top of the z-order

#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int main() {
    static char szAppName[] = "winhello";
    HWND        hwnd;
    MSG         msg;
    WNDCLASSEX  wndclass;

    wndclass.cbSize         = sizeof(wndclass);
    wndclass.style          = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc    = WndProc;
    wndclass.cbClsExtra     = 0;
    wndclass.cbWndExtra     = 0;
    wndclass.hInstance      = GetModuleHandle(0);
    wndclass.hIcon          = LoadIcon(NULL, IDI_APPLICATION);
    wndclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);
    wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wndclass.hbrBackground  = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wndclass.lpszClassName  = szAppName;
    wndclass.lpszMenuName   = NULL;

    RegisterClassEx(&wndclass);

    hwnd = CreateWindow(szAppName, "Hello, world!",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT,
            CW_USEDEFAULT, CW_USEDEFAULT,
            NULL, NULL, GetModuleHandle(0), NULL);

    ShowWindow(hwnd, SW_SHOW);
    UpdateWindow(hwnd);

    while ( GetMessage(&msg, NULL, 0, 0) ) {
    TranslateMessage(&msg);    /*  for certain keyboard messages  */
    DispatchMessage(&msg);     /*  send message to WndProc        */
    } 

    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
    HWND hStatic;
    HWND hButton;

    switch ( iMsg ) {
    case WM_CREATE:
        {

            hButton = CreateWindow("button", "btn", WS_CHILD|WS_VISIBLE, 
                                 10, 10, 100, 100, hwnd, 0, 0, 0);
            hStatic = CreateWindow("static", "edt", WS_CHILD|WS_VISIBLE,
                                   40, 40, 50, 200, hwnd, 0, 0, 0);
            // WS_EX_TOPMOST doesn't work
            // HWND_TOP doesn't work
            // SetWindowPos(hStatic, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
        }
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }

    return DefWindowProc(hwnd, iMsg, wParam, lParam);

      

run the program, press the button, the button will move to the front

enter image description here

I tried SetWindowPos (hStatic, HWND_TOP) and WS_EX_TOPMOST , didn't work.

+3


source to share





All Articles