|
I am trying to programmatically create menus in SDI.
The error message I get is "failed to create
empty document."
I started with a SDI application that was working fine
with menus created by menu templates in the
.RC file. The only thing I changed was to remove the
menu templates in the .RC file. I left the menu
resource definition for IDR_MAINFRAME in
Resource.h. I also left the reference to IDR_MAINFRAME
in InitInstance:
///////////////////////////////////////////////
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSdiDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CSdiView));
//////////////////////////////////////////////
Question 1) Is this use of IDR_MAINFRAME correct?
Question 2) If not, what is supposed to be the second
argument instead of IDR_MAINFRAME?
I placed the following menu creation
commands in the OnCreate function of the frame window
.cpp file, but OnCreate never gets called by InitInstance.
////////////////////////////////////////////////////////////////////////////
CMenu mainmenu; // create main menu
mainmenu.CreateMenu();
CMenu menuPopup; // create the popup menu
menuPopup.CreatePopupMenu();
menuPopup.AppendMenu(MF_STRING, ID_COLOR_RED, "&Red");
menuPopup.AppendMenu(MF_STRING, ID_COLOR_YELLOW, "&Yellow");
menuPopup.AppendMenu(MF_STRING, ID_COLOR_GREEN, "&Green");
// attach popup menu to main menu using menu handle
mainmenu.AppendMenu(MF_POPUP, (UINT) menuPopup.Detach(),
"&Colors");
// the next line is a *complete guess* as to how to load the menu
mainmenu.LoadMenu(MAKEINTRESOURCE(&mainmenu));
AfxGetMainWnd()->SetMenu(&mainmenu);
////////////////////////////////////////////////////////////////////////////
Question 3) Are these menu commands correct for
creating & loading menus?
From what I can tell, the application gets only partly
through InitInstance, specifically up to this command:
if (!ProcessShellCommand(cmdInfo)) return FALSE
It returns false & OnCreate is never called & the
frame window is not created.
Question 3) What else am I doing wrong?
thank you for your assistance.
mary, houston, texas
|
|
|
|
|
I *suspect* it's failing because it cannot find the menu you deleted. Why not try leaving the resource there and deleting it's contents ?
Why do you want to do it this way - is your menu so fluid that greying items is not an appropriate solution ?
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
great idea! I left the barest skeleton of a main menu,
& the menu is loaded, but what do I use for the name of the
CMenu class object with AppendMenu() assuming the
following code remains in OnCreate?
////////////////////////////////////////////////////////////////////////////
CMenu mainmenu; // create main menu
mainmenu.CreateMenu();
CMenu menuPopup; // create the popup menu
menuPopup.CreatePopupMenu();
menuPopup.AppendMenu(MF_STRING, ID_COLOR_RED, "&Red");
menuPopup.AppendMenu(MF_STRING, ID_COLOR_YELLOW, "&Yellow");
menuPopup.AppendMenu(MF_STRING, ID_COLOR_GREEN, "&Green");
// attach popup menu to main menu using menu handle
mainmenu.AppendMenu(MF_POPUP, (UINT) menuPopup.Detach(),
"&Colors");
AfxGetMainWnd()->SetMenu(&mainmenu);
|
|
|
|
|
CMenu* pMenu = AfxGetMainWnd()->GetMenu();
gets you a pointer to the existing menu, then use InsertMenu to insert your created menu (menuPopup) into it.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I'm trying to modify the icecast server so that i can be used as a service. When I use the SC_HANDLE to declare a variable, the compiler gives me a:
error C2275: 'SC_HANDLE' : illegal use of this type as an expression
error. I don't understand what i'm doing to cause that. Here it is in context:
int
main (int argc, char **argv)
{
g_bService = FALSE;
g_bStop = FALSE;
SC_HANDLE hManager;
SC_HANDLE hResult;
SC_HANDLE hService;
hManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
if (hManager)
{
hService = OpenService(hManager,"icecast",SERVICE_ALL_ACCESS);
if (hService)
{
g_bService = TRUE;
SERVICE_TABLE_ENTRY DispatchTable[] =
{
{"icecast", IcecastMain},
{ NULL, NULL}
};
if (!StartServiceCtrlDispatcher(DispatchTable))
{
SvcDebugOut("[ICECAST] StartServiceCtrlDispatcher error=%d\n",GetLastError());
}
}
}
else
{
IcecastMain(argc, argv);
}
startup_mode ();
return 0;
}
It give me an error on the first 3 variable declaration of SC_HANDLE.
Here is the SC_HANDLE declaration from winsvc.h:
DECLARE_HANDLE(SC_HANDLE);
typedef SC_HANDLE *LPSC_HANDLE;
Any Help would be greatly appreciated.
Stephen Caldwell
Blackfission, CEO
http://bf.steffc.yi.org:81
|
|
|
|
|
Hi all.
I'd like to know how it is possible to know the (x,y,cx,cy) of a menu (CRect information ?) or do i have to count the number of item * Item Heigh ?
Who knows ?
|
|
|
|
|
I have a CDialog derived class. I'm trying to make the background colour of the dialog match the dithered title bar. (Like MSN messenger does).
I thought it would be a simple as creating a brush with COLOR_GRADIENTACTIVECAPTION and setting the brush in WM_CTLCOLORDLG. However all I get is the first colour and not the gradient effect.
Can somebody point me in the right direction on how to achieve this effect.
Michael
|
|
|
|
|
Check out the GradientFill() function which will draw a rect (or even a triangle!) with a gradiated color.
--Mike--
http://home.inreach.com/mdunn/
"....." -- Silent Bob
your with and
|
|
|
|
|
So long as you aren't writing for Windows 95 or NT 4.0, and have a Platform SDK installed. Otherwise you'll have to draw the gradient yourself ( no big deal ).
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Can anyone tell me how I can create a Modeless Dialogbox inside an MDI Window. If I create a dialog as modeless, using the Create function, and set the parent to the MainFrame MDI window, the dialog appears non-focused, as if it is disabled but you can still do everything with it.
I found the solution once before, but can't recall it
Any help will be appreciated...
|
|
|
|
|
Dear Sir/Madam,
Can I have a way to convert the view class in MFC Exe project into a DLL
to be used by other program? Since many functions are include in my View
class, it's not so easy to extract them as independent ones. So I am
wondering if I can make the whole view class as a DLL and use it in other
project. Thank you for your any suggestion.
Best regards,
C. Lei
|
|
|
|
|
Yes it is possible to export the view class.
You can export classes from an MFC Extension
DLL, but u got to be sure that it does not
have any dependencies, like using the data
from the document object. If any dependencies
are there then include those classes also.
|
|
|
|
|
Help!
I'm using the Rich Edit control (version3 on win2k) and
I'm trying to code
up a 'Page View' option for an editor I'm writing, the sort of
thing that'll Zoom up/down the text view by a percetage or to
the whole page or page width - you know the sort of thing.
I've got the zooming up working through the new EM_SETZOOM message
and appropriately selected ratio values for nNum and nDenom
but I can't get the zoom down to work, which is vital for the page view.
Has anyone been able to do this?
Are there any other cunning ways to do this?
|
|
|
|
|
|
add this line after the "includes"
#pragma comment(lib,"ddraw.lib")
regards
|
|
|
|
|
|
gern geschehen
|
|
|
|
|
You need to add the .lib library of Direct Draw in the settings of yor project, do ALT+F7, or prject/settings in the menu of vc++, select the link tab, and add the library. Y don't have the MSDN here, but i think that is ddraw.lib
Cheers....
Carlos Antollini.
|
|
|
|
|
- Please take a look at the two macros:
#define DEBUG(x) cout<<#x"="<
|
|
|
|
|
# and ## are preprocessor commands. #x results in the substitution "x" while x##y results in xy .
DEBUG(var) becomes cout<<"var""="<<var<<endl;
FIELD(MyField) becomes char* MyField_string; int MyField_size
And if you're wondering what happens to "var" "=" , the preprocessor concatentates adjacent string literals, so that becomes "var=" .
--Mike--
http://home.inreach.com/mdunn/
"....." -- Silent Bob
your with and
|
|
|
|
|
Thanks Mike pal!
- I still have a question. Do you mean x##y results in a single identifier?
- Can you help?
- Have a nice day?
Thanks,
Maer
|
|
|
|
|
|
I have two dialogs.
I the main dialog which is shown when the app is starting, I write this in the OnInitDialog():
CSecondDialog dlg; // this is the other dialog!
dlg.m_checkbox.SetCheck(1); // m_checkbox is a simple Check Box control, I puted it on the dialog with drag-and-drop
The program crashes and the debuger shows this
_AFXWIN_INLINE void CButton::SetCheck(int nCheck)
{ ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, BM_SETCHECK, nCheck, 0); }
Is there any options for the Check box that isn't avaible?
or....
|
|
|
|
|
It is failing because the checkbox hasn't been created yet, the check box won't be created until the InitDialog function of CSecondDialog has been completed.
The easiest solution would be to create a BOOL flag for the checkbox, set that and then inside the CSecondDialog::InitDialog do the SetCheck code. Either that or use the built in DDX functionality of CDialog.
Michael
|
|
|
|
|
Well , I successed to create my first ATL and it is works.
But the problem that remains is that I dont success to use full at the controls of the ATL Dialog. [ATL object][Miscellaneous][Dialog]
the code line's :
--------------------------------------------
CEdit* pText = (CEdit*)GetDlgItem(IDC_EDIT1);
pText->SetWindowText("Hello! ");
pText->UpdateWindow();
-------------------------------------------
or:
--------------------------------------------
CStatic* image = (CStatic*)GetDlgItem(IDC_PICTURE);
image->......
.....
----------------------------------------
cause to crush the program in run time.
How can I use at the controls correctly ?
|
|
|
|