Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing Window border on the fly

Posted on 1998-12-29
10
Medium Priority
?
515 Views
Last Modified: 2013-12-03
I have a parent window that displays a child window
when a menu option is chosen.
When the child window is displayed I would like to change
the parent window border so that the window could be
resized.  When the child window is removed I would then
return the window border to its original style.

I tried a SetWindowLong call (using a GWL_STYLE (sp?) parameter and a WM_THICKFRAME parameter) before displaying the child window, and another call before removing it.

The border didn't change when the child window was displayed.  It did change to the thick frame when I
removed the child window but the window could not
be resized.
0
Comment
Question by:cpirrita
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1417819
I'm not sure if you can set the border style on the fly. But how about this:
You could set the border style to always resizable. Then you could look at WM_WINDOWPOSCHANGING message, which with you can prevent windows from resizing your window if you don't like it.

Regards, Madshi.
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1417820
The other styles of the window is important as well. To change WS_THICKFRAME, you need to make sure the parent window does not have WS_OVERLAPPED or WS_OVERLAPPEDWINDOW styles (you should not create them with these styles) because WS_OVERLAPPED and WS_OVERLAPPED imply WS_THICKFRAME. Instead, use WS_POPUP | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME. You can remove WS_THICKFRAME initially if that's what you want.
0
 

Author Comment

by:cpirrita
ID: 1417821
sorry - I should have more fully stated I was adding the thickframe parameter in
addition to the existing parameters.  the actual call is:

       SetWindowLong(hDlg, GWL_STYLE,
                                       WS_THICKFRAME | WS_POPUP |  WS_VISIBLE |
                                       WS_CAPTION | WS_VSCROLL | WS_SYSMENU);

I remove the THICKFRAME parameter when I remove the window.
The window border only changes to a thick frame when I execute the call that doesn't have the THICKFRAME parameter (after 1st executing the call with the parameter).

i'll also look into the WINDOWPOSCHANGING msg but the above method works I
think that would look more 'cleaner' (plus I'm curious if it can be done)

0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 1

Expert Comment

by:hddp666
ID: 1417822
In VB the BorderStyle property is only available at design-time. Attempting to change it at run-time causes a compilation error.

Then again, VB is pretty weak.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1417823
Do something like this. It works fine.

 hWin=CreateWindowEx( ...
         WS_POPUP | WS_SYSMENU | WS_CAPTION | WS_VSCROLL | WS_VISIBLE...)


// Set thickframe
  LONG l=GetWindowLong(hWin,GWL_STYLE);
  l|=WS_THICKFRAME;
  SetWindowLong(hWin,GWL_STYLE,l);

// Remove thickframe
  LONG l=GetWindowLong(hWin,GWL_STYLE);
  l&=~WS_THICKFRAME;
  SetWindowLong(hWin,GWL_STYLE,l);

0
 

Author Comment

by:cpirrita
ID: 1417824
my parent window is a dialog box created via a DialogBoxParam call, so I used the
hDlg paramater passed in rather than the return handle from a CreateWindowEx call.
when I added the following:

       lStyle = GetWindowLong(hDlg, GWL_STYLE);
       lStyle = lStyle || WS_THICKFRAME;
       SetWindowLong(hDlg, GWL_STYLE,  lStyle);

to create a thick frame on the parent the program froze and I could only kill it
via the task manager.  If I commented out the logical or operation then my program
remained operational (w/o altering the border style).  Is this something that cannot
be done to a Dialog Box?
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1417825
You should warning us about DialogBox (you said: parent window ...!)

Next,  you wrote:
       lStyle = lStyle || WS_THICKFRAME;
After this line lStyle will be equal 1.
Should be
     lStyle = lStyle | WS_THICKFRAME; // One vertical line


0
 
LVL 15

Expert Comment

by:NickRepin
ID: 1417826
In any case, I'm afraid, it's impossible for dialog box
0
 
LVL 2

Accepted Solution

by:
zyqwert earned 800 total points
ID: 1417827
If you can change your dialog box so that it is initially resizable then we have a solution.
The plan is make the dialog box resource resizeable.
Then in WM_INITDIALOG, or thereabouts, make it not resizable using the code below.
Then you can toggle the state with your child window creation.

If the dialog box is created with a resizeable border then you can turn it on and off at will.  
Strangely, if it is created without a resizable border, you can't make it resizeable -- the DefWindowProc of WM_NCMOUSEMOVE, HTBOTTOM should cause the WM_SYSCOMMAND of SC_SIZE but it doesn't.

Here is the code to make the dialog resizeable:

LONG lStyle= GetWindowLong(h, GWL_STYLE);
lStyle&= ~DS_MODALFRAME;
lStyle|= WS_THICKFRAME;
SetWindowLong(h, GWL_STYLE, lStyle);
lStyle= GetWindowLong(h, GWL_EXSTYLE);
lStyle&= ~WS_EX_DLGMODALFRAME;
SetWindowLong(h, GWL_EXSTYLE, lStyle);
// Force an NCCALCSIZE:
SetWindowPos(h, NULL, 0, 0 ,0, 0, SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);

To make it not resizeable, swap the setting and clearing of bits (x&=~m <--> x|=m)

Let me know if there is any problem.

0
 

Author Comment

by:cpirrita
ID: 1417828
thanks! That worked great.  I haven't played around with it much yet - I want to
reset the original height/width of the Dialog Box when the child window is removed.
I assume I can set the x/y/height/width values in the SetWindowPos to do this;
otherwise I'll use a MoveWindow call.  thanks again.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question