Jump to content
  • Advertisement
Sign in to follow this  

win32 API question

This topic is 4318 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, I want to ask how to adjust modeless dialog's size to a limited range e.g. width cannot smaller than 320, height cannot be smaller than 200 I try to adjust the size during WM_SIZE, WM_SIZING but there have some error! and what is the different of MoveWindow(), SetWindowPos()? Thanks for your help!! ************************************************** thanks for you help! actually, i want to create a dialog with client area which can adjust the size but the client area cannot smaller than 320/200. I use that client area the drawing, but i found that the client area is a little bit smaller than 320/200, i though i havne't count the border of window! I tried to use AdjustWindowRectEx()to find a RECT with client area not smaller than 320/200, but it doesn't work! [Edited by - kknd2006 on July 26, 2006 9:56:31 AM]

Share this post


Link to post
Share on other sites
Advertisement
In WM_SIZING, how did you try to adjust the size? The appropriate way is to treat lParam as a pointer to a RECT struct, and alter the values there, rather than calling a function such as SetWindowPos().

//Note:  This is untested code, mostly from memory

case WM_SIZING:
{
RECT* pRect = reinterpret_cast<RECT*>(lParam);
if (pRect != NULL)
{
if (pRect->right - pRect->left > 320)
{
if (wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_LEFT || wParam == WMSZ_TOPLEFT)
{
//The left edge moved too far
pRect->left = pRect->right - 320;
}
else if (wParam == WMSZ_BOTTOMRIGHT || wParam == WMSZ_RIGHT || wParam == WMSZ_TOPRIGHT)
{
//The right edge moved too far
pRect->right = pRect->left + 320;
}
else
{
//Somehow it's just too wide
pRect->left = (pRect->right - pRect->left - 320) / 2;
pRect->right = pRect->left + 320;
}
}

if (pRect->bottom - pRect->top > 200)
{
if (wParam == WMSZ_TOPLEFT || wParam == WMSZ_TOP || wParam == WMSZ_TOPRIGHT)
{
//The top edge moved too far
pRect->top = pRect->bottom - 200;
}
else if (wParam == WMSZ_BOTTOMLEFT || wParam == WMSZ_BOTTOM || wParam == WMSZ_BOTTOMRIGHT)
{
//The bottom edge moved too far
pRect->bottom = pRect->top + 200;
}
else
{
//Somehow it's just too tall
pRect->top = (pRect->bottom - pRect->top - 200) / 2;
pRect->bottom = pRect->top + 200;
}
}
}
return TRUE;
}




Regarding MoveWindow() and SetWindowPos(), the latter simply provides more control. You can suppress certain things, such as causing the window to obtain focus, and you can set the window's Z position (which windows it is in front of or behind).

[edit]Or do what yadango suggested. I learned something today.[/edit]

[Edited by - Agony on July 26, 2006 9:22:37 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
the reason why it doesn't work is because AdjustWindowRectEx only works for WS_OVERLAPPED type windows. to get it to work for a dialog... hmmm damn i'm not on my dev machine right now and i can't remember the function names... i think it's GetSystemMetrics or something like that and they have flags to get the dimensions of a caption, menu, dialog frame border etc. you just have to tally them up.
Y-Go

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
the reason why it doesn't work is because AdjustWindowRectEx only works for WS_OVERLAPPED type windows. to get it to work for a dialog... hmmm damn i'm not on my dev machine right now and i can't remember the function names... i think it's GetSystemMetrics or something like that and they have flags to get the dimensions of a caption, menu, dialog frame border etc. you just have to tally them up.
Y-Go

AdjustWindowRectEx() should indeed work for windows other than WS_OVERLAPPED. There's a reason the function accepts a style, an extended style, and a BOOL for whether a menu exists or not.

kknd2006, did you use the window style and extended window style for your dialog box? You should be able to use GetWindowLong(hWnd, GWL_style) and GetWindowLong(hWnd, GWL_EXstyle) to get those two values.

As a sidenote, it's probably best in the future if you simply add a new post to a thread, rather than edit your original post, because adding a new post will force it to move up in the list of threads. Otherwise, people might not realize that new questions or solutions have been added, unless they're checking the thread for the first time and thus read all the posts.

Share this post


Link to post
Share on other sites
oops, i remember there being something on MSDN about overlapped windows and AWREx... ha ha ha that's what i get for not being on my dev machine to double-check MSDN b4 i post. should work for everything but WS_OVERLAPPED lol. do as agony suggests and grab your window style from GWL or your resource file and pass it to AWREx.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!