Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Creating an Image Control Class with hWnd with Windows API


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 FrOzeN89   Members   -  Reputation: 108

Like
0Likes
Like

Posted 29 August 2013 - 02:01 AM

Hi there,

 

I'm writing a home made Business Intelligence application. It will be a Windows-based program written with C++. Something I can log into, view data in graphs, maps, etc.

 

I only started C++ a few months ago and I started writing a basic wrapper around the Windows API so I can reuse it more easily. I've got to the point where I'm starting to create Control objects to be added to the Forms. One Control I'm now trying to create is an Image Control.

 

I want the Image to control to also receive events through it's own WndProc(). I just finished making a TextBox control, where I had to subclass it so I could raise the OnKeyDown(...) events, etc. It was using the Windows CreateWindowEx(. "EDIT" ..).

 

My question is what type of window should I be using to make an image control. Could I create a "STATIC" control and subclass it. I want to be able to use SetWindowPos().. on it and have the object move like any other regular control (i.e: TextBox).

 

Thanks!



Sponsor:

#2 Nik02   Crossbones+   -  Reputation: 2874

Like
0Likes
Like

Posted 29 August 2013 - 05:30 AM

Register&create a normal child window (WS_CHILD) and define its paint handler (handle WM_PAINT in its window procedure) to draw the image associated with the control.

 

If you want SetWindowPos to redraw the image with the new window size, you should also handle WM_RESIZE in the window procedure, and invalidate the window area therein. Also invalidate the control area when you change the source image property (which you define as part of your control class).


Edited by Nik02, 29 August 2013 - 05:33 AM.

Niko Suni


#3 FrOzeN89   Members   -  Reputation: 108

Like
0Likes
Like

Posted 29 August 2013 - 06:06 AM

Ah, so just a regular Window with WS_CHILD, but without using a system class. Thanks! smile.png


Edited by FrOzeN89, 29 August 2013 - 06:06 AM.


#4 Abigail111   Members   -  Reputation: 101

Like
0Likes
Like

Posted 13 September 2013 - 04:12 AM

Hi there

You can simply create image control follow the demo code:

using RasterEdge.Imaging.Basic.Core;
using RasterEdge.Imaging.Basic.Codec;
using RasterEdge.Imaging.TIFF;
using RasterEdge.Imaging.Basic;

namespace RE__Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int width = 100;
int height = 60;

REImage reImage = new REImage(width, height, ImageMode.RGB888);// Create a image with specified width, height and color mode; all pixels are set to white

REFile.SaveImageFile(reImage, "c:/reimage.bmp", new BMPEncoder());
REFile.SaveImageFile(reImage, "c:/reimage.png", new PNGEncoder());
REFile.SaveImageFile(reImage, "c:/reimage.jpg", new JPGEncoder());
REFile.SaveImageFile(reImage, "c:/reimage.tif", new TIFEncoder());
}
}
}



#5 cdoubleplusgood   Members   -  Reputation: 844

Like
0Likes
Like

Posted 13 September 2013 - 05:43 AM

Hi there

You can simply create image control follow the demo code:

 

He asked for C++, not C#.



#6 cdoubleplusgood   Members   -  Reputation: 844

Like
0Likes
Like

Posted 13 September 2013 - 05:52 AM


I only started C++ a few months ago and I started writing a basic wrapper around the Windows API so I can reuse it more easily.

Creating a reasonable and reusable wrapper for the API, especially for windows (HWND), is a surprisingly complex task. Are you sure this is what you want? I mean, if you do it for educational purposes or just for fun... go ahead. But if you just want to finish your application, consider using a framework like QT or wxWidgets.



#7 wintertime   Members   -  Reputation: 1798

Like
0Likes
Like

Posted 13 September 2013 - 02:20 PM

Yeah for handling windows it could get difficult to wrap the calls in a good way into classes, but at least hiding the handles so not everything needs to include windows.h would be helpful.

Also there are some smaller things where you need platformspecific calls and its easy and helpful to wrap them, for example memory mapped files, maybe VirtualAlloc and related functions, critical sections and other thread-related things.

 

Oh and maybe this library helps, I didnt actually use it, but it seems good for making a simple image manipulation program and even opening windows with images and graphs generated from them: http://cimg.sourceforge.net/






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS