473,405 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

In C++11 can I preprocess a custom shaped region?

SwissProgrammer
220 128KB
C++11. Not .net. Not VC++.

I can create a region with the following and pick parts of it to use as a custom shaped region for a DIALOG.

I am using a large graphic bmp that takes the following a long time to convert to a custom shaped region that I use for a custom shaped DIALOG.

My question is for the following

Expand|Select|Wrap|Line Numbers
  1. void createSomeRegion(HWND hwndDlg) // This handle is of the DialogBox.
  2.     {
  3.  
  4.         //Get the destination device context
  5.         hdcDestDC = GetDC(hwndDlg);
  6.  
  7.         //Create a memory DC
  8.         hdcMem_001 = CreateCompatibleDC(nullptr);
  9.  
  10.  
  11. //        //To Load from resource.rc as a DIB Device Independent Bitmap
  12. //            HANDLE hBitmap__001 = LoadImage (GetModuleHandle(nullptr), MAKEINTRESOURCE( IDB_TestMasked02), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
  13. //
  14. //            if(hBitmap__001 == NULL)
  15. //                {
  16. //                    MessageBox(hwndDlg, L"Could not load BITMAP from resource!", L"Error", MB_OK | MB_ICONEXCLAMATION);
  17. //                }
  18.  
  19.         //To Load from a file.
  20.             // HANDLE hBitmap__001 = (HBITMAP)LoadImage(GetModuleHandle(nullptr), L"a.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
  21.             //if(!hBitmap__001)
  22.             //    {
  23.             //        //handle error here
  24.             //        return;
  25.             //    }
  26.  
  27.         //Get information about the bitmap..
  28.         GetObject(hBitmap__001, sizeof(bmpInfo_001), &bmpInfo_001);    // Get info about the bitmap
  29.  
  30.         //Select the bitmap into the dc
  31.         SelectObject(hdcMem_001, hBitmap__001);
  32.  
  33.         //Create an empty region
  34.         hRgn_001 = CreateRectRgn(0,0,0,0);
  35.  
  36.         //Create a region from a bitmap with transparency color of white
  37.         //change the pixel values for a different transparency color
  38.         //ex - RGB(0,0,0) will mean a transparency color of black.. so the areas
  39.         //of the bitmap not used to create the window will be black
  40.  
  41.         COLORREF crTransparent = RGB(255, 255, 255);  // To be transparent.
  42.  
  43.         int iX = 0;
  44.         int iY = 0;
  45.         int iRet = 0;
  46.  
  47.         for ( iY = 0; iY < bmpInfo_001.bmHeight; iY++)
  48.             {
  49.                 do
  50.                     {
  51.                         //skip over transparent pixels at start of lines.
  52.                         while (iX < bmpInfo_001.bmWidth && GetPixel(hdcMem_001, iX, iY) == crTransparent)
  53.                             {
  54.                                 iX++;
  55.                             }
  56.  
  57.                         //remember this pixel
  58.                         int iLeftX = iX;
  59.  
  60.                         //now find first non transparent pixel
  61.                         while (iX < bmpInfo_001.bmWidth   && GetPixel(hdcMem_001, iX, iY) != crTransparent)
  62.                             {
  63.                                 ++iX;
  64.                             }
  65.  
  66.                         //create a temp region on this info
  67.                         HRGN hRgnTemp = CreateRectRgn(iLeftX, iY, iX, iY+1);
  68.  
  69.                         //combine into main region.
  70.                         //    int CombineRgn
  71.                         //        (
  72.                         //            HRGN hrgnDst,     // A handle to a new region with dimensions defined by combining two other regions. (This region must exist before CombineRgn is called.)
  73.                         //            HRGN hrgnSrc1,    // A handle to the first of two regions to be combined.
  74.                         //            HRGN hrgnSrc2,    // A handle to the second of two regions to be combined.
  75.                         //            int  iMode        // A mode indicating how the two regions will be combined.
  76.                         //
  77.                         iRet = CombineRgn(hRgn_001, hRgn_001, hRgnTemp, RGN_OR);
  78.  
  79.                         if(iRet == ERROR)
  80.                             {
  81.                                 return;
  82.                             }
  83.                         //delete the temp region for next pass
  84.                         DeleteObject(hRgnTemp);
  85.                     }
  86.                 while(iX < bmpInfo_001.bmWidth);    // Completing a Do While loop.
  87.                                                 // This is not a "while for the next line".
  88.  
  89.                 iX = 0;
  90.             }
  91. //////
  92. //////        //Center it on current desktop
  93. //////        iRet = SetWindowRgn(hwndDlg, hRgn_001, TRUE);
  94. //////
  95. //////        if(!iRet)
  96. //////            {
  97. //////                // messagebox stating that this did not work...
  98. //////                return;
  99. //////            }
  100.  
  101.  
  102. //// Create a reusable rectangular region.
  103. //hReusableRectangularRegion = CreateRectRgn(0,0,100,100);
  104. //
  105. //// Create a temporary brush for a temporary rectangular region.
  106. //HBRUSH hBrushTmporary1 = CreateSolidBrush(RGB(255, 0, 0));
  107.  
  108. //BOOL FillRgn(
  109. //  HDC    hdc,
  110. //  HRGN   hrgn,
  111. //  HBRUSH hbr
  112. //);
  113.  
  114. //FillRgn(HDC_of_MainWindow, hReusableRectangularRegion, hBrushTmporary1);
  115. //
  116. //// The temporary brush is no longer needed. Delete it to free the allocated memory that it is using.
  117. //DeleteObject(hBrushTmporary1);
  118.  
  119.  
  120. ///
  121.  
  122.  
  123. int x = 0;
  124. int y = 4;
  125. //int i = OffsetRgn(hReusableRectangularRegion, (n*47)+(n),(n*47)+(n));
  126. int i = OffsetRgn(hReusableRectangularRegion, (x*47)-x,(y*47)-y);
  127. //int i = OffsetRgn(hReusableRectangularRegion, 0,0);
  128.  
  129.  
  130. iRet = CombineRgn(hRgn_001, hRgn_001, hReusableRectangularRegion, RGN_AND);
  131.  
  132.  
  133.  
  134.         //Center it on current desktop
  135.         iRet = SetWindowRgn(hwndDlg, hRgn_001, TRUE);
  136.  
  137.         if(!iRet)
  138.             {
  139.                 // messagebox stating that this did not work...
  140.                 return;
  141.             }
  142.  
  143.  
  144.  
  145. //        iX = ((GetSystemMetrics(SM_CXSCREEN)) / 2) - (bmpInfo_001.bmWidth / 2 + 50);
  146. //        iY = ((GetSystemMetrics(SM_CYSCREEN)) / 2) - (bmpInfo_001.bmHeight / 2 + 50);
  147.  
  148. //        iRet = SetWindowPos(hwndDlg, HWND_TOPMOST, iX, iY, bmpInfo_001.bmWidth, bmpInfo_001.bmHeight, 0);
  149.         iRet = SetWindowPos(hwndDlg, HWND_TOPMOST, 300, 300, bmpInfo_001.bmWidth, bmpInfo_001.bmHeight, 0);
  150.  
  151.         //Copy the memory dc into hdcDestDC
  152.         paintRegion_001();
  153.  
  154.         //delete the bitmap
  155.         DeleteObject(hBitmap__001);
  156.     }
