|
Hi all,
I am trying to draw a gradient rectangle using the below code. But the problem is am not getting the correct color in the bottom. As per the code the expected color is RGB(0,0,255). But now I am getting RGB(3,0,252). Is there any way to show the correct value?
Color clr1( 255,255,0,0 );<br />
Color clr2( 255,0,0,255 );<br />
Rect rect( 0,0,100,100 );<br />
LinearGradientBrush pushedFace( rect, clr1, clr2, LinearGradientModeVertical );<br />
CClientDC dc(this);<br />
Graphics gr(dc.m_hDC);<br />
gr.FillRectangle( &pushedFace,rect );
Thanks in advance
|
|
|
|
|
Naveen.R wrote: Is there any way to show the correct value?
Add 1 to the rect height.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
you mean like
LinearGradientBrush pushedFace( Rect( 0,0, 30, 101 ), clr1, clr2, LinearGradientModeVertical ); .
In this case the color became more lighter. RGB(5,0,250)
|
|
|
|
|
You're right! LOL sorry.
The problem is with the math (apparently which I'm too tired to comprehend ).
Incrementing evenly through 100 rows from 0 to 255, the last row ends at 252.45 or 252.
There's no way around it that I know of except adjusting the width/height to a value that makes
it come out exact.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Incrementing evenly through 100 rows from 0 to 255
Well I tried making the following changes. Set the height as 255.clr1 = RGB( 0,0,0), clr2 = RGB(0,0,255 )
In this case the color should come correct isnt it? but now the color is 0,0,254 at the bottom( I know the color change is not noticeable. But I have to meet the specifications... ).
|
|
|
|
|
|
Mark Salsbery wrote: You may have to come up with your own formula.
Thanks for your support.
|
|
|
|
|
I'll look deeper into this in the morning - for now, I have to sleep
Good luck!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I'll look deeper into this in the morning - for now, I have to sleep
Thanks for that... Good night.
|
|
|
|
|
OK, if you want to roll your own gradient rect, this formula should work
(((r2 - r1) / (rectheight - 1)) * currentrow) + r1 = rdest
(((g2 - g1) / (rectheight - 1)) * currentrow) + g1 = gdest
(((b2 - b1) / (rectheight - 1)) * currentrow) + b1 = bdest
where
r,g,b == red,green,blue components
Desired Start row color == RGB(r1,g1,b1)
Desired End row color == RGB(r2,g2,b2)
currentrow == current row of rect being drawn (0-based)
RGB(rdest,gdest,bdest) is the resulting color for the currentrow
Note this requires floating point so it will be slower than the standard integer formula.
The example is for vertical gradient - it would work for columns as well (horizontal gradient).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
How to get the Dialog handle of Dialog-based application?
Best Regards,
Suman
|
|
|
|
|
use GetSafeHwnd()
Manish Rastogi
|
|
|
|
|
Hi Manish,
Thanks for the help!!
Best Regards,
Suman
|
|
|
|
|
|
Hi, I want to find the format of a wav file. I use the MediaDetector interface like this:
CoCreateInstance(CLSID_MediaDet,NULL,CLSCTX_INPROC_SERVER,IID_IMediaDet,(void**) &pIMediaDet);
I have included dshow.h and linked to strmiids.lib but I get these link errors:
AudioController.obj : error LNK2001: unresolved external symbol _CLSID_MediaDet
AudioController.obj : error LNK2001: unresolved external symbol _IID_IMediaDet
Any help would be appreciated.
Thanks
Ratna
|
|
|
|
|
#include <Qedit.h>
"This header file is not compatible with Microsoft® Direct3D® headers later than version 7."
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
I am a beginner in MFC. Here is my problem :
I have a MDI application, when I display one image on a child frame, the image disappear if I move(resize or minimize) the frame. I don't really know where the problem comes from.
In my Child frame, I use :
<br />
ON_COMMAND_RANGE(ID_IMAGE1, ID_IMAGE2, OnView)<br />
OnView is like :
<br />
void CChildFrame::OnView(UINT nID)<br />
{<br />
CBitmap bmp1, bmp2;<br />
CClientDC dc1(this), dc2(this);<br />
CDC bmDC1, bmDC2;<br />
BITMAP bi1, bi2;<br />
bmp1.LoadBitmap(IDB_BITMAP1);<br />
bmp2.LoadBitmap(IDB_BITMAP2);<br />
<br />
bmDC1.CreateCompatibleDC(&dc1);<br />
bmDC2.CreateCompatibleDC(&dc2);<br />
<br />
CBitmap *pOldbmp1 = bmDC1.SelectObject(&bmp1);<br />
CBitmap *pOldbmp2 = bmDC2.SelectObject(&bmp2);<br />
<br />
bmp1.GetBitmap(&bi1);<br />
bmp2.GetBitmap(&bi2);<br />
<br />
<br />
switch( nID )<br />
{<br />
case ID_IMAGE1:<br />
<br />
dc1.BitBlt(0,0,bi1.bmWidth,bi1.bmHeight,&bmDC1,0,0,SRCCOPY);<br />
bmDC1.SelectObject(pOldbmp1); <br />
<br />
break;<br />
<br />
case ID_IMAGE2:<br />
<br />
dc2.BitBlt(0,0,bi2.bmWidth,bi2.bmHeight,&bmDC2,0,0,SRCCOPY);<br />
bmDC2.SelectObject(pOldbmp2);<br />
<br />
break;<br />
}<br />
}<br />
Any help would be very appreciated
|
|
|
|
|
Typically you should be drawing in a view, in a CView::OnDraw() override.
You're drawing in a frame window, which, if there's a view embedded in it, the view window is
covering whatever you draw.
If there's not an embedded view in the frame, then you need to draw your bitmap in response to
WM_PAINT.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
ok thank you, I will try this way.
|
|
|
|
|
Hi all. Im going to try my best to explain what i need here.
I need a function to return true if a certain parameter is entered in, based on the true i need other function to call on this function to make sure its ok to proceed, if false is returned then dont do anything, if true is returned then go ahead and execute. I made a simple prog using a boolean to return true.
<br />
#include <iostream><br />
#include <string><br />
using namespace std;<br />
bool password(const char* pass);<br />
<br />
<br />
string input;<br />
int main(){<br />
cout << "Please enter password: ";<br />
cin >> input;<br />
password(input.c_str());<br />
system("pause");<br />
return 0;<br />
}<br />
<br />
bool password(const char* pass){<br />
string password="stupidpass";<br />
if(password == input){<br />
cout << "Password correct! " << endl;<br />
return true;<br />
}<br />
else<br />
{<br />
cout << "Password incorrect! " << endl;<br />
return false;<br />
}<br />
}<br />
It works perfectly. Now what it is im trying to do is compare the strings from password and the sock buffer. So i tried the following ...
<br />
bool checklogin(const char* login);<br />
<br />
if(servbuff.find(login) != string::npos){<br />
if(servbuff.find(auth) != string::npos){<br />
checklogin(servbuff.c_str());<br />
}<br />
else{<br />
error();<br />
}<br />
}<br />
<br />
bool checklogin(const char* login){ <br />
if(password == servbuff){<br />
cout << "Login correct " << endl;<br />
return true;<br />
}<br />
else{<br />
cout << "Login incorrect " << endl;<br />
return false;<br />
}<br />
}<br />
And it kept saying incorrect, i know that it is because the string isnt matching correctly. What im trying to figure out how would i go about calling the function with the parameter that will send what it needs to match the two strings. If im unclear about something let me know and i'll try to be more specific. Thanx in advance!
|
|
|
|
|
If you step through with the debugger this should be easy to spot. At which line is the check
failing? What are the values of the strings at that point?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi All;
I am trying to create a function that takes two
struct tm's and get the bigger of them by difftime.
i am trying the following:
time_t tMyTime, tZeroTime;
struct tm ZeroYear ;
struct tm myTime;
struct tm* pZeroYear = &ZeroYear;
struct tm* pMyTime = &myTime;
ZeroYear.tm_year = 1970;
ZeroYear.tm_mon = 1;
ZeroYear.tm_mday = 1;
ZeroYear.tm_hour = 0;
ZeroYear.tm_min = 0;
ZeroYear.tm_sec = 0;
myTime.tm_year = 2007;
myTime.tm_mon = 7;
myTime.tm_mday = 23;
myTime.tm_hour = 21;
myTime.tm_min = 51;
myTime.tm_sec = 59;
tMyTime = mktime(pMyTime); // ERROR return -1
tZeroTime = mktime(pZeroYear); // ERROR return -1
double testTime = difftime(tMyTime,tZeroTime);
cout<<" testTime is : "<< testTime; // 0 is printed
I know i can check each value one by one but is there a better option?
as you must have noticed i am new to this stuff and it does not work...
thanks alot
Beri
|
|
|
|
|
beriho wrote: tMyTime = mktime(pMyTime); // ERROR return -1
tZeroTime = mktime(pZeroYear); // ERROR return -1
mktime() handles dates in any time zone from midnight, January 1, 1970, to January 18, 19:14:07, 2038. You are trying to handle dates in the years 3870 and 3907, respectively.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
thanks for your reply;
so i need to get from user like this if i want to check year 2007?
CurrentTime.tm_year = 107;
myTime.tm_year = 107;
thanks again
Beri
-- modified at 17:24 Monday 23rd July, 2007
|
|
|
|
|