views:

304

answers:

4

I'm using CreateWindowEx() function to create an "EDIT" window, i.e. where a user can type.

g_hwndMain = CreateWindowEx(0, WC_TEXT, NULL, WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL, 0, 0, 400, 200, phwnd, NULL, g_hInstance, NULL);

But I would also like the window to be static. Is there a way to do it during the creation of the window? Or any other function that may be used after the creation of the window? I tried using SetWindowPos function after creating the window using SWP_NOSENDCHANGING and SWP_NOREPOSITION, but that didn't o the trick. ANy ideas?

A: 

By "static", do you mean read-only? Then send EM_SETREADONLY after loading the text.

RichieHindle
By static he means that the window cannot be moved around.
arul
But it's an edit control... unless you give it WS_CAPTION etc., you can't move it around anyway...?
RichieHindle
You're right arul. BTW, I'm not a he :)RichieHindle, the window is still movable with or without WS_CAPTION ( Unless it's declared "STATIC"). I was looking at whether I could use WC_TEXT and WC_STATIC at the same time, but I guess that's not possible.
GotAmye
A: 

No, I mean Immovable Window. Basically, the window I create should be able to accept text and be immovable at the same time.

GotAmye
A: 

You need to handle the WM_WINDOWPOSCHANGING message for that window and then set the SWP_NOMOVE flag of the flags member of the WINDOWPOS structure before you forward it along.

This blog post has an example (though he's preventing size changes, the technique is the same).

zdan
A: 

Thanks for your help. Ok So far I've done this to handle WM_WINDOWPOSCHANGING message

BOOL OnWindowPosChanging(HWND hwnd, WINDOWPOS *pwp)
{

    return 0;
}

LRESULT CALLBACK
WndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uiMsg) {

     HANDLE_MSG(hwnd, WM_WINDOWPOSCHANGING, OnWindowPosChanging);
    }

    return DefWindowProc(hwnd, uiMsg, wParam, lParam);
}

and when I create my window, I do this:

g_hwndMain =  CreateWindowEx(0,
          TEXT("EDIT"),
          NULL, 
          WS_BORDER,
          0, 0, 400, 200,
          phwnd, NULL, 
          g_hInstance, NULL);

        if (!g_hwndMain) {
         RemoveImages(spHTMLDoc);//Just so I know that the window has been created properly
        }
        else{          

         SetWindowPos(g_hwndMain, HWND_TOP, 500, 500, 300, 300,  SWP_NOSENDCHANGING | SWP_SHOWWINDOW );
        }

The SWP_NOMOVE flag does not let the code change the position of the window, but the user is still able to change the window's position by moving it using a mouse. But this is exactly what I want to prevent. The window should be static. Any thing missing in my code, or any more suggestions?

GotAmye
ok, I figured this out. In CreateWIndow, add WS_CHILD flag as the 4th param. THis will do the trick. Thanks for your help!!!
GotAmye
Better to use WS_POPUP instead of WS_CHILD
GotAmye