{"id":635,"date":"2010-12-17T20:20:21","date_gmt":"2010-12-18T01:20:21","guid":{"rendered":"http:\/\/anvil-of-time.com\/wordpress\/?p=635"},"modified":"2021-03-10T18:40:22","modified_gmt":"2021-03-10T23:40:22","slug":"powerbuilder-get-color-value-of-pixel-under-pointer","status":"publish","type":"post","link":"https:\/\/anvil-of-time.com\/powerbuilder\/powerbuilder-get-color-value-of-pixel-under-pointer\/","title":{"rendered":"PowerBuilder &#8211; Get Color Value of Pixel under Pointer"},"content":{"rendered":"<p>Here is a sample application which will give you the color value of the pixel the user clicked on on a picture control (this can be used for any object inherited from a dragobject). To see the list of draggable controls, open the Browser. All the objects in the hierarchy below dragobject are draggable. This functionality can be used to &#8216;prettyfy&#8217; a report selection window by providing an irregular bitmap (sales region map, delivery routes, etc.) within which the user clicks. Depending upon the color they choose, a separate report is produced.<\/p>\n<p>Anyway, the functionality is encapsulated in an nvo and involves three API external functions.<\/p>\n<pre name=\"code\" class=\"VB\">FUNCTION ulong GetPixel(ulong hwnd, long xpos, long ypos) LIBRARY &quot;Gdi32.dll&quot;\n\/\/ get device context - required for graphic stuff\nFUNCTION ulong GetDC(long hwnd) LIBRARY &quot;user32.dll&quot;\nFUNCTION long ReleaseDC (long hwnd, ulong hDC) LIBRARY &quot;user32.dll&quot;<\/pre>\n<p>The function is called of_get_color. It accepts a dragobject by reference.<\/p>\n<pre name=\"code\" class=\"VB\">long ll_xpos, ll_ypos\nulong ul_rtn\nulong ul_handle, ul_device\n\/\/ get handle\nul_handle = handle(a_object)\nul_device = GetDC(ul_handle)\n\/\/ get position of pointer\nll_xpos = UnitsToPixels(a_object.PointerX(), XUnitsToPixels!)\nll_ypos = UnitsToPixels(a_object.PointerY(), YUnitsToPixels!)\n\nul_rtn = GetPixel(ul_device, ll_xpos, ll_ypos)\nReleaseDC( ul_handle, ul_device)\n\nRETURN ul_rtn<\/pre>\n<p>On the window there is an event which is triggered when the user clicks on an appropriate object.<\/p>\n<pre name=\"code\" class=\"VB\">int li_r, li_b, li_g\nulong lul_color\nn_pixelcolor lnv_color\nlul_color =  lnv_color.of_get_color(a_object)\n\/\/max value of unsigned long indicates error\nIF lul_color = 4294967295 THEN\n\tr_1.fillcolor = 0\n\tst_ul.text = &#039;Invalid Color&#039;\n\tst_rgb.text = &#039;&#039;\n\tRETURN\nEND IF\n\/\/ get RGB values\nli_r = mod(lul_color,256)\nli_g = mod((lul_color \/ 256), 256)\nli_b = mod ((lul_color \/ 65536), 256)\n\nst_ul.text = &#039;U Long: &#039; + string(lul_color)\nst_rgb.text = &#039;RGB( &#039; + string(li_r) + &#039;, &#039; + string(li_g) + &#039;, &#039; + string(li_b) + &#039;)&#039;\nst_rgb.textcolor = RGB(li_r,li_g,li_b) \/\/just to prove the values are correct\nr_1.fillcolor = lul_color<\/pre>\n<p>The window displays the color value as well as its derived RGB values.<\/p>\n<div id=\"attachment_637\" style=\"width: 304px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/anvil-of-time.com\/wordpress\/wp-content\/uploads\/2010\/12\/Pixelcolor.png\"><img aria-describedby=\"caption-attachment-637\" loading=\"lazy\" class=\"wp-image-637 size-full\" title=\"Pixelcolor\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/Pixelcolor.png\" alt=\"\" width=\"294\" height=\"242\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/Pixelcolor.png 294w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/Pixelcolor-150x123.png 150w\" sizes=\"(max-width: 294px) 100vw, 294px\" \/><\/a><p id=\"caption-attachment-637\" class=\"wp-caption-text\">Pixel Color App<\/p><\/div>\n<div id=\"attachment_638\" style=\"width: 304px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/anvil-of-time.com\/wordpress\/wp-content\/uploads\/2010\/12\/pixelcolorpicked.png\"><img aria-describedby=\"caption-attachment-638\" loading=\"lazy\" class=\"wp-image-638 size-full\" title=\"pixelcolorpicked\" src=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/pixelcolorpicked.png\" alt=\"\" width=\"294\" height=\"242\" srcset=\"https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/pixelcolorpicked.png 294w, https:\/\/anvil-of-time.com\/wp-content\/uploads\/2010\/12\/pixelcolorpicked-150x123.png 150w\" sizes=\"(max-width: 294px) 100vw, 294px\" \/><\/a><p id=\"caption-attachment-638\" class=\"wp-caption-text\">Color clicked on.<\/p><\/div>\n<p>The code is in PB11.5.1. A zip file with the .pbl and appropriate exports can be found <a href=\"http:\/\/anvil-of-time.com\/wordpress\/wp-content\/uploads\/2010\/12\/pixelcolor.zip\">here<\/a>.<\/p>\n<p>Special thanks to Roland Smith of TeamSybase.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here is a sample application which will give you the color value of the pixel the user clicked on on a picture control (this can be used for any object inherited from a dragobject). To see the list of draggable controls, open the Browser. All the objects in the hierarchy below dragobject are draggable. This&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,10],"tags":[37,12,16,42],"_links":{"self":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/635"}],"collection":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/comments?post=635"}],"version-history":[{"count":5,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/635\/revisions"}],"predecessor-version":[{"id":1902,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/posts\/635\/revisions\/1902"}],"wp:attachment":[{"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/media?parent=635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/categories?post=635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anvil-of-time.com\/wp-json\/wp\/v2\/tags?post=635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}