|
Hi, I'm wondering if anyone knows how I can get rid of the initial document window that displays when an MFC MDI program first starts up? I am writing a program that would acquire images from a scanner. It would not make sense to have an empty white canvas before acquring any scans.
I believe there's a function OnDocumentClose function I can use, but I have no idea where I can place such a call. Also, how would I create a new canvas? Is there a "OnDocumentOpen" of sort?
Thanks!
Jerry
|
|
|
|
|
You can suppress this 'new file' action with
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
in your apps InitInstance.
Doesn't work for SDI though.
|
|
|
|
|
To answer your second question the way I've always done it is as follows:
1) Find the document template (each template is a different doc/view class - you probably only have one in which case just ignore the last two lines)...
POSITION DocPosition;
DocPosition = GetFirstDocTemplatePosition();
CDocTemplate* first_template = GetNextDocTemplate(DocPosition);
CDocTemplate* second_template = GetNextDocTemplate(DocPosition);
CDocTemplate* third_template = GetNextDocTemplate(DocPosition);
2) Create a new file
CSomethingDoc* newdoc = STATIC_DOWNCAST(CSomethingDoc, first_template->CreateNewDocument());
3) Do any work in the Document class you need to and then show the new file
CFrameWnd* newframe = first_template->CreateNewFrame(newdoc, NULL);
newframe->InitialUpdateFrame(newdoc, TRUE);
Hope that helps.
-Dave
|
|
|
|
|
Hi Dave, it's been a while, but thanks for your posted reply on how to create a new document in CWinApp. I didn't get a chance to implement it until now.
I have a follow up question I hope you can help me with. The code you described to me is for CWinApp class. How would I be able to do the same thing inside MainFrm class? Obiously GetFirstDocTemplatePosition() is only exsistant in CWinApp, and I do not know of a way to acquire a pointer to CWinApp from MainFrm. Would you know a way to do that? I appreciate it. Thank you.
Jerry
|
|
|
|
|
Use AfxGetApp(); This can be called from your main frame class.
HTH
Jignesh
|
|
|
|
|
Worked like a charm!!
Thank you thank you.
|
|
|
|
|
No problem...
Try looking into AfxGetApp()
-Dave
|
|
|
|
|
try replacing your calls with;
SaveModified();
AfxGetApp()->OpenDocumentFile ( _T ( "C:\\your_document.ext" ) );
BTW: OnOpenDocument() should not be called directly, it is used by the framework in response to the File Open command... the framework does allot of initialization before and after it calls this.
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
I have a function which returns the Window-handle of the foreground-window like this:
CWnd* pWnd = GetForegroundWindow();
Now I want to check whether there's a CEdit-Control within that window.
How can I achieve this?
thanks in advance
|
|
|
|
|
You need to use EnumChildWindows and then GetClassName to check for the EDIT class of window.
|
|
|
|
|
Something seems to be wrong with this code
BOOL CALLBACK FindEdit(HWND hwnd, LPARAM lParam)
{
BOOL ret = TRUE;
HWND child = ::GetWindow(hwnd,GW_CHILD);
if(child != NULL)
{
char classname[128];
GetClassName(child,classname,sizeof(classname));
MessageBox(NULL,classname,"Class",MB_OK);
}
return ret;
}
HWND child always is NULL
Or do I need to do in a different way?
|
|
|
|
|
You need the GetWindow line. The hwnd parameter passed to the callback function is the child window handle. Just call GetClassName on hwnd.
|
|
|
|
|
OK, now I have this one:
BOOL CALLBACK FindEdit(HWND hwnd, LPARAM lParam)
{
char classname[80];
GetClassName(hwnd,classname,80);
if((strcmp(classname,"edit")) == 0)
{
::SetWindowText(hwnd,"Test");
::CloseWindow(hwnd);
return 0;
}
return 1;
}
this does not work either, altough a window with class "edit" has been found
|
|
|
|
|
I have found the problem
|
|
|
|
|
Hey everyone,
I'm having a problem deleting a dynamically allocated array of strings.
I do something like this to allocate the array of strings:
.
.
.
char** arrayofstrings = new char*[stringcount];
for(int i = 0; i < stringcount; i++)
{
arrayofstrings[i] = new char[MAX_STRING];
}
.
.
.
I do something like this to delete the array of strings:
.
.
.
for(i = 0; i < stringcount; i++)
{
delete [] arrayofstrings[i];
arrayofstrings[i] = NULL;
}
delete [] arrayofstrings;
arrayofstrings = NULL;
The deletion code always crashes. I've done this before with no problem, but its early and I've got a splitting hangover(damn Thirsty Thursday) and can't seem to make sense of it.
Can anyone point me in the right direction?
Oh yeah, what's the tag to format my code in the forums?
Thanks for any help....
Josh
josh@that-guy.net
|
|
|
|
|
A bad stringcount of zero for new char*[stringcount] would cause problems. Good place for an assert, if stringcount is being passed in.
Use the <pre> tag to format code - for more info, see the C++ FAQ
|
|
|
|
|
And writing more than MAX_STRING chars to one of the strings would do it too:
int stringcount = 2;
char** arrayofstrings = new char*[stringcount];
for(int i = 0; i < stringcount; i++)
{
arrayofstrings[i] = new char[10];
}
strcpy(arrayofstrings[0], "This is entirely too many chars");
for(i = 0; i < stringcount; i++)
{
delete [] arrayofstrings[i];
arrayofstrings[i] = NULL;
}
delete [] arrayofstrings;
arrayofstrings = NULL;
|
|
|
|
|
I'm using BCB5 and I'm delay-loading a couple of DLL's which I have put copies of in both my /windows/ and /windows/system/ directories. I'm getting an error when compliling...
[Linker Error] Delay load module <name> was not found
I have the library loaded into my project. Anyone have any ideas?
|
|
|
|
|
How to remove the maximize button, minimize button and the title bar of a window from a specified window?
Thanks.
|
|
|
|
|
Remove WS_MINIMIZE, WS_CAPTION styles
Zolee
|
|
|
|
|
Thanks for your reply. But I still have a question.
Here is my source codes in a dialog based program, but it does not work.
void CTestStyleDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
this->ModifyStyle(WS_MINIMIZE,0);
CDialog::OnLButtonDown(nFlags, point);
}
I have already added the minimized button to the window before running the program. But nothing happens when clicking the left button of the mouse.
How to resolve the trouble?
Thanks again.
Maer
|
|
|
|
|
How can I get the KB articles?
Thanks.
|
|
|
|
|
It's all here:
http://search.support.microsoft.com/kb/c.asp
Josh
josh@that-guy.net
|
|
|
|
|
Thanks
Your reply helps a lot.
Maer.
|
|
|
|
|
I have designed a class for win32 (not mfc) which takes a bitmap , makes a region of it and then draws that bitmap on the window canvas.(skin stuff)
I use a memory dc to speed things up.
However when i quickly move the window it still leaves prints behind.
I don't use any own code to move the window, i intercept the NCHITTEST message and respond with return HTCAPTION;
I have tried writing my own code for WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE to allow tracking and moving of the window and then use SetWindowPos to actually move the window but this sollution leaves even more trails behind. I also capture the WM_ERASEBKGND message.
Any idea on how to speed it up? The only thing i can think of is not moving the window but showing a rectangle of the new window position when people are dragging the window. I tried something like that but got into trouble. I was using a hdc that i got via ::GetDC(NULL) since i need to draw on top of everything else then but i couldn't find a good way of deleting my previous rectangle.
I have looked at other samples for skinwindows but they al seem to use the same draw stuff like i do.
Does anybody have a sample program for this or know how to speed up the drawing without leaving a trail?
Thanks.
|
|
|
|