|
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
|
|
|
|
|
Just a shot in the dark,
How about trapping for WM_QUERYENDSESSION windows message.
The lParam for this Message should tell you what loog off option it is.
Note that this parameter is a bit mask. To test for this value, use a bitwise operation; do not test for equality.
you need to test it with the following values
EWX_LOGOFF
EWX_POWEROFF
EWX_REBOOT
EWX_SHUTDOWN
Hope this helps
Regards
Alfadhly
<marquee>
It is Illogical to define an inventor by his invention
|
|
|
|
|
Hi all.
I need source code about 2d game programming by DX in VC++ ...
If anyone have please send to:
hadi_rezaie@hotmail.com
Thanks.
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
If you want to get into this, I recommend you buy Tricks of the Windows Game Programming Gurus, by Andre Lamothe. It covers every aspect of 2D DX game programming you could think of ( I bought it to learn some AI stuff, and promptly never did, because I'm so busy ).
The SDK also has some game examples, including one called Donuts, an Asteroids game ( I've never seen it because I wrote my own and didn't want to see their source code unless I became absolutely stuck, on the basis that originally I stole their graphics I presume it would be a good exmaple though, but I'm sure it does not use MFC, if you're not used to Win32 style programs. Of course, that would make another reason why you'd benefit from checking it out....
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
|
|
|
|
|
Can i learn DirectX programming by this book ?
Because i want to learn DX7 programming, what is best book for it ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Direct X is up to 8a, why did you choose 7 ? The trouble is they update it so often that there *are* no good books on the latest versions, they are too new. The book I mentioned will cover enough to get you going, but in DX5 ( from memory ). The fundamentals are the same though, especially in 2D. The book gets my vote for broad ( if not terribly deep ) coverage of everything from DirectDraw ( which is what you want )to DirectSound to AI to physics modelling. It's a good overview, and will probably serve you very well in terms of getting you to the point of being able to write a 2D game.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
|
|
|
|
|
I choose DX7 for graphic programming ...
And i don't want to say, why i choose DX7 ?!!!
In your book, Andre Lamonthe used about DX5 ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Fair enough - no need to take it personally. I didn't ask your sexual preference
Like I said, ultimately for DirectDraw it doesn't really matter *that* much, the changes are more in Direct3D ( especially from 7 to 8, but that is another story ). Yes, the book uses 5. So do the official Microsoft books on the subject. Like I said, the hectic release schedule of DirectX versions means by the time books come out, two versions of DX have ticked by.... It is generally accepted that there are no *really* good Direct3D books, people get the general theory from the Red book and then find out the D3D commands from the MSDN.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
|
|
|
|
|
hmmm, Yes.
You said: DirectDraw programming have not different in DX7 or DX8 or DX5, but D3D have many different in DX5 and DX7 and ...
SO, IF I BUY THIS BOOK, I LEARN PROGRAMMING BY DirectDraw in DX ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
>> hmmm, Yes.
>>You said: DirectDraw programming have not different in DX7 or DX8 or DX5, but D3D have many different in DX5 and DX7 >>and ...
>>SO, IF I BUY THIS BOOK, I LEARN PROGRAMMING BY DirectDraw in DX ???
I'm confused here. I'm not sure what the emphasis on the last sentence means. Yes, the book I recommended deals with all facets of writing a 2D game using DirectX, which, by definition, means DirectDraw. I am told there are some pretty cool new DD things in DX8, such as being able to play a movie direct onto a surface, but I would still suspect that there would be more new stuff on the 3D side than in Direct Draw, and certainly DX5 up has everything in Direct Draw that I'd image you *needing*. The book includes full source for a DD game ( an Asteroids game ), which gets built through the book. You should probably go to FatBrain or Amazon if you're interested in the book, and read what other people think of it, plus see an outline of what is in the book. The MicroSoft DirectX book covers DD ( and everything else bar D3D ) and is also a useful reference, but if you specifically want to write a game, then the book I recommended will cover all the other areas you'll want to know about as well. Like I said, the SDK also contains full source to a DD game, that may be all you need.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|