|
Check that your main window's class styles include CS_ HREDRAW|CS_VREDRAW . When you say you get no paint messages when making the window smaller, that's the normal behavior without those class styles - no portion of the client area is being revealed, so no painting is necessary.
|
|
|
|
|
Hi..
I've got a dialog window with horizontal and vertical scroll bars to move the window... That all works fine.. The only problem is I have some slider controlls inside the window that move it too.. and that isn't wanted..
I'm thinkin any time I move one of my slider objects.. it sends a message to OnHScroll(); or OnVScroll(); depending.
I only want the window scroll bars to send the message. Not the dialog slider objects
void CEdrumMonDlg::OnSize(UINT nType, int cx, int cy) //Creates the window scroll bars if the window size is changed
{
CDialog::OnSize(nType, cx, cy);
m_nCurHeight = cy;
m_nCurWidth = cx;
int nScrollMax;
int nScrollMax2;
if (cy < m_rect.Height())
{
nScrollMax = m_rect.Height() - cy;
}
else
nScrollMax = 0;
if (cx < m_rect.Width())
{
nScrollMax2 = m_rect.Width() - cx;
}
else
nScrollMax2 = 0;
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS;
si.nMin = 0;
si.nMax = nScrollMax;
si.nPage = si.nMax/10;
si.nPos = 0;
SetScrollInfo(SB_VERT, &si, TRUE);
SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
SCROLLINFO si2;
si2.cbSize = sizeof(SCROLLINFO);
si2.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS;
si2.nMin = 0;
si2.nMax = nScrollMax2;
si2.nPage = si2.nMax/10;
si2.nPos = 0;
SetScrollInfo(SB_HORZ, &si2, TRUE);
SetScrollPos(SB_HORZ, m_nScrollPos2,TRUE);
}
void CEdrumMonDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
int nDelta;
int nMaxPos = m_rect.Height() - m_nCurHeight;
switch (nSBCode)
{
case SB_LINEDOWN:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(nMaxPos/100,nMaxPos-m_nScrollPos);
break;
case SB_LINEUP:
if (m_nScrollPos <= 0)
return;
nDelta = -min(nMaxPos/100,m_nScrollPos);
break;
case SB_PAGEDOWN:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(nMaxPos/10,nMaxPos-m_nScrollPos);
break;
case SB_THUMBPOSITION:
nDelta = (int)nPos - m_nScrollPos;
break;
case SB_PAGEUP:
if (m_nScrollPos <= 0)
return;
nDelta = -min(nMaxPos/10,m_nScrollPos);
break;
default:
return;
}
m_nScrollPos += nDelta;
SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
ScrollWindow(0,-nDelta);
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CEdrumMonDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) //pretty much same as OnVScroll
|
|
|
|
|
I "think" pScrollBar is NULL if the message doesn't come from a scroll bar so maybe try
just returning from your OnHScroll/OnVScroll handlers if pScrollBar is NULL.
Mark
|
|
|
|
|
Awsome!
it's actually the other way around...
if(pScrollBar != NULL){return;}
Thanks again mark.
|
|
|
|
|
Hello,
i need your help again
so, i am trying to create invisible window with MFC i will post my source code then you should understand more easily what a f**k i am trying to do i know, i am doing something wrong hmm.. so the main question is how to create invisible window?
***HookApp.cpp***<br />
<pre>#include "stdafx.h"
#include "HookApp.h"
HookApp theApp;
void HookApp::FileWrite(char *data)
{
FILE *f;
errno_t err;
err = fopen_s(&f, "C:\\debug.txt", "a");
fprintf(f, data);
fflush(f);
fclose(f);
}
HookApp::HookApp()
{
FileWrite("Constructed\n");
}
HookApp::~HookApp()
{
FileWrite("Destructed\n");
}
BOOL HookApp::InitInstance()
{
FileWrite("Initialized\n");
MyWnd* pWnd;
pWnd = new MyWnd();
WaitForSingleObject(HookApp::m_hThread, 10000);
return false;
}</pre><br />
<code>***HookApp.h***<pre>class HookApp : public CWinApp
{
public:
HookApp();
virtual ~HookApp();
virtual BOOL InitInstance();
static void FileWrite(char *data);
};
class MyWnd : public CWnd
{
DECLARE_DYNAMIC(MyWnd)
public:
MyWnd();
virtual ~MyWnd();
afx_msg LRESULT OnMsg(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
};</pre><br />
<code>***MyWnd.cpp***<pre>#include "stdafx.h"
#include "HookApp.h"
#include "pKhook.h"
IMPLEMENT_DYNAMIC(MyWnd, CWnd)
LRESULT MyWnd::OnMsg(WPARAM wParam, LPARAM lParam)
{
HookApp::FileWrite("message\n");
return 0;
}
MyWnd::MyWnd()
{
HookApp::FileWrite("Invisible Window Constructed\n");
InstallKeyHook();
KEYENTRY m_entry;
m_entry.nMessage = WM_MY_EVENT;
m_entry.hCallWnd = m_hWnd;
m_entry.hHookWnd = 0;
m_entry.iCombKeys = 0;
m_entry.iIndicators = 0;
m_entry.iKeyEvent = 0;
m_entry.iMinVKCode = 0x00;
m_entry.iMaxVKCode = 0xff;
if(KH_OK == AddKeyEntry(&m_entry)) HookApp::FileWrite("KeyHook Init Done\n");
}
MyWnd::~MyWnd()
{
HookApp::FileWrite("Invisible Window Destructed\n");
}
BEGIN_MESSAGE_MAP(MyWnd, CWnd)
ON_MESSAGE(WM_MY_EVENT, OnMsg)
END_MESSAGE_MAP()</pre><br />
thanks for all of you in advance :)
|
|
|
|
|
edvintas wrote: so the main question is how to create invisible window?
My main question is "why" do you want an invisible window?
led mike
|
|
|
|
|
because i need to handle messages from *.dll which is using PostMessages method
|
|
|
|
|
edvintas wrote: so the main question is how to create invisible window?
Windex?
Here's one way. In your invisible window class add this override function
BOOL CMyInvisibleWindow::PreCreateWindow(CREATESTRUCT& cs)
{
CWnd::PreCreateWindow(cs);
cs.style &= ~WS_VISIBLE;
return TRUE;
}
|
|
|
|
|
edvintas wrote: ...how to create invisible window?
By removing the WS_VISIBLE style. There's also ShowWindow(SW_HIDE) .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
so this is a problem that i am not sure how to create window message handling with MFC and i am not sure whether i should use CWnd or somewhat other base class
could you give me a hint how what to do next after this:
MyWnd* pWnd;
pWnd = new MyWnd();
what method should i use?
|
|
|
|
|
edvintas wrote: i am not sure how to create window message handling with MFC
Well if you don't actually want a GUI window then don't use MFC message handling. Override WindowProc and handle your messages in there. Of course you still need to "create" the window as Chris points out.
led mike
|
|
|
|
|
You would also need to call the Create() method in order to get a window and message handling all set-up. The next problem you are going to have though, is that whatever DLL you are trying to get messages from will need to be linked into your process or your window will never see the messages. Are you trying to hook into any DLL that may be posting messages or is the DLL linked into your app and it is posting messages to you?
Chris Meech
I am Canadian. [heard in a local bar]
Nobody likes jerks. [espeir]
The zen of the soapbox is hard to attain...[Jörgen Sigvardsson]
I wish I could remember what it was like to only have a short term memory.[David Kentley]
|
|
|
|
|
|
edvintas wrote: i suppose i have found something useful here...
The CWnd Class[^] docs are useful for understanding CWnd creation/destruction as well.
|
|
|
|
|
Hi, everybody:
I encounter a very strange behaviour between a release mode and debug mode of the program.
I use application wizard to create a win32 application. then add a modeless dialog to control something of a view. I use message from the modeless dialog to communicate with the view. in debug version, everything is fine. For release version, the first message is fine, when the second message arrives, I use GetDocument() function to return m_pDocument of the view, i found m_pDocument is NULL????!!!!!
Anybody can give me a clue on this?
When I debug the release mode, I found the m_pDocument pointer is NULL, but could not identify where it was changed?
If possible, I can upload the source code, you cn look it up.
Thanks a lot!
|
|
|
|
|
how jack wrote: Anybody can give me a clue on this?
It means that the view is not attached to a document.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
David --- how does that not show up in Debug (the view is not attached to a document)?
To me that is one of the most frustrating elements of VC++ 6.0. If it works in Debug, it should, by default almost, work in Release mode. Can you shed any light on this 'anomaly'?
Thanks
John P.
|
|
|
|
|
Exactly how is the modeless dialog communicating with the view?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
jparken wrote: Can you shed any light on this 'anomaly'?
By far the most common cause of this, and it is not an anomaly or problem with the enviroment or C++, is misuse of assert.
led mike
|
|
|
|
|
Thanks, guys, for the responses.
John P.
|
|
|
|
|
What function in MFC will be called and discnnect the view from the document?
|
|
|
|
|
|
I have a console app that reads and writes from a virtual comport pair.
It works great when only one instance of the program is running. But when I execute another app that opens a different virtual comport pair, I get some strange errors. I have tried different (brand) virtual comport devices, resulting in the same effect.
Once I enter data on the comport for the second application to read, the first app will respond erroneously. The second app fails to perform as it should as well.
So my real question: Do console apps share memory space somehow? These are not threads but separate processes.
Any help is appreciated.
Thanks.
|
|
|
|
|
switang wrote: So my real question: Do console apps share memory space somehow? These are not threads but separate processes.
No, but the virtual com port might be doing so.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|