|
There just isn't enough information there. It looks like it should work, but there could be 100000 other things going on.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
in the second approach r u still creating it/them pImageDisplay->Create(IDD_IMAGEDISPLAY, this);
?
-pete
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
Yes, I create them. push_back them in one function. then, retrieve them in another function..
Another thing....I'm trying to figure out by putting in breakpoints the sequence of events. Basically I'm going to restore the Cdialogs spawned by my view using the registry. Each CDialog has a magnification member . So if the registry says there were cdialogs spawned last time, I create the cdialogs in initial update after seeing how many there were the last time it ran. Then I call another function so I dont clutter things, and in that I was going along looping and assigning the magnification saved in the regsitry to the dialogs via pointers from the vector. Finally i did showwindow on them (in this separate fuunction).
The way it looks now is that I'll have to quiz my registry for the magnification info in a function which I had wanted to dedicate only to create the CDialogsvector. ....
But I'll look some more into it befoore I spaghettify things....
Thanks everyone!
|
|
|
|
|
I have a Single Doc app. I the apps InitInstance, the program does several things, one is finding out how to configure the menus and configuring them. The top level ones work fine, File, Edit, Help - i can gray them out and enable them if I wish. But the submenues blow up the program when they go to open. I'll move to a disabled item, and click it (nothign happens of course) I move to a non-disabled one (but one who'se contents I've modified) and I get an assert. I don't have any numm handles or pointers though.
Also I am having a problem updating the screen. I can all RedrawWindow wit the RDW_FRAME flag and the menu looks corrcectly, but it erases everything in my Doc view!
Many thanks in advance!
|
|
|
|
|
It sounds like a problem of managment of graphic objects, as fonts, brushs or pens.
The first rule with these objects is to always release them before destroying the device context using these objects
I suppose its located in your view. When you open a submenu, it hides a small part of the view, which is redrawn when the submenu is closed.
Where is the assert?
Angels banished from heaven have no choice but to become demons
Cowboy Bebop
|
|
|
|
|
Ok, here is the line I am using in my CWinApp derived app, in the InitInstance, (AFTER the CSingleDocTemplate has loaded specifying the menu (IDR_MAINFRAME) AND after Show() has been called)
[ccode]
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CWinAppDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CWinAppView));
AddDocTemplate(pDocTemplate);
... code to determine that some menu items are to be disabled ...
m_pMainWnd->GetMenu()->GetSubMenu(0)->EnableMenuItem(i, MF_BYPOSITION|MF_GRAYED);
[/ccode]
That line 'works', but when I try to exand SubMenu 0 ('File') it blows up here:
[ccode]
_AFXWIN_INLINE UINT CMenu::GetMenuItemCount() const
{ ASSERT(::IsMenu(m_hMenu)); return ::GetMenuItemCount(m_hMenu); }
[/ccode]
Which is being called from: CFrameWnd::OnInitMenuPopup(CMenu * 0x00bf6b80 {CTempMenu}, unsigned int 0, int 0)
I think it's because the menu hasn't been init'ed but the calls to modify the menu don't fail.
|
|
|
|
|
Ok, I thin I've understood. It's not the good way to set menu item sensitivity. MFC framework uses another system, the "OnUpdateUI" mechanism.
Basically:
In the MainFrame (or View, as you wish) message map, add
ON_UPDATE_COMMAND_UI(ID_MYMENUCOMMAND, OnUpdateMyMenu)
Next, add the method
void CMainFrame::OnUpdateMyMenu(CCmdUI* pCmdUI)<br />
{<br />
pCmdUI->Enable(FALSE);
}
It's possible to do this using the ClassWizard.
You may find useful info on this mechanism on
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_ccmdui.asp
HTH,
K.
Angels banished from heaven have no choice but to become demons
Cowboy Bebop
|
|
|
|
|
Thank you...
But so you're saying for each one [menu item] I have to create an entry and write a function?
Wow.
Thanks again.
|
|
|
|
|
There is a possibility to affect a method to a range of Ids, using the macro ON_UPDATE_COMMAND_UI_RANGE
(also, by default, menu items which have an associated command are enabled, menu items without command are disabled)
But mainly, yes, you have to. However, classWizard makes the task easier.
Angels banished from heaven have no choice but to become demons
Cowboy Bebop
|
|
|
|
|
hi,
i get this same error.
And i have done
ON_UPDATE_COMMAND_UI(ID_MYMENUCOMMAND, OnUpdateMyMenu)<br />
(and)<br />
void CMainFrame::OnUpdateMyMenu(CCmdUI* pCmdUI)<br />
{<br />
pCmdUI->Enable(FALSE);
}<br /> for one of my submenu's (with handler for the commands of all menuitems) which gets executed.
However, i still get this error.
ps: when doing e.g. GetMenuItemCount() it works; but after doing myMenu.Detach(); it doesn't work anymore (like in the assert error on GetMenuItemCount as stated by Anonymous)
|
|
|
|
|
|
i read it and i think i understand the updating of the menuitems.
But i am still having my assert error..
?
|
|
|
|
|
I want to create some 'Global' flag (expalantion...):
Iv'e tried the kernel sync objs but I can't query it with 'IsLocked' kind of functions (no such???)
They must support naming, have boolean behaviour - means that they can be queried and set with true/false values (or 'valid addrr'/'NULL'), must be accessable from any process/thread, mustn't be physicals (like files).
Is there someone with an answer or am I going CRaZzZzY?!?!?!
Thanks gals...
--BlackSmith--
/*The roof is on fire, we don't need no water, let the MF burn*/. BHG.
|
|
|
|
|
can u specify why/how the mutex does not solve ur problem?
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
I don't need any kind of a waitable lock. On a mutex I can't ask 'IsLocked' and get an ansewer right away without waiting. I only want a 'flag' that I can 'set and get' ( True/False ) from any process/thread ( Naming is required for locating it of course ).
This comes any clearer? damn I hope so...
--BlackSmith--
/*The roof is on fire, we don't need no water, let the MF burn*/. BHG.
|
|
|
|
|
>> This comes any clearer?
no i'm afraid not.
>> I don't need any kind of a waitable lock
it sounds like u do from ur description:
>> I only want a 'flag' that I can 'set and get' ( True/False )
also
>> On a mutex I can't ask 'IsLocked' and get an ansewer right away without waiting.
not true
if( WAIT_TIMEOUT == WaitForSingleObject( mymutex, 0))
// it's not signaled
else
// it's signaled
-pete
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
Indeed, some kernel objects can be queried using WaitForSingleObject (events, semaphores, mutexes ...). Here's a sample that I didn't bother to build or test, but it should be pretty close to what you need:
class CSharableObject
{
public:
CSharableObject( const TCHAR * p_pszName ) :
c_hMutex( NULL )
{
c_hMutex = OpenMutex( SYNCHRONIZE, FALSE, p_pszName );
if( c_hMutex == NULL )
{
c_hMutex = CreateMutex( NULL, FALSE, p_pszName );
if( c_hMutex == NULL )
{
}
}
}
~CSharableObject()
{
if( c_hMutex != NULL )
{
CloseHandle( c_hMutex );
c_hMutex = NULL;
}
}
bool IsLocked()
{
DWORD a_dwReason = WaitForSingleObject( c_hMutex, 0 );
if( a_dwReason == WAIT_TIMEOUT )
return true;
return false;
}
unsigned long Lock( unsigned long p_ulTimeout = INFINITE )
{
return WaitForSingleObject( c_hMutex, p_ulTimeout );
}
bool Unlock()
{
return ReleaseMutex( c_hMutex ) != 0;
}
protected:
HANDLE c_hMutex;
};
Now, whereever you need to use the shared resource:
CSharableObject a_oLocker( _T("SomeUniqueName") );
a_oLocker.Lock();
a_oLocker.Unlock();
if( !a_oLocker.IsLocked() )
{
}
else
{
}
It would be a good idea to make this more robust etc, but it's a start.
Chris Richardson
C/C++ Include Finder[^]
|
|
|
|
|
Is there a way to add a menu to a dialog based application? I could start over again with a Single Document design, but if there's a relatively simple way to add a menu to my existing dialog based app, it would be the least painful for me.
Thanks.
|
|
|
|
|
|
That was easy!
Thanks
|
|
|
|
|
I am working with the VC++ 7 build-in CImage class.
there is a
CImage::SetTransparentColor(int nIndex);
but if i use
m_bmpMyBitmap.SetTransparency(0); /* which should set color 0 in palette transperent */
m_bmpMyBitmap.Save(dlg.GetPathName(), GUID_NULL);
and save it to gif or png the color is not transperent
|
|
|
|
|
What is the most reliable way to convert a float variable to a double variable?
The reason I ask is this:
float fData=2.7;<br />
double dData=fData;
After the above operation dData is: 2.7000000476837158
not 2.7
I know this is probably due to some problem with .7 being represented accurately in binary. How do I ensure that 2.7 float = 2.7 double without resorting to string based conversions and truncating etc?
|
|
|
|
|
there is no easy way to do this, since both float and double are approximations.
i believe the best you can do is to do the float->double cast, then choose an arbitrary precision (say 6 decimal places) and round up or down.
-c
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
|
|
|
|
|
Hi Chris, yes that would be perfect (2 decimal places actually). Is there a function that will round a float in any of the libraries that you know of? (reason I ask is that I can't seem to find anything applicable)
|
|
|
|
|
i'd start with this:
int scale = 1000;
f*=scale;
if(f>0)
f+=0.5;
else
f-=0.5;
double d =(double)(((double)(int)f) / scale);
-c
Be very, very careful what you put into that head, because you will never, ever get it out. --Thomas Cardinal Wolsey
|
|
|
|