What I have tried:

C++11. Not .net. Not VC++.

I tried searching for a faster custom region creation but did not find that.

I tried testing the time that it takes for the large bitmap to be converted to a custom region and to be used for the modeless dialog, and it looks like about 10 to 15 seconds. That is too long.

I tried to figure out how to pre-process the custom region, but I am not clear how to do this.

I tried #void createSomeRegion(HWND hwndDlg), but that did not work.

I want to be able to process a large graphic (bmp) into a custom region, and have that already-processed region included in my final stand-alone executable, which I can use without having to go pixel by pixel when the exe runs.

I wandered through various wastelands of .net and VC++ starving for real C++ code.

Thanks for your help with C or up to C++11 answers.
Jul 7 '20 #1
2 1764
Banfa
9,065 Expert Mod 8TB
I haven't worked with regions like this myself but by the sounds of it you are trying to create a custom region that doesn't change, I suspect the time issue is because you are creating so many small regions and adding them into a larger region but this isn't really what you need.

I would have thought you would be better off with a single call to CreatePolygonRgn. In order to make that call you will need a list of points that make up the polygon that you wish the region to have.

Therefore I would create a separate utility program that analyses the bitmap and outputs the list of points, you can then include that into your main program so that you can create the region in a single step without having to process the bitmap at all.

