|
What is the easiest way to convert a HBITMAP to JPEG file in C/C++?
Thanks,
Regards,
Xavier
|
|
|
|
|
I don't know why that didn't post - I'll try again. Use GDI+, read the Doodle article on this site.
Jonathon
|
|
|
|
|
Hi everyone! This is my first foray into 'The Code Project'.
I learned windows programming through MFC and I'm just now going back and trying to relearn it without MFC (so that presumably when I return to using it I will have a much higher appreciation.) Anyway, I have a simple problem and I would be grateful for help with it.
I made the default MSVC 6.0 SDK 'Hello World' project. Then I put some controls on it using CreateWindow("EDIT"...) and "STATIC" and "BUTTON". Now I want a window that simply sends a message to the parent giving client x,y coordinates when it is clicked on. The way I used to do this was just to capture the clicks in the main window and do the calculations to see whether the click was in any of the child windows. I tried subclassing (I just learned what subclassing is) a "STATIC" window to handle the WM_LBUTTONDOWN, but it acts like it's not even there . I know the subclassing worked though because it handles WM_PAINT fine.
Thank you!
|
|
|
|
|
When you create the static control add the SS_NOTIFY style. This will make the control send the STN_CLICKED notification message when the window gets clicked on.
-Ben
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
I saw that option while I was poking around (though it doesn't help that SS_NOTIFY isn't in the MSDN help index ) and I dismissed it after looking at the scant offerings of STN_* (I think they were 'click' 'dblclick' 'enable' and 'disable' or something) since I needed more information (like *where* they clicked and which button) which is why I decided to learn about subclassing.
Anyway, I tried the SS_NOTIFY style just for the hell of it, and lo and behold all of the subclassing stuff I was trying to do started working! I guess the subclassing doesn't work unless you have SS_NOTIFY on, though I can't find that in the help anywhere.
Thank you, Benner!
|
|
|
|
|
Is there any other build-in function that can receive the window message or message generated by driver?
I just know that WindowProc() is one of the function.....
Thanks
|
|
|
|
|
using the windows hook.
SetWindowHookEx(...),you can find more detail from Msdn.
|
|
|
|
|
I an trying to pass a CArray object as a parameter to a function.
code is somewhat like this:
"
void SetPoints(CArray"<"CPoint, CPoint&">" points);
anotherfunction{
CArray"<"CPoint, CPoint&">" myArray;
SetPoints(myArray);
....
}
I keep getting compilation errors saying that it cannot convert parameter 1 of SetArray from
CArray<cpoint, cpoint&=""> to CArray<cpoint, cpoint&="">
"
does not make sense to me!!
Please respond by e-mail if you know what's ahappend..
really need it badly!!
|
|
|
|
|
void SetPoints(CMyArrayType &array)
{
...
}
you need to pass the array as a reference
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
#include '<'afxtempl.h'>'
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
#include '<'afxtempl.h'>'
Cheers!!!!
Carlos Antollini.
Carlos Antollini.
|
|
|
|
|
I an trying to pass a CArray object as a parameter to a function.
code is somewhat like this:
"
void SetPoints(CArray<cpoint, cpoint&=""> points);
anotherfunction{
CArray<cpoint, cpoint&=""> myArray;
SetPoints(myArray);
....
}
I keep getting compilation errors saying that it cannot convert parameter 1 of SetArray from
CArray<cpoint, cpoint&=""> to CArray<cpoint, cpoint&="">
"
does not make sense to me!!
Please respond by e-mail if you know what's ahappend..
really need it badly!!
|
|
|
|
|
I an trying to pass a CArray object as a parameter to a function.
code is somewhat like this:
void SetPoints(CArray<cpoint, cpoint&=""> points);
anotherfunction{
CArray<cpoint, cpoint&=""> myArray;
SetPoints(myArray);
....
}
I keep getting compilation errors saying that it cannot convert parameter 1 of SetArray from
CArray<cpoint, cpoint&=""> to CArray<cpoint, cpoint&="">
does not make sense to me!!
Please respond by e-mail if you know what's ahappend..
really need it badly!!
|
|
|
|
|
You're trying to pass CArray by value. This fails, because CArray has no copy constructor defined. To solve the problem, pass array by reference:
void SetPoints(CArray<CPoint, CPoint&> & points);
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
I don't know if it will help you, but...
I have never passed a CArray object to a function, but I have returned one from it.
//prototype.
CArray <strctpaquetreldocreceptor,strctpaquetreldocreceptor&> *GetArrayPaquetRelDocReceptors();
//return of the CArray (inside the f(x))
CArray <ctamcontrolcenterapp::strctpaquetreldocreceptor,ctamcontrolcenterapp::strctpaquetreldocreceptor&> *CTAMControlCenterApp::GetArrayPaquetRelDocReceptors()
{
return &m_ArrayPaquetRelDocReceptor;
}
I remember that without the #include <afxtempl.h> inside the stdafx.h it didn't work...
This is the same but in the reverse order, I expect it helps you...
I'm a novice speaking english, I'm sure you will have noticed it... I beg your pardon...
|
|
|
|
|
Hi all,
I have trouble refreshing one static text after having set it to WM_VISIBLE off
if I minimize & maximise again the static is gone but how can I send order to refresh
the static text directly.
I tried already invalidatrect drawwindows() and some other solutions, nothing work.
I suppose that I should invalidat the Cstatic object (in fact the excellent CLabel class
derived from CStatic) then send a WM_PAINT to the main but I don't know how to exactly
do this following the rules to get clean code. (I'm newbies at MFC)
Thanks for any help
Dany
|
|
|
|
|
Using WS_VISIBLE is similar to using the following function:
ShowWindow(hwnd, SW_HIDE); //This hides the window!
To re-show or make visible:
ShowWindow(hwnd, SW_SHOW);
Mh2!
|
|
|
|
|
don't set id of the static control to id_static,
it must unique
|
|
|
|
|
Many thanks, just tried it work fine...
I dealed with several API and language and was always suspicious about MFC but it's
incredible what we can do in no time
I don't want to abuse but one more question:
Is there a ways to avoid immediate refresh when setting SW_SHOW cause I have several
static (another name of course ) to show and even if it's fast we can see that
they come up one by one.
something like :
DisableWindowsUpdate();
..SW_SHOW
..SW_SHOW
...
EnableWindowsUpdate();
Again thanks it will be my last question (for this thread of course )
|
|
|
|
|
After looking in several places for example code and not finding any, this is the result: (please ignore any extraneous quotation marks)
#pragma pack(1)
typedef struct {
int A;
int B;
} myType1;
typedef struct {
char A;
char B;
} myType2;
#pragma pack()
template "<"typename T">"
void copydata(T* dst, char* src)
{
char* ptr = (char*)dst;
for (int i=0; i < sizeof(T); i++) {
*ptr = *src;
ptr++;
src++;
}
}
I know it isn't very type-safe. Does anyone have suggestions for improving this? Thanx
>>>-----> MikeO
|
|
|
|
|
I'd use memcpy.
> I know it isn't very type-safe.
It's not only type-unsafe. It's totally unsafe.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
It was written as a non-class template excercise. The example is trivial, but the real-world structures share some common elements that will be used in future templates. Since sizeof(T) is used to limit the amount of data copied, what is unsafe about the template?
>>>-----> MikeO
|
|
|
|
|
> real-world structures share some common elements that will
> be used in future templates. Since sizeof(T) is used to limit
> the amount of data copied, what is unsafe about the template?
You're using a C++, right? (last time I've checked C had no templates). Don't expect bitwise copy to work correctly with C++ objects. Moving bits around will work only if your structs are simple aggregates of primitive types like int, char or double.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
> Moving bits around will work only if your structs are
> simple aggregates of primitive types like int, char or double
In this instance the structs are simple aggregates, but your point is well taken.
Having programmed in C for the past several years it is sometimes difficult adjusting to C++.
Thanx for your input.
>>>-----> MikeO
|
|
|
|
|
I'm working on an application that contains a CListCtrl. One requirement for the list is that it always displays its vertical and horizontal scrollbars, regardless of the client area. I've tried simply setting the WS_HSCROLL and WS_VSCROLL styles during creation, but to no avail. After much trial and error, I was able to force the scrollbars to display by modifying the list's style in response to a WM_SIZE message.
//
// WM_SIZE handler
//
void ACtrlGrid::OnSize(UINT f_nType, int f_cx, int f_cy)
{
// call base class
CWnd::OnSize(f_nType, f_cx, f_cy);
// re-add horz + vert scrolls
UINT nStyle = GetStyle();
if ( (nStyle & WS_HSCROLL) != WS_HSCROLL
|| (nStyle & WS_VSCROLL) != WS_VSCROLL )
{
ModifyStyle(0, WS_HSCROLL | WS_VSCROLL,
SWP_NOMOVE | SWP_NOSIZE |
SWP_NOZORDER | SWP_FRAMECHANGED);
}
else
{
// ... actually handle WM_SIZE message
}
}
I have two problems with this approach. First, as a result of re-adding the scrollbars the client area size changes which generates another WM_SIZE message. Eventually this recursion is terminated, no thanks to me, but its still a hack. My second issue involves the CListCtrl's header sizing ability. With this approach it is impossible to grab the last column's sizing handle because the vertical scrollbar is covering the right edge of the last column header item. It seems that the listview don't realize when the vertical scrollbar is displayed, and as a result, the horizontal scrollbar range is not increased to account for the extra room the scrollbar is covering.
I'm really looking for an elegant way to override the listview's default scrollbar implementation.
Your assistance is greatly appreciated.
Mike
|
|
|
|