|
I have an activex(simple custom edit) that i place on a dialog. If i call SetWindowPos or MoveWindow of CWnd, the control is moved ok. But if i use SetWindowPos or MoveWindow of the SDK (like ::MoveWindow) the activex is moved in the right position, but after it gains focus it automaticly changes coords to the initial position.
I have tested this with various Activex, even the Microsoft ones. They all behave like this. But i have another activex (i don t have the source code for that ) that behaves correctly.(even if i call ::Movewindow and click on the control it won't go to the initial position).
In short : I have to make my activex not to move back to the initial position on focus gain (after i call ::Move window for ex.)
Thx. in advance.
|
|
|
|
|
I have to manage a part of my user interface (dialogs) in a separate thread.
I've created a CWinThread derived class and I've tryed to show a dialog
in the PreTranslateMessage method but when I close the dialog an
exception is fired.
This is my PreTranslateMessage:
BOOL CTest1Thread::PreTranslateMessage(MSG* pMsg) <br />
{<br />
switch(pMsg->message)<br />
{<br />
case WM_START:<br />
AfxMessageBox(_T("START EVENT"), MB_OK | MB_ICONEXCLAMATION);<br />
break;<br />
<br />
case WM_STOP:<br />
AfxMessageBox(_T("STOP EVENT"), MB_OK | MB_ICONEXCLAMATION);<br />
::PostQuitMessage(0);<br />
break;<br />
<br />
case WM_SHOW_CHILD:<br />
m_pDlgThreadChild = new CDlgThreadChild();<br />
m_pDlgThreadChild->DoModal();<br />
delete m_pDlgThreadChild;<br />
m_pDlgThreadChild = NULL;<br />
break;<br />
<br />
default:<br />
break;<br />
}<br />
<br />
return CWinThread::PreTranslateMessage(pMsg);<br />
}
The exception is fired in WINCORE.CPP at this point:
ASSERT(::IsWindow(m_hWnd));<br />
<br />
CHandleMap* pMap = afxMapHWND();<br />
ASSERT(pMap != NULL);<br />
<br />
CObject* p;<br />
ASSERT((p = pMap->LookupPermanent(m_hWnd)) != NULL ||<br />
(p = pMap->LookupTemporary(m_hWnd)) != NULL);<br />
ASSERT((CWnd*)p == this);
<br />
So... I've seen is not easy to manage dialogs in threads...
How can I do that ?
Thanks a lot !!!
|
|
|
|
|
You cannot share GUI elements across different threads, maybe your problem is coming from there. But why do you want to use another thread for that ? And why to manage that in the PreTranslateMessage function ?
|
|
|
|
|
My problem is the following:
a part of the user interface must be sinchronized with an external
interface, some dialogs must be shown when a message is received and must
be blocked until another message is received.
While this part of the user interface is running (pay attention.. it may be
blocked waiting for some events) the rest of the application have to do other
things and Windows messages must be processed. So I supposed to let a separate
thread to manage that part of the user interface in order to don't block
the main thread while waiting for external events.
Do you know what's a good way to solve this problem ?
|
|
|
|
|
It is difficult to help you because we don't know what are those two 'parts' of your app. Is that dialog boxes or what ?
Anyway, I think a better option is to start a thread that will only look for the specific message of the other interface (again, we don't know how they 'communicate' together). Then, when you need to lock a part of the GUI, you send a user define message to the GUI message loop. There, you can manage how the GUI needs to react and you can disable part of it. But again, I cannot help you more without knowing how you manage your GUI. Please post some more information.
|
|
|
|
|
Here I try to give you more information.
My application manages an Ethernet interface with 2 other applications.
It has to send periodic messages and to manage messages received through
Ethernet interfaces. Ethernet interfaces are multi-thread and talks with
the CMainFrame instance through Windows messages so Dialog boxes are
updated with received data when the CMainframe receives the Windows message
sent by Ethernet interfaces threads.
For a specific functionality of my software I have to show and hide some modal
windows when I receive specific Ethernet messages and my flow of operations
must be blocked waiting to next messages. Then I've to send some messages when
the user sets some data and closed the dialog boxes. As you can see, in this case,
the GUI and the Ethernet interface are synchronized in a unique flow of operations.
If it'd be possibile a thread would be the better way to implement this functionality
but I think it is not possible....
Maybe I should let a thread to manage the flow of operations (messages, events,
waits) and post messages to the main thread in order to let it show the dialog
boxes but I've also to use modless dialogs instead of modal dialogs.
|
|
|
|
|
Besides what Cedric said...
Writing code for each message in PreTranslateMessage is dirty. Have message handlers for each of the messages.
Nibu thomas
Software Developer
|
|
|
|
|
Thanks, I know.... the code you have seen is only a test application
written to try to solve my main problem!
|
|
|
|
|
ilgale wrote: solve my main problem
Well we would like to know your main problem. Be more clear. Just specify the main problem and what you want to achieve.
Someone here can suggest you a different solution or an enhanced one.
Nibu thomas
Software Developer
|
|
|
|
|
Here I try to give you more information.
My application manages an Ethernet interface with 2 other applications.
It has to send periodic messages and to manage messages received through
Ethernet interfaces. Ethernet interfaces are multi-thread and talks with
the CMainFrame instance through Windows messages so Dialog boxes are
updated with received data when the CMainframe receives the Windows message
sent by Ethernet interfaces threads.
For a specific functionality of my software I have to show and hide some modal
windows when I receive specific Ethernet messages and my flow of operations
must be blocked waiting to next messages. Then I've to send some messages when
the user sets some data and closed the dialog boxes. As you can see, in this case,
the GUI and the Ethernet interface are synchronized in a unique flow of operations.
If it'd be possibile a thread would be the better way to implement this functionality
but I think it is not possible....
Maybe I should let a thread to manage the flow of operations (messages, events,
waits) and post messages to the main thread in order to let it show the dialog
boxes but I've also to use modless dialogs instead of modal dialogs.
|
|
|
|
|
there is a button uses IDC_BTN1 on my dialog, I write it's OnClick() function like follow code:
CMyDialog::OnBtn1Click()
{
m_bState = !m_bState; // remember whether the
// button highlights;
m_btn1.SetState(m_bState); // set the button's state
}
there is another button uses IDC_BTN2 on my dialog, the problem is when I click m_btn2, if m_btn1 still highlights, the OnClick function of m_btn1 will be called. This is not what I want.
Someone may tell me how to prevent this from happenning again.
thanks a lot
|
|
|
|
|
And what happens if you press the second button without pressing the first button before ?
That is not logical that OnBtn1Click gets called only when the button1 is in another state. Are you absolutely sure that OnBtn1Click gets called (did you use your debugger to check if it was inside this function) ? Alos an easy way to check is to display two different message boxes in each of the handler.
|
|
|
|
|
I write this code in OnBtn1Click():
TRACE(".......state is %x........\n", m_btn1.GetState());
when I click the other buttons, if m_btn1 highlights, debugger will types".......state is 8........". And I just find, need not click the other buttons, if I switch to other application window, while m_btn1 highlights, debugger will type same message also.
It's strange.
|
|
|
|
|
Post the code of the message map of your dialog class (the part that starts with BEGIN_MESSAGE_MAP(CYourDialog, CDialog) and finishes with END_MESSAGE_MAP()
Post also the code for the OnBtn2Click handler function
|
|
|
|
|
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
ON_BN_CLICKED(IDC_BTN1, OnBtn1Click)
END_MESSAGE_MAP()
There is no code for m_btn2
I find something new, I am sure it because focus, when m_btn1 lost focus, if it hightlights, OnBtn1Click() is called. But I don't konw how to prevent it.
My code is very simple, you may create a dialog application and put 2 buttons on dialog, I think you will find the same thing.;)
|
|
|
|
|
What does the project's resource.h file look like? When was the last time you did a rebuild-all?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"We will be known forever by the tracks we leave." - Native American Proverb
|
|
|
|
|
Why are you calling m_btn1.SetState() ? If you're wanting a button that is alternately on and off, use a checkbox with the push button style. Windows will then take care of the button state automatically.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
sorry my friends, I use a checkbox now, but same thing happens again.
Q:when the checkbox lost focus, if it's on state, it will become off state. while I want it to keep its on state until I press it again.
help me!
|
|
|
|
|
Hi,I have some trouble!Please help me!
When I run command promt(cmd.exe),I can open a text file by typing,example : C:\>type Text.txt
Then, it will open the Text.txt in that command prompt window!
How can I do that in MFC Application!Example,When I press a button,it'll open command prompt!And then,the command prompt will automatic open the specified Text file!
Please,Help me!!!
|
|
|
|
|
Use ShellExecute to start the command prompt.
Pass the command as a command line argument to the command prompt with the switch /k turned on.
for eg:
cmd /k type help.txt
or
cmd /k dir
Nibu thomas
Software Developer
|
|
|
|
|
Ok!I got it!
Thank A lot !!!
|
|
|
|
|
Hi All,
Can anyone suggest me a way to record audio lively from microphone using DirectShow?
Thanks,
Poornima
|
|
|
|
|
|
I've been trying to learn a bit of MDI , but I'm failing everytime. Anybody has links where I can learn MDI with a simple Example? I want to learn SDI with Multiple views too. Any help?
NULL
|
|
|
|
|
Search CP with the keyword MDI and see what happens.
Nibu thomas
Software Developer
|
|
|
|