|
Hello
Sure I can inherit from anything, but unfortunately it doesn't seem to help: taking CEdit as base class still doesn't make the static get the keyboard focus... Annoying!
I've found a workaround: instead of creating the control in a static, I create it in an EDITTEXT ... so, it does capture the keyboard when clicked, but has the normal behaviour of an edit text: it changes the cursor into a "I", it blinks, it has a border and worse it types in text when you press buttons!
Do you have any other ideas?
Thank you
S. Ali Tokmen
http://ali.tokmen.com/
|
|
|
|
|
Derive your class directly from Cwnd. That will give you the most flexibility.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
alitokmen wrote: 've found a workaround: instead of creating the control in a static, I create it in an EDITTEXT ... so, it does capture the keyboard when clicked, but has the normal behaviour of an edit text: it changes the cursor into a "I", it blinks, it has a border and worse it types in text when you press buttons!
Subclass it!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
alitokmen wrote: This is a direct email response to your message on the page 'Visual C++ / MFC':
This message has not appeared on the discussion board for that page.
DO NOT HIT 'REPLY' TO THIS EMAIL: To reply, visit the URL below or
send an email to the email address below.
URL : http://www.codeproject.com/script/comments/forums.asp?msg=1572159&forumid=1647#xx1572159xx
From: alitokmen <#######################>
Hello
I'm poting you this message and sure you don't need to reply or help me, I would just be glad if you can
As I told in the forum post, my aim is to develop an MFC-based object which would act like, for instance, CHtmlView: on the programmer side, the only action that would need to be done would be to call CMyClass::Create(dwStyle, rect, parentDialog, staticCtrlID) and this would create the control, in any kind of control (static text, edit box, ...). Also, the control would take over the default keyboard and mouse actions on the dialog and therefore, for example, clicking on the class "window" and then pressing the arrow buttons on the keyboard would only make the class take an action.
This is the point where I'm stuck: how can I make this class get created on any kind of static control and second (more importantly) how do I make it capture all actions once clicked on (and release it back once the user clicks somewhere else)?
Thank you
S. Ali Tokmen
http://ali.tokmen.com
---------------------------------------------------------------
NOTE: This message has been sent from an unattended email box.
Daily news delivered: The Code Project Insider
Sign up at http://www.codeproject.com/Redir.aspx?id=1648
alitokmen wrote: This is a direct email response to your message on the page 'Visual C++ / MFC':
This message has not appeared on the discussion board for that page.
DO NOT HIT 'REPLY' TO THIS EMAIL: To reply, visit the URL below or
send an email to the email address below.
URL : http://www.codeproject.com/script/comments/forums.asp?msg=1572159&forumid=1647#xx1572159xx
From: alitokmen <#######################>
Hello
It's just to tell you that I've solved the issue... Here's how it goes:
Problem: when there's a control in a dialog box replacing a STATIC resource, it will lose focus as soon as a key is pressed (things move in the dialog box) and it will never receive the OnKeyDown call.
Reason: STATIC is not supposed to be doing input/output, as a result it cannot receive keyboard events. As a result, you won't receive the OnKeyDown call (even if you do put it in the message map) and any pressed key, since not captured by the STATIC, will get dispatched to the parent (the dialog box) and this will make it take the default action -changing the selected button.
Solution: in the class that wants to go into a STATIC, overload the PreTranslateMessage, OnLButtonDown and OnRButtonDown methods (you also need to specify the mouse actions in the message map). PreTranslateMessage shall check if( pMsg->message == WM_KEYDOWN ), and in this case call OnKeyDown followed by CWnd::PreTranslateMessage and return TRUE (so the message doesn't get dispatched). If not, it shall return whatever CWnd::PreTranslateMessage returns. In the mouse handling methods, call SetFocus to get the focus when clicked.
New problem: the call you do to OnKeyDown is ignored (in classes that inherit from our base class, at least).
Reason: Don't know why...
Solution: Create a new virtual OnKeyDown method which would have a different signature from the original method (for example, one that only takes the nChar argument) and call that one. Now, put the key handling stuff in that new OnKeyDown method.
The solution therefore doesn't require you to overload CDialog::PreTranslateMessage or do other things like that. Note that the modification done to PreTranslateMessage is also very small, which makes that the overall behaviour of the control as well as the dialog box remains the same...
S. Ali Tokmen
http://ali.tokmen.com
---------------------------------------------------------------
NOTE: This message has been sent from an unattended email box.
Daily news delivered: The Code Project Insider
Sign up at http://www.codeproject.com/Redir.aspx?id=1648
Why are you sending this to my personal in box. How does doing that help anyone? Please keep all messages in this forum so that others with the same problem can learn from it.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Hello
I had sent you as an e-mail as well since I had sent a message saying "please help me" ... to say that you don't need to help anymore
Sorry for the noise
Cheers
S. Ali Tokmen
http://ali.tokmen.com/
|
|
|
|
|
OK, I've solved the issue... Here's how it goes:
Problem: when there's a control in a dialog box replacing a STATIC resource, it will lose focus as soon as a key is pressed (things move in the dialog box) and it will never receive the OnKeyDown call.
Reason: STATIC is not supposed to be doing input/output, as a result it cannot receive keyboard events. As a result, you won't receive the OnKeyDown call (even if you do put it in the message map) and any pressed key, since not captured by the STATIC, will get dispatched to the parent (the dialog box) and this will make it take the default action -changing the selected button.
Solution: in the class that wants to go into a STATIC, overload the PreTranslateMessage, OnLButtonDown and OnRButtonDown methods (you also need to specify the mouse actions in the message map). PreTranslateMessage shall check if( pMsg->message == WM_KEYDOWN ), and in this case call OnKeyDown followed by CWnd::PreTranslateMessage and return TRUE (so the message doesn't get dispatched). If not, it shall return whatever CWnd::PreTranslateMessage returns. In the mouse handling methods, call SetFocus to get the focus when clicked.
New problem: the call you do to OnKeyDown is ignored (in classes that inherit from our base class, at least).
Reason: Don't know why...
Solution: Create a new virtual OnKeyDown method which would have a different signature from the original method (for example, one that only takes the nChar argument) and call that one. Now, put the key handling stuff in that new OnKeyDown method.
The solution therefore doesn't require you to overload CDialog::PreTranslateMessage or do other things like that. Note that the modification done to PreTranslateMessage is also very small, which makes that the overall behaviour of the control as well as the dialog box remains the same...
S. Ali Tokmen
http://ali.tokmen.com
|
|
|
|
|
Hi all, I'm currently performing the following sequence of actions:
- My prog creates a directory
- It opens an OLE link to an external program, which creates files in that directory
- the OLE link releases the dispatch driver
- The external program may quit
- My prog deletes the files from the directory
At this point, my prog tries to delete the directory, but it fails with the error message that another process is still using the directory.
Any ideas, please?
Cheers,
Steve.
Asynes yw brassa ages kwilkynyow.
|
|
|
|
|
Hi all.
I am using MFC, and I want to display a bitmap on a button. I created the resource and it appeared in the bitmap resources as IDB_BITMAP1. Now I added a button named m_opaque and added the followin code to the OnPaint function:
void HelloDlg::OnPaint()<br />
{<br />
if (IsIconic())<br />
{<br />
CPaintDC dc(this);
<br />
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);<br />
<br />
int cxIcon = GetSystemMetrics(SM_CXICON);<br />
int cyIcon = GetSystemMetrics(SM_CYICON);<br />
CRect rect;<br />
GetClientRect(&rect);<br />
int x = (rect.Width() - cxIcon + 1) / 2;<br />
int y = (rect.Height() - cyIcon + 1) / 2;<br />
<br />
dc.DrawIcon(x, y, m_hIcon);<br />
m_opaque.ModifyStyle(0, WS_CHILD|WS_VISIBLE|BS_BITMAP);<br />
m_opaque.SetBitmap( ::LoadBitmap(NULL, MAKEINTRESOURCE(IDB_BITMAP1)) );<br />
}<br />
else<br />
{<br />
CDialog::OnPaint();<br />
}<br />
}<br />
The code compiles but the image doesnt appear. what is the reason?
-- modified at 11:27 Tuesday 11th July, 2006
|
|
|
|
|
safigh wrote: if (IsIconic())
You are painting only when the window is minimized!
Also setting the bitmap is not a "painting" function. That should be done during initialization not painting.
Last modified: Tuesday, July 11, 2006 10:26:23 AM --
|
|
|
|
|
Adding these two line to the init dialog also doesnt show the picture????
m_opaque.ModifyStyle(0, WS_CHILD|WS_VISIBLE|BS_BITMAP);
m_opaque.SetBitmap( ::LoadBitmap(NULL, MAKEINTRESOURCE(IDB_BITMAP1)) );
|
|
|
|
|
You are painting in the OnPaint message of the dialog when the dialog is minimized.
If you want to draw the bitmap on a button that is child control of the dialog, you are not painting at the right place.
To draw a bitmap on a button, you can use the CBitmapButton class.
Louis
* google is your friend *
|
|
|
|
|
See here.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi all. could any one tell me how i can add webbrowser controle to my visual c++ 6 MFC project? I already have project made byMFC AppWizard which has a few conroles such as buttons an textbox/editbox and i want to add to it a webbrowser controle.Thanks
|
|
|
|
|
Examples exist on MSDN and likely here on CodeProject as well. Did you search at all?
http://www.codeproject.com/cpp/htmleditvc6.asp[^]
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
man i am using MFC with dialog and just want to display a webpage in part of a form. But that example never talkes bout url!!
All i want to dispaly a site such www.cnn.com inside the form just like visual basic webbrowser controle.
|
|
|
|
|
method007 wrote: But that example never talkes bout url!!
Then do a freakin search and find one that does, there are hundereds of them including on the MSDN site!
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
If u do not want to help some one do not try to flame. i am new to visual c++ world so if u do not want to help just do not reply!! very simple. do not think every one is in same level!!
|
|
|
|
|
method007 wrote: do not think every one is in same level!!
Same level? Can't you read? The Sample/Example code you ask for is free for the "reading" on MSDN like I told you three times now. Telling you where you can find what you asked for is not a "flame". If you really want to be flamed just let me know.
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
Have you considered the WebBrowser Control (shdocvw.dll)?
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I just want to load a URL inside my application just like visual basic 6 and i do not know how. I am looking for easy way . could u tell me how to use
shdocvw.dll ?Thanks
|
|
|
|
|
method007 wrote: could u tell me how to use
shdocvw.dll ?
Project --> Add To Project --> Components and Controls.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
could u tell me what is the controle path for it ? furthermore , how to load the url using this method?
|
|
|
|
|
method007 wrote: furthermore , how to load the url using this method?
Use either the Navigate() or Navigate2() method.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
but how to know the path of controle and what should i do with navaigate? it seems like this is lunching a rocket to space processs!!!
|
|
|
|
|
method007 wrote: but how to know the path of controle...
Most, but not all, reside in the \Windows\System32 folder. However, there's rarely a need to know such information. Once a control has been registered with the OS, its path is mostly irrelevant.
method007 wrote: ...what should i do with navaigate?
Pass it a URL.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|