|
The handler is called multiple times for a single event with different parameters, and also upon specific device changes even when not registered. So you have to check always if the device type matches and cast then to the corresponding broadcast structure (because all structures have the common _DEV_BROADCAST_HDR | Microsoft Docs[^] header, casting can be done initially when checking for the matching type).
So your code should look like (based on your code snippet posted in the above sub thread):
const GUID CTesterDlg::GUID_DEVINTERFACE_FTDI_D2XX =
{ 0x219D0508, 0x57A8, 0x4FF5, { 0x97, 0xA1, 0xBD, 0x86, 0x58, 0x7C, 0x6C, 0x7E }};
BOOL CTesterDlg::OnDeviceChange(UINT nEventType, DWORD_PTR dwPtrData)
{
BOOL bReturn = CWnd::OnDeviceChange(nEventType, dwPtrData);
PDEV_BROADCAST_DEVICEINTERFACE b = reinterpret_cast<PDEV_BROADCAST_DEVICEINTERFACE>(dwPtrData);
if (b &&
b->dbcc_devicetype == DBT_DEVTYP_DEVICEINTERFACE &&
b->dbcc_classguid == GUID_DEVINTERFACE_FTDI_D2XX)
{
}
return bReturn;
} Regarding the encoding of the name, see _DEV_BROADCAST_DEVICEINTERFACE_A | Microsoft Docs[^]:
Quote: When this structure is returned to a window through the WM_DEVICECHANGE message, the dbcc_name string is converted to ANSI as appropriate. That means you will get an ANSI string with ANSI builds and a Unicode string with Unicode builds when having called RegisterDeviceNotification() .
Portions of the above (like the GUID) are from some testing code I have written in 2012 where I have logged the name using
App()->Log(TRACE_LOG_DEBUG,
_T("Device %s has been %s"),
pDev->dbcc_name,
nEventType == DBT_DEVICEARRIVAL ? _T("added") : _T("removed")); As far as I remember, the name was displayed properly .
|
|
|
|
|
All valid points, thank you. The note about device interface was good and got me on the right track. I was blind to that part as the code seemed to work and returned something. The problem seems to have been that I have registered to receive messages to my Hwnd from GUID_DEVCLASS_PORTS which is not an interface class, now I changed to GUID_DEVINTERFACE_USB_DEVICE and I get a proper string with VID & PID. Problem solved, thanks!
|
|
|
|
|
Fine to hear that the problem is solved.
If you don't need the VID and PID but just want to be informed of the plugin / -out for the virtual COM ports, there is even no need to register. Then just check for DBT_DEVTYP_PORT events. They are one of the always signaled events (as already mentioned):
PDEV_BROADCAST_PORT pPort = reinterpret_cast<PDEV_BROADCAST_PORT>(dwData);
if (pPort && DBT_DEVTYP_PORT == pPort->dbcp_devicetype)
{
}
|
|
|
|
|
Thanks for the tip. You've been very helpful.
|
|
|
|
|
Hi,
What should I use to change the display's gamma? I tried looking on google, but I don't see anywhere how to do it. Can you give me a link, or an example of changing the value? I need it to be able to change it when I want and faster, I could go each time in "Display Color Calibration" and change it from there, but that takes time, and I can't add a key shortcut to certain values.
Just as a note, I want to change gamma, not brightness.
modified 10-Jul-18 7:10am.
|
|
|
|
|
|
I tried looking at "Windows Graphics Device Interface" and "Microsoft Direct3D 9’s" but without an example to understand, I got lost in the parameters types they ask. I would like to make it kinda like the slider from "Display Color Calibration" (Calibrate Display Color, as you find it in search box), the difference will be that I will add a function so you can add some default key shortcuts to certain gamma values.
I'm used to code in Java, but there is no way to change gamma using that.
|
|
|
|
|
You have to generate a table that is passed to the setter function.
That is what the calibration does too: It generates the table according to the slider position.
But I do't know the formula (and the range used by the calibration tool). If you only need a few selections, you can use the getter function to read the table for different calibration settings.
|
|
|
|
|
I found the following code in a post, and this note but I didn't figured out what is the min and the max value the float factor should have. Is this the formula you were talking about?
Quote: To change gamma, cycle into ramp buffer and change RGB color where Gamma is the float factor.
WORD ramp[256*3];
for( int i=0; i<256; i++ ) {
ramp[i+0] = ramp[i+256] = ramp[i+512] =
(WORD)min(65535, max(0, pow((i+1) / 256.0, Gamma) * 65535 + 0.5));
}
SetDeviceGammaRamp(::GetDC(NULL), ramp);
I got it from this article (it does contain the source code, but the GUI code is very different from JavaFX):
Gamma correction slider[^]
|
|
|
|
|
Looks good, but I have not tested it.
But you do know that this is the C/C++ board and Java would be off topic?
However, all you have to do is converting the Algorithm to Java (should be no problem), check how to call Windows API functions from Java, and create the GUI according to your requirements. The GUI from that article is an example. Even a C++ developer using that code would create his own GUI controls and windows instead of using those from the example.
|
|
|
|
|
Quote: But you do know that this is the C/C++ board and Java would be off topic?
Yeah I know, that is why I didn't asked questions about java. I only made a comparison between the 2 of them.
Quote: However, all you have to do is converting the Algorithm to Java
I know how to use native functions. I missed this part in that article "float factor between 0.0 and 2.0"
Thanks for your help.
modified 10-Jul-18 4:47am.
|
|
|
|
|
So, I did a few tests with that formula for set gamma, and I found out that the range 0.0-2.0 isn't actually good. I gave values between 0.0-0.2 and nothing happened, then I tried some values between 0.3-4.0 and it was working. So there are values OVER 2.0 that are working and the values under 0.3 aren't working at all.
Can it be that the formula isn't actually correct or that the range he gave is wrong? Or maybe he thought that those values are what users may want?
|
|
|
|
|
I suggest to read about Gamma correction - Wikipedia[^] to understand it.
Note also that the default value for Windows is 2.2. Anything far away from that will display weird.
Very low values will simply result in most - if not all - table values to be set to zero. Similar for very high values which will result in 0xFFFF. That means that there is a range of useful Gamma values while all others will be clipped (note the max() and min() calls in the formula).
|
|
|
|
|
|
Hi sir,
i am working on MFC VC++ and i am very new to MFC application development. kindly please help me.
our application tool have a vertical scrollbar. it's working with the dragging.but not working with the mouse wheel. kindly please let me know what kind of code support have to give for mouse wheel.
i am using the below classes for creating the frame window.
1.class CMainFrame : public CFrameWndEx
{
.......
CMainFrame(); // main SDI frame window
...........
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (!CreateToolBar())
{
TRACE0("Failed to create Ribbon bar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) )
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_STATUS, csStatus, TRUE), csStatus);
m_wndStatusBar.AddSeparator();
m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_VER, csVersion, TRUE), csVersion);
m_wndStatusBar.AddSeparator();
m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_MEMORY, csMemory, TRUE), csMemory);
m_wndStatusBar.AddSeparator();
m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_SECURITY, csSecurity, TRUE), csSecurity);
theApp.SetMainFrame(this);
}
kindly please let me know how to handle the mouse wheel messages and what are steps have to follow to enable this.
|
|
|
|
|
The wheel scrolling has to be performed by the window which content should be scrolled by handling the WM_MOUSEWHEEL message | Microsoft Docs[^]. If that window is CWnd based, just override the OnMouseWheel() function.
I can not give more information because you did not give any information about your window. With frame based MFC applications, that are usually the CView derived classes.
|
|
|
|
|
hi sir,
i wrote the code below, the code is hitting whenever my mouse wheel scrolling. but the vertical scroll bar not moving.could you please give me your input please.
Header file:
class CMainFrame : public CFrameWndEx
{
protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)
public:
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
};
source file :
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWndEx)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
ON_WM_MOUSEWHEEL()
END_MESSAGE_MAP()
BOOL CMainFrame::OnMouseWheel(UINT fFlags, short zDelta, CPoint point)
{
TRACE0("in CMainFrame:: OnMouseWheel function");
return CWnd :: OnMouseWheel(fFlags, zDelta, point);
}
here CMainFrame is derived from CFrameWndEx, CFrameWndEx id derived from the CFrameWnd, CFrameWnd class is derived from the CWnd.
could you please help me if did any wrong.
|
|
|
|
|
Member 13903818 wrote: here CMainFrame is derived from CFrameWndEx, CFrameWndEx id derived from the CFrameWnd, CFrameWnd class is derived from the CWnd.
But do your application also have one or more Views (CView/CScrollView/CForView/... derived classes)?
|
|
|
|
|
yes .....
(class CFormView : public CScrollView
class CScrollView : public CView)
in our application we are deriving the class from the CView like below.
class CCommonEDM_AVitarView : public CView
in above derived call i have handled the OnMouseWheel function. but it's not hitting the code while scrolling the mouse wheel.
code :
Header file:
class CCommonEDM_AVitarView : public CView
{
protected: // create from serialization only
CCommonEDM_AVitarView();
DECLARE_DYNCREATE(CCommonEDM_AVitarView)
public:
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
};
source file :
IMPLEMENT_DYNCREATE(CCommonEDM_AVitarView, CView)
BEGIN_MESSAGE_MAP(CCommonEDM_AVitarView, CView)
ON_WM_MOUSEWHEEL()
END_MESSAGE_MAP()
BOOL CCommonEDM_AVitarView::OnMouseWheel(UINT fFlags, short zDelta, CPoint point)
{
TRACE0("in CCommonEDM_AVitarView:: OnMouseWheel function");
return CView :: OnMouseWheel(fFlags, zDelta, point);
}
i am not understanding how internal child windows are working with mouse wheel scrolling. but main window is not working..
|
|
|
|
|
The MFC document - view concept is a little bit complicated regarding the parent and child windows and their interaction.
But the message is sent to the control / window that has the focus. If your view contains controls then one of them probably has the focus and gets the message.
It is still unclear to which window your scroll bars belong. If they are for the view: why is your view not CScrollView based? If your view contains a single control: handle the message there.
|
|
|
|
|
Hello sir,
i have written the below code for my each child frame. this class is derived from the CScrollView. my mouse wheel is working fine for each individual window class. but i am trying to implement same support from my main window class.but mouse wheel is not working. could you please give me your valuable inputs.
My intention is instead of writing mouse wheel code for all the child class. if i implement mouse wheel function for my main frame. i would have been worth to all child classes.
my individual window class code :
mouse while is working with below code with below class..
Header file:
class CAboutView : public CFormView
{
-----------
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
}
Source file :
BEGIN_MESSAGE_MAP(CAboutView, CFormView)
//ON_WM_MOUSEWHEEL()
END_MESSAGE_MAP()
BOOL CAboutView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
return DoMouseWheel(nFlags, zDelta, pt);
}
This is my main frame:
with the below code my mouse wheel not working.
Header file :
class CMainFrame : public CFrameWndEx
{
-----------
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
}
Source file :
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
ON_WM_MOUSEWHEEL()
END_MESSAGE_MAP()
BOOL CMainFrame::OnMouseWheel(UINT fFlags, short zDelta, CPoint point)
{
CScrollView *wnd = NULL;
BOOL mValue;
mValue = wnd->DoMouseWheel(fFlags, zDelta, point);
return mValue;
}
|
|
|
|
|
|
I have a CData derived from CObject. In my CDocument, I have a CMap, with key as int, and values as CData*.
In a CMyDocument method I have:
void CMyDocument::GetData(int nItemData, CData* pData)
{
m_MapData.Lookup(nItemData, pData);
TRACE("Inside doc method: pData is not NULL: %d\n", NULL != pData);
}
and in my CMyView:
int nItemData = 1;
CData* pData = NULL;
GetDocument()->GetData(nItemData, pData));
TRACE("In MyView: pData is not NULL: %d\n", NULL != pData);
and here is the result:
Inside doc method: pData is not NULL: 1
In MyView: pData is not NULL: 0
Why inside CMyDocument I have a valid pData, but outside not ?
modified 8-Jul-18 10:17am.
|
|
|
|
|
In case 1 you have not shown the value of pData. In case 2 you have explicitly set its value to NULL.
|
|
|
|
|
In case 1, the trace show me that pData is not NULL, and after GetData call, I set up nothing, I only display if pData is NULL or not ... but is NULL ...
|
|
|
|
|