Not sure if this would work but it's what I would try.
Jul 7 '20 #2
SwissProgrammer
220 128KB
Thank you Banfa.

I would like that. I think that is what I am trying to do in my efforts to streamline the process. I do not know how.

Example: A cloud map of one moment of clouds over the United States and outlying regions. If that cloud map is stationary and if it is used for some interactive purpose later where the user can click through the transparent areas to the US map behind the cloud map then creating the custom region for the cloud areas, as I am doing, can take a long time. I want to process the custom region one time, then include the processed custom region in the executable so that each time the exe starts up it does not have to re-process the custom region. This is a struggle for me as I write this.

I am not so good at arrays. Could I do this custom region processing and save it to an exterior array file and then load that as a resource when compiling the executable, thus making the array an integral part of the final exe?

I feel like a monkey contemplating calculus while not knowing to let go of the apple in the monkey-puzzle box.

Help!



Thanks.
Jul 8 '20 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: James | last post by:
I have an picture cut out in a certain shape that I would like to make as my form. I have tried following the directions in MSDN on how to make shaped windows forms but their directions did not work...
2
by: Flix | last post by:
I need some help to handle the Region property of my Form in the correct way. Usually when I create shaped forms in my programs, I modify the Form.Region property, making it include only a part of...
0
by: Erick Shuai | last post by:
In my project, I need to use custom attribute on all assemblies. This attribute will implement some non-functional code and I want to use it on assembly scope(AttributeTargets is Assembly). I...
4
by: Failure | last post by:
As far as I know, Groupboxes only come in one shape, a rectangle. But on one of my forms, it would be best if I could have a groupbox that's shaped like this: _______ | | _________|...
2
by: M West | last post by:
hello, currently trying to write a custom control that will display an image in true transparent form, e.g. can actually see the background images placed behind the control rather than the...
3
by: pamelafluente | last post by:
Hi I have seen on some web pages a nice type of tooltip. See for instance http://www.programurl.com/software/tooltip.htm and mouse over on Javascript (first box left). Can anyone point me or...
0
by: zyberboy | last post by:
I am a beginner in programming(c#),and this is my first post in this forum. I want to know how to create custom shaped windows form in vs2005 express edition. I was able to create a oval shaped form...
1
by: PankajGaur | last post by:
Hi, I need to create a Ellipse shaped user control which have folloiwng attributes: 1) The edges are smooth 2) The control shuld only be selected when click on the ellipse shape & not when...
0
by: =?Utf-8?B?UGFua2FqR2F1cg==?= | last post by:
Hi, I need to create a Ellipse shaped user control which have folloiwng attributes: 1) The edges are smooth 2) The control shuld only be selected when click on the ellipse shape & not when...
0
by: castironpi | last post by:
Hi all, I am trying to create a custom tuple type. I want it to live in a custom memory region, which will be a memory-mapped file. Its contents cannot be PyObject*. They have to be offsets...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.