|
Yes: see http://www.microsoft.com/express/support/faq/[^], question 7 .
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]
|
|
|
|
|
Hi all..
Can i fill my Moving dialog, Bubble Dialog with gradient color???
Can someone throw light on that??
Thanks..
|
|
|
|
|
My mind reader's on the blink today.
Try this on for size.
void GradientFillRect(HDC hdc, LPRECT rcGradient, COLORREF start, COLORREF end, BOOL isVertical)
{
BYTE startRed = GetRValue(start);
BYTE startGreen = GetGValue(start);
BYTE startBlue = GetBValue(start);
BYTE endRed = GetRValue(end);
BYTE endGreen = GetGValue(end);
BYTE endBlue = GetBValue(end);
HBRUSH endColor = CreateSolidBrush(end);
FillRect(hdc, rcGradient, endColor);
DeleteObject(endColor);
int dy = 1;
int length = (isVertical ? rcGradient->bottom - rcGradient->top : rcGradient->right - rcGradient->left) - dy;
for (int dn = 0; dn <= length; dn += dy)
{
BYTE currentRed = (BYTE)MulDiv(endRed-startRed, dn, length) + startRed;
BYTE currentGreen = (BYTE)MulDiv(endGreen-startGreen, dn, length) + startGreen;
BYTE currentBlue = (BYTE)MulDiv(endBlue-startBlue, dn, length) + startBlue;
RECT currentRect = {0};
if (isVertical)
{
currentRect.left = rcGradient->left;
currentRect.top = rcGradient->top + dn;
currentRect.right = currentRect.left + rcGradient->right - rcGradient->left;
currentRect.bottom = currentRect.top + dy;
}
else
{
currentRect.left = rcGradient->left + dn;
currentRect.top = rcGradient->top;
currentRect.right = currentRect.left + dy;
currentRect.bottom = currentRect.top + rcGradient->bottom - rcGradient->top;
}
HBRUSH currentColor = CreateSolidBrush(RGB(currentRed, currentGreen, currentBlue));
FillRect(hdc, ¤tRect, currentColor);
DeleteObject(currentColor);
}
}
|
|
|
|
|
Well just to be sure..Please explain some parameters..Because i tried and it didn't work..
void GradientFillRect(HDC hdc, LPRECT rcGradient, COLORREF start, COLORREF end, BOOL isVertical)
1. hdc is handle of device context(dialog box)..
hdc = GetDC(hWnd);
2. rcGradient is rect structure of my dialog box..
GetWindowRect(hWnd, &myWindowRect);
3. COLORREF start is my start color of blue (I need blue gradient)
The Blue hex number.
4. COLORREF end is my end color of blue.
The blue hex number (end).
5. BOOL isVertical???
|
|
|
|
|
Alright now i'm passing something like this..
hdc_myWindow = GetDC(hWnd);
GetWindowRect(hWnd, &thisWindowRect);
static COLORREF StartColor = RGB(0,0,238);
static COLORREF EndColor = RGB(0,0,250);
GradientFillRect(hdc_myWindow,&thisWindowRect,StartColor,EndColor, FALSE);
And i believe
HBRUSH currentColor = CreateSolidBrush(RGB(currentRed, currentGreen, currentBlue));
FillRect(hdc, ¤tRect, currentColor);
Entries are right..I mean currentRed,currentGreen is 0 and currentBlue is what i need...Everything seems to be right.. But my dialog is still Grey
|
|
|
|
|
Cool magool, at least I'm on the right track.
Been eating dinner, sorry to leave you waiting.
It seems that the thing that strikes me is that I forgot the fact that the function
expects the rect to be logical units - not screen units.
Say if I have a 10x10 rect located at 50,50 on the screen, the function wants
RECT gradRect = {0,0, 10,10} not RECT gradRect = {50, 50, 60, 60} like you would expect.
Sorry for the confusion there.
As for the bool isVerticle param, you can run the gradient from leftToRight or topToBottom.
isVerticle = true ---> topToBottom gradient
isVerticle = false ---> leftToRight gradient
Here's a 45 second example. You need to link in gdi32, user32 and kernel32.
No points for guessing which IDE I've used
#include <windows.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Code::Blocks Template Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nCmdShow);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
void GradientFillRect(HDC hdc, LPRECT rcGradient, COLORREF start, COLORREF end, BOOL isVertical)
{
BYTE startRed = GetRValue(start);
BYTE startGreen = GetGValue(start);
BYTE startBlue = GetBValue(start);
BYTE endRed = GetRValue(end);
BYTE endGreen = GetGValue(end);
BYTE endBlue = GetBValue(end);
HBRUSH endColor = CreateSolidBrush(end);
FillRect(hdc, rcGradient, endColor);
DeleteObject(endColor);
int dy = 1;
int length = (isVertical ? rcGradient->bottom - rcGradient->top : rcGradient->right - rcGradient->left) - dy;
for (int dn = 0; dn >= length; dn += dy)
{
BYTE currentRed = (BYTE)MulDiv(endRed-startRed, dn, length) + startRed;
BYTE currentGreen = (BYTE)MulDiv(endGreen-startGreen, dn, length) + startGreen;
BYTE currentBlue = (BYTE)MulDiv(endBlue-startBlue, dn, length) + startBlue;
RECT currentRect = {0};
if (isVertical)
{
currentRect.left = rcGradient->left;
currentRect.top = rcGradient->top + dn;
currentRect.right = currentRect.left + rcGradient->right - rcGradient->left;
currentRect.bottom = currentRect.top + dy;
}
else
{
currentRect.left = rcGradient->left + dn;
currentRect.top = rcGradient->top;
currentRect.right = currentRect.left + dy;
currentRect.bottom = currentRect.top + rcGradient->bottom - rcGradient->top;
}
HBRUSH currentColor = CreateSolidBrush(RGB(currentRed, currentGreen, currentBlue));
FillRect(hdc, ¤tRect, currentColor);
DeleteObject(currentColor);
}
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT myRect;
COLORREF startCol = RGB(71,71,71), endCol = RGB(200,200,200);
switch (message)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_ERASEBKGND:
GetClientRect(hwnd, &myRect);
GradientFillRect(HDC (wParam), &myRect, startCol, endCol, false);
return 1;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|
|
|
|
|
Woooaaahhhhhhh... Really Thanks enhzflep.. You don't know you have solved my creepy problem...
Anyways WM_ERASEBKGND: was actually the main KEY...
Don't know you're Guy or Girl but in any case a rose for you
Thanks a ton...
|
|
|
|
|
Beautiful!!
Glad it helped. Something else you can do is use a bitmap then create a patterned brush from that. If you create your own class like I did in that example, you can just set the background brush of your window class to the patterned brush that holds your bitmap. Windows will automatically tile your background image. So, if I have a window thats 100 x 600 pixels and I just want a left to right gradient, I'll just create a 100 x 1 bitmap and assign it to the background brush. Super light on code, super-light on resources.
This means that you don't even have to handle the WM_ERASEBKGND messages.
Here's an example:
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
HBITMAP hbmp = loadTgaResource(GetModuleHandle(NULL), MAKEINTRESOURCE(1001));
hbr = CreatePatternBrush(hbmp);
DeleteObject(hbmp);
if (!hbmp)
{
MessageBox(NULL, "Couldn't load image file", "ERROR", MB_ICONEXCLAMATION);
return 0;
}
wincl.hbrBackground = hbr;
if (!RegisterClassEx (&wincl))
return 0;
You find a bunch of gems like this trick in any of the books by Charles Petzold. I think this one came from the 10 year old "Programming Windows Fifth Edition" - I have it as a chm, there's I think there's also one available as a pdf
Oh, and thanks for the rose - the name's Simon.
|
|
|
|
|
Yeah i do have that Charles Petzold - "Programming Windows Fifth Edition".. In chm format...Seems have to go through it seriously...
And i'll definitely try this trick..
Thanks again..This is Ashish
|
|
|
|
|
Hey Simon.. A bit of confusion...
According to MSDN
"The Rectangle function draws a rectangle. The rectangle is outlined by using the current pen and filled by using the current brush."
So Gradient Fill actually fill the rectangle not the border or edges.
Initially i thought the dialog box border was black because of some dialog properties but i believe we've to tackle it programmatically...
Am i right???
|
|
|
|
|
Hey Ashish,
not sure to be honest, I've never noticed that artifact.
Guess you could just expand the border by 1 pixel with something like:
rect.top--; rect.left--; rect.right++; rect.bottom++;
Nonetheless, that's a rather interesting problem - I'll have to look into that, thanks for the heads-up.
|
|
|
|
|
Weel yes simon..And i believe expanding the border will not solve the problem...
My hunch is to select pen of particular color, say blue in my case and then redraw the borders.. But don't know how it's gonna work..
If you come to any decision. Please let me know about that..
I'm leaving now as my working hour is over.. Will see ya on Monday..
Happy Weekends..
Ta-ra..
|
|
|
|
|
Hey all..
I believe i've big prob now.. Actually i'm putting some controls on my dialog box. and i need my controls to be Transparent. i.e same color as of background.
For example i'm loading icon with the help of LoadImage and to make Transparent i'm passing "LR_LOADTRANSPARENT" as a last parameter of LoadImage.. But it actually taking black and sometimes Gray as background color... I believe that black border is creating prob...
What do you guys think?
|
|
|
|
|
Hi,
I am planning to create a new application, it is targeted to windows platform, it contains basic user controls and have a duplex communication with COM port (virtual COM port).
I am planning to use Visual C++ for it.
But I am not sure what IDE I should use.
Would Visual Studio C++ Express Edition 2008 be good?
Should I use .NET, Is there any option not to use .NET Frame work.
Thanks a lot in advance.
|
|
|
|
|
Visual C++ express edition should be enough for your purpose. If you create a Win32 application then .Net framework will not be available.
-Saurabh
|
|
|
|
|
Ok, thanks a lot, I have a little concern about the license as well, can I use this application for commercial purpose also... is there a way once I develop in Express edition or the 90 days evaluation copy (I have this) then I can buy the license for commercial purpose.
|
|
|
|
|
As far as I know you can use express editions to develop commercial application.
-Saurabh
|
|
|
|
|
KSuthar wrote: can I use this application for commercial purpose also
Yes: see, for instace, http://www.microsoft.com/express/support/faq/[^].
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]
|
|
|
|
|
In VC6.0 it's tstcon32.exe.
logics
|
|
|
|
|
|
Hi All
How can i convert CString to LPCSTR?Array Is Cstring search[100] and LPCSTR as. I want to convert search[100] to as.Plz help me
|
|
|
|
|
To convert a single object, just you need a casting like:
CString str;
LPCSTR pstr = (LPCSTR)(LPCTSTR)str;
But you can't use this technique for an entire array, you will need to create a parallel array and convert each element one by one.
Best regards,
Jaime.
|
|
|
|
|
Thanks it is working.Sir how can i convert this char *lpStr1 to LPCSTR.
Plz help me
|
|
|
|
|
Doing a double cast like that is not the proper way. Ever heard of CString::GetBuffer()?
|
|
|
|
|
PJ Arends wrote: Doing a double cast like that is not the proper way. Ever heard of CString::GetBuffer()?
That is relative, for read-only purposes, my proposal will be simpler.
Calling GetBuffer() implies calling ReleaseBuffer() later, according to MSDN configuration.
Best regards,
Jaime.
|
|
|
|
|