|
If you don't want to close at all handle the WM_CLOSE message and do nothing.
If it is just ALT+F4, try overriding PretranslateMessage() (Assuming you're using MFC)
Christian Skovdal Andersen
|
|
|
|
|
How can deal with PreTranslateMessage to
disable Alt+F4?
|
|
|
|
|
Take a small, blunt knife (for example a butter knife) and lift the key 'caps' for 'Alt' and 'F4' out of the keyboard. Then pour quick setting resin in the spaces and leave for five minutes.
Now you have disabled Alt+f4 . You may like to add this method to your readme file so any end users know as well.
|
|
|
|
|
You can disable closing of the window by disabling the close item in the system menu. (This also disables the close gadget and Alt-F4).
if ((WS_CAPTION|WS_SYSMENU) & GetStyle())
{
CMenu *pSysMenu = GetSystemMenu(FALSE);
if (NULL != pSysMenu)
{
pSysMenu->EnableMenuItem(SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
}
}
|
|
|
|
|
I wish to get the coordinates for the upper left corner of a control derived from a control class, for example CButton. The coordinates should be relative to the uppper left corner of the parents client area.
I've seen that one possible way is to use GetWindowRect, but then I must know the size of the non-client area. How can I get that, or is there a better way to do this?
|
|
|
|
|
You might look at the CWnd::ScreenToClient() method:
void CNewFormView::OnButton2()
{
RECT buttonRect;
CButton* cb = (CButton*)GetDlgItem(IDC_BUTTON1);
cb->GetWindowRect(&buttonRect);
ScreenToClient(&buttonRect);
}
|
|
|
|
|
That was a smart one. I had already solved it, but this cuts my code with 4 rows.
|
|
|
|
|
I installed Microsoft Visual C++ 6.0 but when I click HELP then SEARCH I get following message "MSDN collection not found. Please re-install MSDN". What can I do?
|
|
|
|
|
Try to go into Tools - Options, and select the tab "Help System", in there you can select what MSDN Collection you want to use...
If that does not work, reinstall MSDN...
- Anders
|
|
|
|
|
Imagine we have a CView object and we want to save the screen of the window it handles to a bitmap file or print it out. Any suggestions?
|
|
|
|
|
CWindowDC dc(m_hWnd) will give you a DC that contains your current window. Now CBitmap* pScreen = dc.GetCurrentBitmap(); will give you a CBitmap to play with to your hearts content. There is no point building a DIB, the image is clearly already devive dependant.
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
When I go to File/Print, a print dialog box pops up. At the bottom, the user can change the paper size options. How can I reduce the paper size options to just letter (8 1/2 x 11) and legal (8 1/2 x 14) size paper? How can I eliminate all the other paper size options?
Please, any response any one can give me will be greatly appreciated.
Sincerely,
danYELL
|
|
|
|
|
Doing this will be difficult, since you'd have to either disable print setup or chase all the proprietary printer setup dialogs.
Here's an option that traps the wonky paper size before printing starts, and localizes things in OnPreparePrinting:
BOOL CSDITestView::OnPreparePrinting(CPrintInfo* pInfo)
{
BOOL retval;
while(1) {
retval = DoPreparePrinting(pInfo);
if(retval) {
DEVMODE *dm = pInfo->m_pPD->GetDevMode();
if(dm->dmPaperSize != DMPAPER_LETTER && dm->dmPaperSize != DMPAPER_LEGAL) {
if(IDCANCEL == MessageBox("Paper size is yada yada...", "Prepare printing...", MB_OKCANCEL)) {
retval = FALSE;
break;
}
else {
continue;
}
}
else {
break;
}
}
else {
break;
}
}
return retval;
}
You don't necessarily have to send the user back to the print setup, as this does. Not very friendly, really.
Check the docs for DEVMODE for lots of other good things you can check.
BTW this is not to say you can't alter the print dialog - if what you want to do is add something, rather than disable something, check out Al Stevens article in the December Dr. Dobbs for one approach.
|
|
|
|
|
I want to draw a frame on my toolbar, but unfor. i found maybe CMainFrame has drawn a line on top of the bar that what i don't like it.
What can i do if i dont want the line?
i want MY frame instead of it.
Please talk to me.
|
|
|
|
|
question of beginner
i tried a lot to return full path and the name of the file
to put that in a CString ms
this is the code
{
OPENFILENAME selfile = { 0 };
selfile.lStructSize = sizeof selfile;
selfile.hwndOwner = m_hWnd;
selfile.lpstrFilter = "All Files (*.bin)\0*.bin\0";
selfile.lpfnHook = CResizeTestDlg::HookProc;
selfile.Flags = OFN_ENABLEHOOK | OFN_EXPLORER;
selfile.lpstrTitle="Select File ";
GetOpenFileName( &selfile );
CString ms;
//ms.GetBuffer(of.lpstrFile);
AfxMessageBox(ms);
}
|
|
|
|
|
Before the GetOpenFileName() call, do:
CString strPath;
selfile.lpstrFile = strPath.GetBuffer( MAX_PATH );
selfile.nMaxFile = MAX_PATH;
Don't forget to call strPath.ReleaseBuffer() before using any CString methods on strPath .
--Mike--
http://home.inreach.com/mdunn/
"Didn't I tell you? I've got a brain the size of a planet."
--Marvin the paranoid android
|
|
|
|
|
When I open a new Dialog my using the "m_object.Modal". If I ask the user to enter something in a edit box, and I saved what he typed by using a varible "CString word." After the user closed the Dialog box and now is in the main Dialog, and I want to know is it possible to get what is stored in the word variable?
|
|
|
|
|
It's in m_object.word. You can access all the variables this way, but remember you can't get data from variables attached to edit boxes & the like, because they don't exist anymore.
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
Sure. Either make the members public or create access functions.
CMyDialog dlg;
CString strWord;
if (dlg.DoModal() == IDOK)
{
strWord = dlg.word;
}
|
|
|
|
|
How do I create an MFC application without a dialog or a view? When I put my code in InitInstance it exits and I don't want to use an infinate loop due to cpu. What is the correct way to do this?
|
|
|
|
|
I'm not sure I follow you. Why do you want ot use MFC if you're not going to open windows? If you just want to use the MFC utility classes (CString, CList, etc..) you can do so without creating a CWinApp derived class.
|
|
|
|
|
Yeah MFC or no MFC.. but how would I keep my program running in the background without an infinate loop?
|
|
|
|
|
That depends on if your program accepts messages or not. If it does, then you wait in a loop on GetMessage(), if not then you can use Sleep to give up processor time to other programs or run your program at a low priority.
|
|
|
|
|
This doesn't seem to work. It loops then hangs while waiting for the message.
|
|
|
|
|
Alright, it seems clear that you really don't understand what you want, or cannot communicate it well enough for anyone to understand.
You said you wanted to loop without using CPU time, I told you how, now you're complaining that it's not looping????
Either you want it to loop all the time, or you want to wait for something to trigger a loop, which is it?
|
|
|
|