|
how would i use that
the code below is basically what i have for the mouse down, up and move ( sometimes the window dissapears and sometimes it resizes a littlebit then dissapears, im not sure what to do tbh
case WM_LBUTTONDOWN:
if(
{
SetCapture(hWnd);
mResize = TRUE;
}
break;
case WM_LBUTTONUP:
{
ReleaseCapture();
mResize = FALSE;
}
break;
case WM_MOUSEMOVE:
{
if(wParam == MK_LBUTTON) && mResize)
{
RECT rcWnd;
POINT pnt, pntDiff;
GetCursorPos(&pnt);
GetWindowRect(hWnd, &rcWnd);
DeleteObject(hRegion2);
DeleteObject(hRegion1);
pntDiff.x = pnt.x - rcWnd.right;
nWidth = nWidth + (int)pntDiff.x;
pntDiff.y = pnt.y - rcWnd.bottom;
nHeight = nHeight + (int)pntDiff.y;
MoveWindow(hWnd,rcWnd.left, rcWnd.top, nWidth, nHeight, TRUE);
HRGN hRegion1 = CreateRectRgn(0, 0, nWidth, nHeight);
HRGN hRegion2 = CreateRectRgn(0, 0, nWidth, nHeight);
CombineRgn(hRegion1, hRegion1, hRegion2, RGN_OR);
SetWindowRgn(hWnd, hRegion1, true);
UpdateWindow(hWnd);
}
}
break;
|
|
|
|
|
OOpsie!
Did you realise you're changing the size of the regions every time the major block of code in the WM_MOUSEMOVE message is processed?
What are nWidth & nHeight to begin with?
Since you can't click below or to the right of your window, pntDif.x & pntDif.y are always going to be negative. By adding these to the (unknown) values of nWidth & nHeight, you are rewarded with a window that shrinks.
|
|
|
|
|
well my nWidth and nHeight are global variables with the form/region and bitmap use to create my GUI
initially set to 506x376.
i dont know much on how to resize it, which is annoying cause it should be straight forward math
basically i have the width and the height, i have it set to check whether the mouse is in the bottom corner (which works)
and when i click on it and drag it outwards, i want it to resize with it like a normal window would do,
but eitherway its causing major problems lol, i managed to get it working when i clicked and dragged and the resize would happen on WM_LBUTTONUP but that didnt give a sizing/growing effect with it, and additionally i dont know how to stretch the skin out either(i didnt particulaly want to do it with multiple pictures and layers lol so any help would be really good, if i could send the actual code to someone that would be better and they could take a look whats wrong but all i can give is bits at the time atm
|
|
|
|
|
Yeah sure, I'll have a look at the code as long as it's not MFC, as I don't have it.
enhzflep at yahoo dot com dot au
|
|
|
|
|
Changes to your code marked in red...
<code>POINT AnchorPoint;</code>
...
case WM_LBUTTONDOWN:
if(
{
SetCapture(hWnd);
mResize = TRUE;
<code>::GetCursorPos(&AnchorPoint);</code>
}
break;
case WM_LBUTTONUP:
{
<code>if (mResize)
{</code>
ReleaseCapture();
mResize = FALSE;
<code>}</code>
}
break;
case WM_MOUSEMOVE:
{
if(wParam == MK_LBUTTON) && mResize)
{
<code>POINT newPoint;
::GetCursorPos(&newPoint);
if (newPoint.x != AnchorPoint.x || newPoint.y != AnchorPoint.y)
{
RECT rcWnd;
::GetWindowRect(hWnd, &rcWnd);
rcWnd.right += (newPoint.x - AnchorPoint.x);
rcWnd.bottom += (newPoint.y - AnchorPoint.y);
::MoveWindow(hWnd, rcWnd.left, rcWnd.top, rcWnd.right-rcWnd.left, rcWnd.bottom-rcWnd.top, TRUE);
AnchorPoint = newPoint;
}</code>
}
}
break;
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Also...
When you handle any of those messages, you should also return 0 to
indicate you've handled the message instead of passing it on to the
default window proc (if that's what you are doing).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
That code works for forms without regions being used, as i have my own GUI i also have HRGN, which practically covers the window, a bitmap ontop of that AND transparency lol which allows me to shape my form and have nice round edges so given the HRGN how would i get that to work with it
|
|
|
|
|
That's fine - the idea was to show you working code.
In your code sample, you delete two regions on every mousemove message.
Who creates those regions?
You DO know you are not supposed to delete a region you've used in SetWindowRgn(), right?
You also create two identical new regions and OR them together (???) on
every mousemove message. You use local variables for those so if you think you are
destroying them later, you are wrong.
You didn't show any code that does anything with transparency or
"shape my form and have nice round edges" so it's hard to give you an
example that does what you are doing (or trying to do)
It's also impossible to tell what might be wrong...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
well if i showed my working code it would kinda fill up most of this forum and posting a lot of code in here tends to be tedious
as far as the questions go
as far as knowing im not supposed to delete regions ive used in setWindowRgn, no i did not know but i do know, which kinda begs the question how to you resize a region without destroying it or setting a new windowrgn.
again as far as identical local variables i didnt actually think it would matter in this trial run but also again i was wrong lol
so begs the question given my own GUI and region how would i resize it lol
The regions used are below along with the definitions and most of the skining stuff
at the top with the beloved variables I have
#define LWA_COLORKEY 0x00000001
#define LWA_ALPHA 0x00000002
#define g_ColourKey 0xFF00FF // 255,0,255(pink) in hex RGB
#define WS_EX_LAYERED 0x00080000
#define IDB_CLOSEWINDOW 1000
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes;
int nWidth = 506;
int nHeight = 376;
BOOL mDown = FALSE;
POINT AnchorPoint;
the initial regions are create at the top of WndProc and are used in WM_CREATE
LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
HRGN hRegion1 = CreateRectRgn(0, 0, nWidth, nHeight);
HRGN hRegion2 = CreateRectRgn(0, 0, nWidth, nHeight);
switch(Msg)
{
case WM_CREATE:
g_Hwnd = hWnd;
dwStyle &= ~(WS_CAPTION|WS_SIZEBOX);
SetWindowLong(hWnd, GWL_STYLE, dwStyle);
CombineRgn(hRegion1, hRegion1, hRegion2, RGN_OR);
SetWindowRgn(hWnd, hRegion1, true);
SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hWnd, g_ColourKey, 0, LWA_COLORKEY);
m_hCloseButton = CreateWindow("BUTTON",
"x",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_CENTER | BS_FLAT,
nWidth-28, (nHeight-nHeight+10), 20, 20,
hWnd,
(HMENU)IDB_CLOSEWINDOW,
hInst,
NULL);
WM_PAINT calls a function called skin() which is below
BOOL Skin() {
HBITMAP hSkinBmp = LoadBitmap(hInst,MAKEINTRESOURCE(IDB_MAIN));
if (!hSkinBmp) return -1;
HDC dcSkin = CreateCompatibleDC(0);
HBITMAP hOldBmp = (HBITMAP)SelectObject(dcSkin, hSkinBmp);
PAINTSTRUCT ps;
BeginPaint(g_Hwnd,&ps);
BitBlt(ps.hdc, 0, 0, nWidth, nHeight, dcSkin, 0,0, SRCCOPY);
EndPaint(g_Hwnd,&ps);
return 0;
}
and as far as the mouse move well you have all that and i may aswel delete most of it and start again lol
WinMain is just the standard create you own Win32 API window
so any help would be had lol as you can tell im a n00b trying to learn API and not having too much success
|
|
|
|
|
Okay, I've had a look at your code Sarriss, and the one thing that strikes me more than anything is the approach you've taken.
Typically, whenever a resizeable box with rounded corners is drawn, it is drawn using 9 images - top left corner, top middle, top right corner, right middle, middle-middle, right-middle, bot left corner, bot middle, bot right corner.
Doing so means that the corner pieces are always drawn at the correct scale and that the window is sized by stretching all pieces except the corner images.
In your case, it'll be not quite that simple since the bar across the top of the window isn't of uniform height. You may need 5 images to cover the top - the two corners, the low part, the high part and the transition between the two. To make the window wider, you'd just stretch the high part and/or the low part, while drawing the corners and the transition at 1:1 scale.
If you've not seen it, you may like to take look at this.[^]
|
|
|
|
|
Thnx, will take a look at the picture thing i knew kind of that i would need a lot of pictures was more trying to get the window to resize first and making sure i had the resize of the window but i will take a look at the link you gave me, might give me more ideas lol
and also given that i have two levels at the top pic couldnt i just have a bigger corner piece in the corner and then have the otherone plus the pink bit that isnt showing.
also how do you scale/stretch the pictures :S been looking for that for like ages
|
|
|
|
|
Pleasure. Yeah, the link I left is quite a good example of this type of work.
Well worth a close read.
Sarriss wrote: and also given that i have two levels at the top pic couldnt i just have a bigger corner piece in the corner and then have the otherone plus the pink bit that isnt showing.
Sorry, I don't quite follow you here. Could you put it another way?
As for scaling/stretching the picture, have a look at the docs for StretchBlt , that should do what you need.
|
|
|
|
|
enhzflep wrote: In your case, it'll be not quite that simple since the bar across the top of the window isn't of uniform height. You may need 5 images to cover the top - the two corners, the low part, the high part and the transition between the two.
couldnt i just use one pic in the top right corner even if it isnt uniform height
|
|
|
|
|
Oh - yeah sure. That'd be fine. A picture can be worth a 1000 words, so I've sent you a bunch.
I've sent you an email that shows how I'd chop the picture up.
|
|
|
|
|
wow, lol they are like mega small had to zoom in to see them will the stretchblt thing work well with that kinda stuff then???
|
|
|
|
|
Hehe - from over 500kb of image down to around 20kb - nice huh?
Yeah, stretchblt should work fine with them. You only need to stretch the toplow, tophigh, left, right and bottom images - that's why these are all only 1 pixel wide or high. If for whatever reason StretchBlt doesn't work, you can just draw a piece repeatedly until you have a border of the appropriate length.
Not sure which approach the article I linked you to uses, but it'd be one of the two.
|
|
|
|
|
havent finished going through the source code of the article but i loaded the toplow bit into a region and used the stretchblt and it worked beautifully now just have to create a function to put them all together lol, will take me a while im sure heh, thank you very much for your help, couldnt have asked for better
|
|
|
|
|
I would do something like this...
case WM_LBUTTONDOWN:
if(
{
SetCapture(hWnd);
mResize = TRUE;
}
break;
case WM_LBUTTONUP:
{
<code>if (mResize)
{</code>
ReleaseCapture();
mResize = FALSE;
<code>}</code>
}
break;
Beyond that, if its not resizing properly, you'll need
to debug your resizing code
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello, friends~
I have some questions about the MFC programming.
I use the Visual studio 2005 and use Multi-byte-code.
I execute this code..(this is in CView)
///////////////////////////////////////////////////////////////////////////////////
void CRETURN1View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
int nCharIndex;
nCharIndex = m_strOutText.GetLength();
if(nChar == VK_BACK)
{
m_strOutText.Delete(nCharIndex-1, 1);
}
else
{
m_strOutText += nChar;
}
Invalidate();
CView::OnChar(nChar, nRepCnt, nFlags);
}
//////////////////////////////////////////////////////////////////////////////
this error is occur..
// error C2593: 'operator +=' is ambiguous //
I don't know why this error is occur
ps. m_strOutText is CString data type.
plz tell me what is problem...
|
|
|
|
|
In VC6.0 its possible. But in VS2005 rules are a bit more strict and you've to convert the UINT to TCHAR since in CString += doesn't expects a UINT to be added to it.
Well, for making it compilable, just cast to TCHAR as follows,
m_strOutText += (TCHAR)nChar;
m_strOutText += static_cast<tchar>( nChar );</tchar>
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
FR2ESOD wrote: // error C2593: 'operator +=' is ambiguous //
m_strOutText += nChar;
The compiler is not sure what to make of this.
Bram van Kampen
|
|
|
|
|
Hi,
I have a DialogBox with a Single line edittext control
Whenever I enter a number and use GetDlgItemText reterive the data
Nulls get inserted between each character/byte
e.g. if I enter 123456 in the Editext it appears in Memory
as 31 00 32 00 33 00 34 00 35 00 36
is there maybe a ES_ style I should add to the resource file when
Creating the edit control or Maybe sending a message to the edit
control to Format the text ???
thankx
|
|
|
|
|
If you're doing a UNICODE build (i.e. the default with Visual Studio 2003 and above) then there's nothing strange you're getting a UNICODE string.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
Just changed The Visual Studio Build "Character Set" in the
Configuration Properties->General->Project Defaults->character Set to "Not Set" from Unicode
and it worked thankx
|
|
|
|
|