|
Yes, EndDialog(int) did the trick, thanks a lot!
You wouldn't know how to load and display images from Win GDI as well?
Thomas
|
|
|
|
|
GDI+ knows how to load images from disk, in GDI you can use ::LoadImage to load a .bmp, but no other format is supported. You can try a library like paintlib if you want to load jpg, etc. You need to load the image in and select it into a DC. Then you can manipulate it or copy to a ClientDC/PaintDC if you want to see it.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
|
|
|
|
|
Yes, LoadImage is present for DirectX too, and only .bmp-files also for that.. great, I couldn't find it anywhere in my MSDN lib because I thought it had a different name.
I will try out the paintlib; it'd be nice to be able to load jpg's too..
Thanks again (to both of you)!
Thomas
|
|
|
|
|
I wondering what code is that ti be added to a dialog based app if I want serialazing?
BETA
|
|
|
|
|
I wondering what code is that ti be added to a dialog based app if I want serialazing?
BETA
|
|
|
|
|
I'm working on a project that has to extract data from an INI file using GetPrivateProfileString. Under Windows 2000, my code works fine, but under Win9x and WinME, it fails.
The INI file in question is formatted like so:
[ SectionName ]
KeyName = SomeValue\t\t; comment
Notice that there are spaces in the "[ SectionName ]", as well as before and after the "=" sign in the key value assigments.
I'm using this code to read the file:
GetPrivateProfileString(" Section Name ", "KeyName", "", 255, "C:\Path\MyFile.ini");
I've tried all combinations of leading and trailing spaces for the section and key names in the GetPrivateProfileString call, but it still refuses to work in Win9x. I can't change the file tro be "compatible" because I'm not the one that generated the file, and besides, it might screw up the original program if I did so.
Anybody got any hints or suggestions?
|
|
|
|
|
I *was* going to point out that .ini files are six years obsolete, but apparently you're stuck with them. I'm surprised at the order of your problem, I'd have thought if anything the legacy code would be broken later ( i.e. Win2K ) rather than a problem where only Win2K works. Is there any reason why you can't just open the file and parse it yourself ?
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
|
|
|
|
|
Well, I'm not really a believer of Microslop's mantra that all program settings belong in the registry, so I only use it when it's required. But beyond that little personal item....
I'm gonna try just removing the offending white spaces from the file, and writing it back to the disk. Then, it *should* work fine on any version of Windows. How it affects the original program that uses this file has not yet been determined.
This is admittedly the most bizarre thing I've seen in a while (if you don't count .NET).
|
|
|
|
|
I scrubbed the files and a) the original program that uses them still works, and b) now mine does too.
The requirement to do so is freaky though.
|
|
|
|
|
Hi !
How can I get a controls HWND ?
|
|
|
|
|
For example the ID of the dialog control is IDC_BUTTON2.
CWnd *pWnd = GetDlgItem(IDC_BUTTON2);
if (pWnd)
{
HWND hwnd = pWnd->m_hWnd;
// hwnd is your handle to the control
}
I hope I could help you...
Gregor Mitsch
E-Mail: abacus-@gmx.de
|
|
|
|
|
Hi Gregor Mitsch!
do you know how to use this function bellow? I found it in the sdk, but fail to use it. Basically, I have 2 dialog. I need to change a value of an edit box on the second dialog, when a button on the first dialog is clicked.
//here is the function prototype
HWND GetDlgItem(
HWND hDlg, // handle to dialog box
int nIDDlgItem // control identifier
);
Thank You
Vu
vucsuf
|
|
|
|
|
You need to say ...
HWND hwnd = ((CastMainWindow*)AfxGetMainWnd)->NameOfControl;
|
|
|
|
|
|
|
i wonna prepare the image (in bmp)
void CTestView::Test()
{
CClientDC dc(this);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
memDC.Ellipse(0,0,200,200);//prepare image
CBitmap bmp;
HBITMAP hBmp=::CreateCompatibleBitmap(dc.GetSafe, 200, 200); // <---------?
bmp.Attach(hBmp);
memDC.SelectObject(&bmp);
//mus be ellipse in dc but...
dc.BitBlt(0, 0, 200, 200, memDC, 0, 0, SRCCOPY);
}
quastion is:
how prepare the image in bitmap and bitblt.. it to main dc?
and what doing the function ::CreateCompatibleBitmap() (in this sample code) ?..
big thx.
|
|
|
|
|
CreateCompatibleBitmap creates a bitmap compatible with a device context. You can just create a bitmap and use GetDeviceCaps(dc.m_hDC, BITSPIXEL) if you prefer - the net result is the same.
By selecting a bitmap into a DC you get sent back the old one that was in the DC, this is one reason why the call to Ellipse does nothing. The second is that until you select a HBITMAP, CBitmap or DIBSection into a DC, it has a size of 1 x 1 x 1, one bit in total. This is clearly of no value
Select the bitmap into the DC first, then draw to your hearts content, the memory bitmap will then be created and able to be blted across. One more caveat - if you use functions like Ellipse as opposed to FillSolidRect ( which takes a pointer to a brush ), then the drawing will be done in the default brush colour, and I'm not sure if Windows offers any guarentees as to what that would be ( but I'd guess white pen, white brush, black bitmap ). Either way, you'd do better to be sure and create your own, and catch all the returns to avoid memory leaks.
Oh - I nearly forgot - call CClientDC at the LAST possible minute to avoid flicker, which I presume is the whole point ?
So here is the final code:
CDC memDC;
memDC.CreateCompatibleDC(NULL);
CBitmap bitmap;
bitmap.CreateBitmap(200, 200, 1, GetDeviceCaps(memDC.m_hDC, BITSPIXEL), NULL);
CBitmap * pOldBitmap = (CBitmap*)memDC.SelectObject(&bitmap);
CBrush red (RGB( 255, 0, 0));
memDC.FillSolidRect(0, 0, 200, 200, &red); // Or create pens/brushes and select the same as we did the bitmap, catching the return of the same type, then you can draw whatever you like...
CClientDC dc(this);
dc.BitBlt(0, 0, 200, 200, &memDC, 0, 0, SRCCOPY);
memDC.SelectObject(pOldBitmap); // And any other objects we selected in, otherwise we get memory leaks
memDC.DeleteDC();
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
|
|
|
|
|
how can write(not from keyboard) in window from CEditView the next text:
"first string
second string
"
using methods of this class. (?)
thx.
|
|
|
|
|
The easiest way is to use SetWindowText method from CEditView object.
|
|
|
|
|
We've got a problem:
We want to load data from a CFile object:
CFile m_ArrFile;
m_ArrFile.Open(m_strArrFile, CFile::modeRead);
char tmp[10];
[...]
UINT bytes = 0;
for (UINT x = 0; x < elemX; x++)
{
bytes += m_ArrFile.Read(&tmp, sizeof(int));
}
No matter how large the file is, the variable "byte" contains only 712 bytes after the loop. Why is it like that and what can we do against it? We use Windows ME.
Gregor & Dominik
|
|
|
|
|
Cause the method CFile::Read returns number of bytes read.
I assume that elemX contain the size of file.
I further assume that You want to add every read int to 'bytes' variable.
Maybe try the following:
m_ArrFile.Read(&tmp, sizeof(int));
bytes += tmp;
Also take a look at the [...] code, cause it may contain
CFile methods which move file pointer ahead in the file.
|
|
|
|
|
Your error lies in m_ArrFile.Read(&tmp, sizeof(int)). Look at what the code means.
"Read 4 (=sizeof(int)) bytes from m_ArrFile and put it where the array buf is located". But what is an array if not a const *pointer* to a static memory area?
Surely you meant m_ArrFile.Read(tmp, sizeof(int)).
(You are most likely screwing up the stack -> which explains your "magic" 712)
|
|
|
|
|
Thank you for the answer. It is true, you are right ( Read(tmp, sizeof(int) ), but nevertheless it does not work even if we leave the '&' out: The function reads only 712 bytes from the file. I could not imagine why...
Gregor Mitsch
E-Mail: abacus-@gmx.de
|
|
|
|
|
Hi! We've solved the problem.
We used CStdioFile and thought that CStdioFile behaves like CFile (because it's derived from it). But that's wrong (at least in our case).
Now we use CFile and it works.
Gregor Mitsch
E-Mail: abacus-@gmx.de
|
|
|
|
|
Hi all,
I have a servive that laucnh a third party program. When the system shuts
down, I try to use my service control handler to process the
SERVICE_CONTROL_SHUTDOWN request from the system for terminating the
launched program (by using TerminateProcess func), but it doesn't work and
the system pop up some message that says "OleMainTreadWndName cannot respond
to End Task Request". It seems the third party program gets hang! I then try
to use SetConsoleCtrlHandler() to setup a handler routine to catch the
CTRL_SHUTDOWN_EVENT and terminate the process a bit ealier than the
SERVICE_CONTROL_SHUTDOWN request, but it doesn't work either. Now I try to
add up the CTRL_LOGOFF_EVENT and terminate the process at this event, then
there is no error message shows up. It seems to me that I need to terminate
the process ealier, at the time my service receive the CTRL_LOGOFF_EVENT.
But the problem is, if user just log off, but not shut down the system, the
process gets terminated! Anyone know some way so that at the time I receive
the CTRL_LOGOFF_EVENT, I also know whether the system is going to shut down
or not?
Thank you for your help,
Rocky Lee
|
|
|
|
|