|
First, create your file, then:
SetFileAttributes(lpFileName, FILE_ATTRIBUTE_READONLY);
Of course i'm not sure ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Can a CRuntimeClasses be serialized using a CArchive. Can it be done by using code like this
CRuntimeClass *runtimeclass = RUNTIME_CLASS(CRandomClass)
ar << runtimeclass; or by
CRuntimeClass *runtimeclass = RUNTIME_CLASS(CRandomClass)
ar.WriteObject(runtimeclass); or is there another more complex solution?
Joel Holdsworth - the child eating devloper
'My cup of tea has caught fire!'
|
|
|
|
|
|
Hey folks,
I've been working on some code for some time which simply draws interconnecting boxes with text on the screen using the basic window calls to illustrate some kind of network connectivity. (Box represents a server, lines represent some kind of cabling between that server, and another).
For fun, I thought it would be great if I could implement some kind of "ZOOM" function which would change the sizes of the boxes dynamically, then choose a font which would fit in the new boxes.
I created a pull-down from the window I created, and added a resource for "10%", "25%", "50%", 100%", "200%", where 100% is the NORMAL view when you launch this window, 50% being half of the original etc, you get the idea.
When a user clicks on one of my "Zoom" items, I initialize a global variable called ZoomFactor which contains the ratio of how the diagram is to change. (ie. ZoomFactor == 1, denotes 100%, or normal view, ZoomFactor == 0.5, denotes half the original).
When the time comes to "build" the diagram again, I dynamically determine the new cell size by using the code below:
// Set our cellsize to be our zoomed cell size.
GetTextExtentPoint32 ( hdc, "A", 1, &szorgFontSize );
szZoomCellSize.cx = (LONG)(szorgFontSize.cx * ZoomFactor );
szZoomCellSize.cy = (LONG)(szorgFontSize.cy * ZoomFactor );
// Set the size of my server box width, by multiplying
// the new cell X size, by the maximum number of chars/server box.
ServerBoxWidth = szZoomCellSize.cx * MaxServerChars;
NO Problems, everything is great, my szZoomCellSize is scaled properly, my box sizes change as they should, Problem comes when I want to create an appropriate font for the new cellsize.
Basically, I want to create a font which will fit in the szZoomCellSize rectangle, I make this call in hopes that the font it creates will fit insize of the ZoomCell.
// Setup our new font
hfont = CreateFont ( szZoomCellSize.cy, 0, GM_COMPATIBLE, GM_COMPATIBLE, FW_NORMAL, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEVICE_PRECIS, CLIP_LH_ANGLES,
PROOF_QUALITY, FF_MODERN, lfnt.lfFaceName );
After I made this call, I noticed that in many cases, the font that it choose had a proportionate height and width (the font didn't look stretched), but was often TOO big for the box I've created. I added a "GetTextExtentPoint32" call after the create font and found that the font it picked was in most cases, LARGER than the "szZoomCellSize.cy" I specified. I understand that most fonts are NOT fixed width, so I even change the character in both "GetText" calls to "M", because M is usually one of the bigger characters, no go, same results.
I've spent some time looking through "CreateFont" and found it to be a little out of my league... By no means am I an expert graphics guy, just need a basic explanation! Anyone? Ive heard I can also create a bitmap of sorts, and just StrechBlt it, but I'm leaning NOT to do that...
Anybody see what I'm doing wrong here?
Much appreciated,
Mike.
|
|
|
|
|
First things first: you should negate the szZoomCellSize.cy. Details are in CreateFont docs
The second thing is that you're not guaranteed to get all character widths multiplied by X when you're scaling height by X. Scalable fonts can have hints and rendered bitmaps may have slightly different widths. You should just use DrawText with DT_END_ELLIPSIS flag to automatically display '...' if there's not enough space to display all characters in the box.
I've heard I can also create a bitmap of sorts, and just StrechBlt it, but I'm leaning NOT to do that
Don't StetchBlt. The algorithm used by this function is simple and fast - it doesn't perform any interpolations and resulting image looks ugly when scaling factor is not 2, 4, etc.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thomas,
Thanks for your reply.
I'm not quite sure what you mean by "negate", sounds silly and all, but do you mean put a "-" in front of my szZoomCellSize.cy?
hfont = CreateFont ( -szZoomCellSize.cy, 0, GM_COMPATIBLE, GM_COMPATIBLE, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEVICE_PRECIS, CLIP_LH_ANGLES, PROOF_QUALITY, FF_MODERN, lfnt.lfFaceName );
I've made this change, and I'm still finding that the font its creating is larger than the HEIGHT I've specified. Is there a way or flag what would tell CreateFont to take the closest, lesser nHeight it can find?
In my code, everything revolves around the size of the font. Before I draw the text using the "ExtTextOut" with the ETO_CLIPPED option, I call "GetTextExtent32" to find out the average height and width of a characer. I then build a rectangle to which the text "should" fit. If the font "CreateFont" picks is larger than the box, then my rectangle and font will inevitably fall out of the box. You see my problem
By the way, I downloaded your screen saver app, great job...
Thx.
Mike.
|
|
|
|
|
I call "GetTextExtent32" to find out the average height and width of a characer.
Well, this is an average width. I think the best solution would be using DrawText instead of GetTextExtent32/ExtTextOut. You can use DrawText with DT_CALCRECT - in this case, nothing is drawn - the function calculates the rectangle needed to fit your string. So when user zooms in/out, you should create a font with given height, then paint all boxes using rectangle returned by DrawText called with DT_CALCRECT.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Have you tried using DrawText, seeing as you already have a rectangle in which you what the text to fit.
I am not too sure as to what this does to the actual font you have selected in the DC at the time, but I do know that there is a flag that will scale the text to fit in a given rectangle.
Hope this help
AndyC
|
|
|
|
|
Andy,
I'm using ExtTextOut with the ETO_CLIPPED option. This works the same way as DrawText, my problem comes when the font is created, its TOO big based on the nHeight I specified.
I build a rectangle object using the limits of the box that is to be created dependant on the zoom factor etc, but the font it creates is LARGER than the box I've created. whooops!
I'd have to show you in a screen shot or something! Any ideas?
Thx.
Mike.
|
|
|
|
|
I am creating listbox, where the user can select one or more items. I wnat my software to be such that even after the user makes the selections, clicks OK, and then opens the same dialog (with the listbox in it), he/she would see tha last selections made highlighted in the listbox.
In short I want the listbox to show the last chosen settings.
How do I do that??
It is what we choose to be that makes us what we are, far more than our abilities.
-J.K. Rowling
|
|
|
|
|
You should store the selection in CYourDlg::OnOK, and re-load it in CYourDlg::OnInitDialog (after the call to CDialog::OnInitDialog). Do you use item data in listbox?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Ok,
I'm rather new to this, so I'm stumped... but I don't think it should be too hard...
I have a window-based app with buttons. When certain buttons are clicked, lenghty processes are started. I want a modal dialog box to display with a message like "Wait..." (or perhaps a progress bar) when the button is clicked and then be undisplayed when the process is finished. It's important that mouseclicks on the main window's buttons are ignored when the process is underway (that's why I want the dialog to be modal).
This seems like it should be simple, but I don't understand how I can call DoModal(), get the window displayed, get the process started, wait for the process to finish, and then do an EndDialog()... this must be a pretty common task, but I don't see how to use the CDialog framework (or derivation of it) to get the job done.
thanks! any help is appreciated!
m-flury@northwestern.edu
|
|
|
|
|
In VC++ help, go to 'Contents' tab, then Periodicals - 1997 - MS Systems Journal - February - Wicked Code. The article by Jeff Prosise has a solution for your problem.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
2 ways you can do this
1) Show your dialog and in your modal dialogs OnInitDialog or somewhere else approrpriate, launch the lengthy process.
2) Show a modeless dialog but call AfxGetMainWnd()->EnableWindow(FALSE);
|
|
|
|
|
These errors were displayed when I ran my game in debug mode. The application runs fine as far as I can tell but I have no clue what they mean:
DAMAGE: After Normal block (#17) at 0x00A60DC0
CORE :fff6095f:fff5278f:pdnObject [2f2f110]
CORE :fff6095f:fff5278f:Could not find any entries in the HandleTable
CORE :fff6095f:fff5278f:Object is not initialized
Direct3D8: (ERROR) :Hwnd passed is not a valid window
memory check error at 0x00A60E13 = 0x6F, should be 0xFD.
memory check error at 0x00A60E14 = 0x20, should be 0xFD.
memory check error at 0x00A60E15 = 0x31, should be 0xFD.
memory check error at 0x00A60E16 = 0x36, should be 0xFD.
Any help would be appreciated
-Corillian
|
|
|
|
|
DAMAGE: After Normal block (#17) at 0x00A60DC0
This sounds like heap corruption - the bytes after allocated memory block have been overwritten by your application. In debug mode you're only getting the message, in release this would be probably the application crash. You should use BoundsChecker or Purify to pinpoint the problem.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Where would I get BoundsChecker or Purify, and are they free?
|
|
|
|
|
BoundChecker is at www.numega.com, I guess ( i.e. Numega make it ) and your guess on price is out by about a grand ( in Australia anyhow ).
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
The most common cause for this problem is a buffer overflow condition. You probably have either an array or dynamically allocated memory somewhere in your app which you are writing-past in your application.
Example:
char szTemp[20];
for (int iX = 0; iX <= 20; iX++)
{
szTemp[iX] = ' ';
}
This will write past the end of the array and corrupt the stack at offset (szTemp + 20)
should be
char szTemp[20];
for (int iX = 0; iX < 20; iX++)
{
szTemp[iX] = ' ';
}
|
|
|
|
|
Ok, that's what my first assumption was also. The problem is that i have almost a hundred arrays doing various things. Do you know of any tricks to help find the location of a memory overwrite/leak in a source file?
|
|
|
|
|
Off the top of my head, I can think of 3 things you can try.
1) Make sure your warning level is set to level 4. This will probably not find the error, but its worth a shot and is always a good place to start.
2) If you have access to Purify or BoundsChecker, either will almost always find this kind of problem.
3) This is also not guaranteed, but has proven succesful for me on ocassion. It requires modifying your code, but makes for a simple and performance sensitive check. If you get in the habbit of coding this way, it can solve problems later.
When you have code which reads like below.
char szBuffer[20];
for (int iX = 0; iX < 20; iX++)
{
}
change the code to be
char szBuffer[22];
szBuffer[20] = 0; szBuffer[21] = 255;
for (int iX = 0; iX < 20; iX++)
{
}
ASSERT(szBuffer[21] = 255);
This also mean that when allocating blocks of memory, you will always need to allocate 1 or 2 extra bytes and set the last byte to some value which is unlikely to properly exist in the data. Then before freeing the data, check the value of the last byte for the value you gave it, if its not what you set it to, you just overan your memory.
Note: This is not a guaranteed check because it is possible that the value written into the check byte was the value you put there to begin with, but its still a good preaution.
|
|
|
|
|
oops!
ASSERT(szBuffer[21] = 255);
should have been
ASSERT(szBuffer[21] == 255);
|
|
|
|
|
My CMainFrame class has code to position my docking control bars in OnCreate(). When my app is activated as an active document server, the control bars are created in OnCreateControlBars(). The code to dock each control bar requires m_wndToolBar.GetWindowRect(). The result of GetWindowRect()is silly when called from OnCreateControlBars(). Does anyone know where I should create and position docking control bars when activated as an active doc server?
|
|
|
|
|
hi,
I want to remove my mfc application icon from the taskbar.It must be present only in the process list of task manager.ie it must not appear in the application in taskmanager.
|
|
|
|
|
|