|
i m trying to understand ur problem. if i m correct, u want to disble some submenu item on some event occuring. ur code seems to be perfectly OK. i guess u can remove the statement
DrawMenuBar();
i hope it will work. as it works in my application
|
|
|
|
|
Yes, i want to disable the submenu item on some event and enable it on some other event. However the code does not work with or without DrawMenuBar(); The menu does not get affected at all.
Should I do something with the UPDATE_COMMAND_UI?
|
|
|
|
|
Maybe something like this:
//add event handler to menu item.
void PbmFlexListViewer::OnUpdateYourMenuItem(CCmdUI *pCmdUI){<br />
pCmdUI->Enable(bEnable);<br />
}
good luck!
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
Could not make it grayed, but is disabled right now.
I use this code and threw away the preivous things!
settingsF_Enable = TRUE;<br />
<br />
settingsF_Enable = TRUE;<br />
<br />
void MyDlg::OnUpdateSettingsF(CCmdUI* pCmdUI) <br />
{<br />
pCmdUI->Enable(settingsF_Enable);<br />
}
I hope somebody could tell me how to make it gray.
There must be something to be added in the OnUpdateSettingsF() function, but I couldn't find how to call the pointer to the menu item and call EnableMenuItem() with MF_GRAYED
|
|
|
|
|
i have created a status bar in my dialog based application.
the code is below:-
#define IDC_STATUSBAR 32000 //resource id
CStatusBarCtrl m_StatBar;
BOOL m_bStatOK = m_bStatBar.Create(WS_CHILD | WS_BORDER | WS_VISIBLE, rect, this, IDC_STATUSBAR);
m_StatBar.SetText("Application Running",0,0);
The program is running fine. the text is shoen on the left hand side of the status bar. Now i want to display another text on the right hand side of the statusbar. how do i do? i tried by inserting the statement
m_StatBar.SetText("Time",255,0);
But it had no impact?
how do i proceed?
|
|
|
|
|
I want to change the position of mouse on an internet explorer window.I have tried the code below.The problem is that hr = pDoc4->createEventObject(NULL,&pEvtObj) fails.Because of this failure there is no point proceeding with the remaining code.Can you tell me the reason for this failure.Thanks in advance.
//For changing mouse position
IHTMLEventObj *pEvtObj = NULL;
IHTMLDocument4 *pDoc4 = NULL;
hr = m_pHTMLDoc->QueryInterface(IID_IHTMLDocument4,(void**)&pDoc4);//m_pHTMLDoc is a valid document pointer
if(SUCCEEDED(hr))
{
// VARIANT vEvt;
// VariantInit(&vEvt);
// vEvt.vt = VT_DISPATCH;
// vEvt.pdispVal = NULL;
hr = pDoc4->createEventObject(NULL,&pEvtObj);
if(SUCCEEDED(hr))
{
CComQIPtr<ihtmleventobj2, &iid_ihtmleventobj2=""> pEvtObj2;
pEvtObj2 = pEvtObj
Xpos = 100;
Ypos = 200;
g_Ypos = g_lastYpos = Ypos;
hr = pEvtObj2->put_clientX(Xpos);
if(hr == 0)
{
AfxMessageBox("put_clientX successful");
}
else
{
AfxMessageBox("put_clientX failed");
}
hr = pEvtObj2->put_clientY(Ypos);
// }
// pEvtObj->Release();
}
pDoc4->Release();
}
|
|
|
|
|
I need and algorithm or a sample code to compare two lines on word basis and show added/deleted/changed words within lines during comparison.
Any suggestion would be appreciated.
Thanks
|
|
|
|
|
Hello, I don't know if this is super-easy to accomplish,
I am pretty new to VC++/MFC..
I need to create a dialog which must contain a different number
of CButton controls depending on certain state parameters of the
application. So I need to dynamically create a number of those
controls and attach a message handler for them ( they all share
the same message handler code ).
How do I attach this listener function to the controls once
I've created them?
(I destroy all buttons and create a bunch of new ones when the layout changes)
thankful for any help.
|
|
|
|
|
Why dont you enable/disable or show/hide the controls at runtime, it is also better by UI Design-Guidelines.
-> Make a full dialog with all resources in the resource editor, assign control objects to all controls and work with mycontrol.EnableWindow( bActiveNow )
Try this @ home. (B&B)
|
|
|
|
|
I've thought of that as well.
But I really don't have a clue as of what the maximum number of controls is. I could of
course create a ridiculously large amount of CButton objects to be on the safe side, and just
hide/show those. But it sounds a bit unneccessary to me...
And I'm still very much interested in attaching a message handler dynamically. Can I for example
create a hook and install it for every new item? And in that hook listen for the BN_CLICKED event
and if one is received obtain the text for the control and pass it further on?
If so, how is a hook procedure attached?
|
|
|
|
|
Hello, I don't know if this is super-easy to accomplish,
I am pretty new to VC++/MFC..
I need to create a dialog which must contain a different number
of CButton controls depending on certain state parameters of the
applications. So I need to dynamically create a number of those
controls and attach a message handler for them ( they all share
the same message handler code ).
How do I attach this listener function to the controls once
I've created them?
(I destroy all buttons and create a bunch of new ones when the layout changes)
thankful for any help.
|
|
|
|
|
Hello,
Can a GDI object be created once (say when the class is constructed) and be used as many times as the programmer is pleased?
Example:
Class::Class()
{
myPen = CPen(....);
}
void Class::DrawThis()
{
pDC = new CDC();
pDC -> Attach(GetDC() -> GetSafeHdc());
pDC -> SelectObject(&myPen);
}
Is this valid and recommended?
dNimrod#X
________________________
|
|
|
|
|
Yes, but I don't recommend it because it can be hard(er) to maintain code that shares GDI objects. The only time I'd keep a GDI object around for the lifetime of my app is when it's very expensive to create one on the fly.
One other thing - DrawThis() should unselect myPen when it's done using it. For example:
void Class::DrawThis()
{
CPen* pOldPen = pDC->SelectObject (&myPen);
...
pDC->SelectObject (pOldPen);
} /ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I disagree with Ravi, if you are going to use a GDI object a lot, I say create it once and just keep using it. The exception is device contexts (CDC and related classes) - DCs are a shared and scarce system resource, and CDC s should exist for only as long as you need them.
Your sample code is wrong, however, in the way it's using CDC . You need to match GetDC() and ReleaseDC() calls, as well as select the pen out of the DC before releasing it.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
#include "witty-quote.h"
|
|
|
|
|
|
I have been trying to create a tokeninzer/scanner for my school project. But I have a hard time dealing with spaces between words. rather than it would separates the words after spaces, it will keep on adding the characters to one big word. If I inputed "print codes", it will make the variables as one 'printcodes' rather than "print" as one keyword and "codes" as identifier.
Could anyone help me solve this problem?
Here is the c++ codes I created:
while(!read.eof()) //(read>>letter)
{
//catching symbols
if(letter == '*'||'/'||'+'||'-'||'='||'('||')') {
checkid.checktokenop(letter); }
char gotit2 = letter;
//catching letters
if(gotit2 != '*')
if(gotit2 != '/')
if(gotit2 != '+')
if(gotit2 != '-')
if(gotit2 != '=')
if(gotit2 != '(')
if(gotit2 != ')')
{
int result = 1;
codes+= gotit2;
if(gotit2 == ' ')
{
result = checkid.checktokenword(codes);
codes.erase();
}
if(result == 0)//if Reserved word and,or,print,not
{
codes.erase();
}
}//end of catching letter
}
Please help!!!
|
|
|
|
|
|
Hello,
How does one do about disabling/enabling a menu and toolbar item that share the same ID?
Thanks a million,
David
|
|
|
|
|
Hi,
You can to obtain it adds an event to UPDATE_COMMAND_UI message, associated to this ID, with ClassWizard.
<br />
void CMainFrame::OnYourEvent(CCmdUI* pCmdUI) <br />
{<br />
pCmdUI->Enable(m_bFlag);<br />
}<br />
the m_bFlag is a bool variable to manage the enabing/disabling.
Ivan Cachicatari
www.latindevelopers.com
|
|
|
|
|
Hi, thanks for the reply!
Can you tell me how to enable/disable an item without having to wait for the event to fire?
I mean, what is the way to do it manually?
|
|
|
|
|
dNimrod#X wrote:
without having to wait for the event to fire?
The event is sent during the app's idle processing. You don't have to do anything special - just set the appropriate bool variable to false and query it in the UI update handler. Try it - you'll like it!
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hi there,
I have this application which opens different modeless dialog boxes and has some accelerators defined.
My question is assuming a window/control/... has the focus at the time, how can the C[...]App know the user pressed a key? Basically, what I am trying to do is make the app process certain accelerators, independently of the window that has the focus.
|
|
|
|
|
The easiest way is to use a "hot key". See RegisterHotKey .
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
My purpose is to pass an icon to the resource of a file or dll. If you have any sugestions..
for that I have to use UpdateResource
so I did that
hUpdateRes = BeginUpdateResource("D:\\Bureau\\ressource\\test resource\\test resource.exe", FALSE); <br />
if (hUpdateRes == NULL) <br />
{ <br />
MessageBox(0,"Could not open file for writing.",0,0); <br />
} <br />
<br />
result = UpdateResource(hUpdateRes,RT_ICON,szTitre,MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),ico,1384);
if (result == FALSE) <br />
{ <br />
MessageBox(0,"Could not add resource.",0,0); <br />
} <br />
<br />
<br />
if (!EndUpdateResource(hUpdateRes, FALSE)) <br />
{ <br />
MessageBox(0,"Could not write changes to file.",0,0); <br />
}
1384 reprsente the exact size of the ico, I will chage it with sizeof or somethingelse
my problem is ico
acording to msdn ico, so the LPVOID lpData must be in "raw binary data" and the "text must be in Unicode format"
so I try that
char* ico;<br />
wchar_t *wchar=(wchar_t *)malloc( sizeof( wchar_t ) );<br />
<br />
_setmode( _fileno( stdin ), _O_BINARY ); <br />
FILE* file=fopen(szFile,"rb");<br />
FILE* filedest=fopen("dest.ico","w");<br />
fpos_t pos;<br />
if(fseek(file, 0,SEEK_END)!=0)MessageBox(0,"fseek erreur",0,0);<br />
else<br />
{<br />
if( fgetpos( file, &pos ) == 0 )<br />
{<br />
<br />
ico=(char*) malloc((size_t)pos);<br />
fseek(file, 0,SEEK_SET);<br />
fread(ico, sizeof( char ), (int)pos, file );<br />
mbtowc( wchar ,ico,MB_CUR_MAX );<br />
}<br />
}<br />
fclose(file);<br />
fclose(filedest);
I'm not sure about the mbtowc, ...
If have no clue to pass ico in "raw binary data and in Unicode format"
Pleazeeeeeeee help me!!
|
|
|
|
|
If the "lpType" parameter is a string resource, it must be in UNICODE format. That is what MSDN says.
But since your "lpType" is RT_ICON, you do not need to do anything, since a icon contains no text, just binary data.
But if you wanted to update a resource type of RT_STRING for example, *that* string(pointed to by lpData) would need to be made into UNICODE.
Bikram Singh
|
|
|
|