{"id":309,"date":"2009-04-12T23:38:38","date_gmt":"2009-04-12T18:08:38","guid":{"rendered":"http:\/\/techtwaddle.net\/?p=309"},"modified":"2011-04-12T23:38:54","modified_gmt":"2011-04-12T18:08:54","slug":"applications-that-thing-called-gradience","status":"publish","type":"post","link":"https:\/\/techtwaddle.co.in\/blog\/2009\/04\/12\/applications-that-thing-called-gradience\/","title":{"rendered":"Applications: That thing called Gradience"},"content":{"rendered":"<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">I added a little gradient fill to the main screen. And it is quite easy really. By the way, here&#8217;s what my main screen looks like now, cool eh (:<\/span><\/div>\n<p><img decoding=\"async\" loading=\"lazy\" width=\"350\" height=\"546\" alt=\"\" src=\"\/images\/geekswithblogs_net\/TechTwaddle\/HelloWorld\/HelloWorld8.JPG\" \/><\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">Lets look at <span style=\"font-family: Tahoma;\">GradientFill<\/span> first. The function is prototyped as:<\/span><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Tahoma;\"> <span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">BOOL GradientFill(HDC hdc, PTRIVERTEX pVertex, ULONG numVertex, PVOID pMesh, ULONG numMesh, ULONG mode);<\/span><\/span><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\"> The first parameter is the handle to the device context. The second parameter, <span style=\"font-family: Tahoma;\">pVertex<\/span>, is a pointer to an array of <span style=\"font-family: Tahoma;\">TRIVERTEX<\/span> structures. The third parameter contains the number of elements in the array pointed to by <span style=\"font-family: Tahoma;\">pVertex<\/span>. <\/span><\/div>\n<p>\n<span style=\"font-family: Tahoma; color: rgb(0, 0, 128);\"> <span style=\"font-family: Verdana;\">TRIVERTEX structure:<\/span><\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\"> struct _TRIVERTEX<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\"> {<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; LONG x;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; LONG y;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; COLOR16 Red;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; COLOR16 Green;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\"> &nbsp;&nbsp;&nbsp; COLOR16 Blue;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; COLOR16 Alpha;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">} TRIVERTEX;<\/span><\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">The structure defines a point <span style=\"font-family: Tahoma;\">x,y<\/span> in the device context and its color. <span style=\"font-family: Tahoma;\">Alpha<\/span> define the transparency of the point <span style=\"font-family: Tahoma;\">x,y<\/span>. The points in the array should define the upper left and the lower right corners of the rectangle being filled. The fourth parameter <span style=\"font-family: Tahoma;\">pMesh<\/span> points to a <span style=\"font-family: Tahoma;\">GRADIENT_RECT<\/span> structure.<\/span><\/div>\n<p>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">struct _GRADIENT_RECT<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">{<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ULONG topLeft;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ULONG bottomRight;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">} GRADIENT_RECT;<\/span><\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">The <span style=\"font-family: Tahoma;\">GRADIENT_RECT<\/span> structure specifies which entry in the array containing <span style=\"font-family: Tahoma;\">TRIVERTEX<\/span> array is the upper left point and which is the bottom right point. The last parameter, <span style=\"font-family: Tahoma;\">mode<\/span>, specifies whether the gradient should be filled horizontally, <span style=\"font-family: Tahoma;\">GRADIENT_FILL_RECT_H<\/span>, or vertically <span style=\"font-family: Tahoma;\">GRADIENT_FILL_RECT_V<\/span>.<\/span><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">Now to the static text control. I tried to make the control transparent but found out that it is not very straight forward. Tried to use <span style=\"font-family: Tahoma;\">SetBkMode(hdc, TRANSPARENT)<\/span> and reurning <span style=\"font-family: Tahoma;\">NULL_BRUSH<\/span> in response to <span style=\"font-family: Tahoma;\">WM_CTLCOLORSTATIC<\/span>, didn&#8217;t work for me. So I removed the static control and used <span style=\"font-family: Tahoma;\">ExtTextOut<\/span> to draw the text directly on the screen.<\/span><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\"><span style=\"font-family: Comic Sans MS;\">Here is the final piece of code. All the code goes in under <span style=\"font-family: Tahoma;\">WM_PAINT<\/span> function. And <span style=\"font-family: Tahoma;\">g_hImageStatic<\/span> is a global which contains window handle to the static control containing the image. I store it while creating the static control in AlignComponents(), check my previous <a href=\"http:\/\/geekswithblogs.net\/TechTwaddle\/archive\/2009\/04\/27\/applications-adding-image-to-your-application.aspx\">post<\/a>.<\/span><\/div>\n<p>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">TRIVERTEX vert[2];<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">GRADIENT_RECT gradRect;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">RECT rect;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">TCHAR szStrLine1[] = TEXT(&quot;TechTwaddle&quot;);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">TCHAR szStrLine2[] = TEXT(&quot;Copyright (c) 2009&quot;);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">hdc = BeginPaint(hWnd, &amp;ps);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">GetClientRect(hWnd, &amp;rect);<\/span><br style=\"font-family: Tahoma;\" \/><br \/>\n<br style=\"font-family: Tahoma;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[0].x = rect.left;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[0].y = rect.top;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[0].Red = 0x0000;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[0].Green = 0x2000;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[0].Blue = 0xA000;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[0].Alpha = 0x0000;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[1].x = rect.right;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[1].y = rect.bottom;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[1].Red = 0x0000;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[1].Green = 0x8000;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[1].Blue = 0xFF00;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">vert[1].Alpha = 0x0000;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">gradRect.UpperLeft = 0;<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">gradRect.LowerRight = 1;<\/span><br style=\"font-family: Tahoma;\" \/><br \/>\n<br style=\"font-family: Tahoma;\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">GradientFill(hdc, vert, 2, &amp;gradRect, 1, GRADIENT_FILL_RECT_H);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">if(g_hImageStatic)<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">{<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; GetWindowRect(g_hImageStatic, &amp;rect);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; SetTextColor(hdc, RGB(120, 160, 130));<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; SetBkMode(hdc, TRANSPARENT);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ExtTextOut(hdc, rect.left &#8211; 23, rect.bottom &#8211; 24, 0, NULL, <\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; szStrLine1, _tcslen(szStrLine1), NULL);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; <\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; ExtTextOut(hdc, rect.left &#8211; 37, rect.bottom &#8211; 11, 0, NULL, <\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; szStrLine2, _tcslen(szStrLine2), NULL);<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">}<\/span><br style=\"font-family: Verdana; color: rgb(0, 0, 128);\" \/><br \/>\n<br style=\"font-family: Tahoma;\" \/><br \/>\n<span style=\"font-family: Tahoma;\"><span style=\"font-family: Verdana; color: rgb(0, 0, 128);\">EndPaint(hWnd, &amp;ps);<\/span><br style=\"font-family: Tahoma;\" \/><br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I added a little gradient fill to the main screen. And it is quite easy really. By the way, here&#8217;s what my main screen looks like now, cool eh (: Lets look at GradientFill first. The function is prototyped as: &nbsp; BOOL GradientFill(HDC hdc, PTRIVERTEX pVertex, ULONG numVertex, PVOID pMesh, ULONG numMesh, ULONG mode); &nbsp; &hellip; <a href=\"https:\/\/techtwaddle.co.in\/blog\/2009\/04\/12\/applications-that-thing-called-gradience\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Applications: That thing called Gradience<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p1ktFF-4Z","_links":{"self":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/309"}],"collection":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/comments?post=309"}],"version-history":[{"count":2,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/309\/revisions"}],"predecessor-version":[{"id":691,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/posts\/309\/revisions\/691"}],"wp:attachment":[{"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/media?parent=309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/categories?post=309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techtwaddle.co.in\/blog\/wp-json\/wp\/v2\/tags?post=309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}