I do not have lvm_GetSelectionMark in my commctrl.h - c++

I needed to get the id of the focused item from a listview using a handle:
int selected = (int)SendMessage(hWnd, LVM_GETSELECTIONMARK, 0, 0);
However, I get an error that LVM_GETSELECTIONMARK was not declared in this scope? Is there something wrong with my library because the macro ListView_GetSelectionMark(hWnd) does not exist either.
Also, I did include commctrl.h in the header.
Thank you.

Add these lines to your project. For some reason these are missing from the Commcrtl.h included with Codeblocks IDE.
#define LVM_GETSELECTIONMARK (LVM_FIRST+66)
#define ListView_GetSelectionMark(w) (INT)SNDMSG((w),LVM_GETSELECTIONMARK,0,0)

Related

How to use VirtualDesktopManager interface?

I'm trying to find out if a window belongs to the current virtual desktop.
I found the VirtualDesktopManager class form the winapi, but even though it is supposed to be in the "shobjidl.h" header according to here, when I compile the code it throws this error:
85:5: error: 'VirtualDesktopManager' was not declared in this scope
important piece of my code:
#include <shobjidl.h>
...
BOOL is_on_current_desktop = FALSE;
VirtualDesktopManager g_pvdm;
g_pvdm.IsWindowOnCurrentVirtualDesktop(hwnd, &is_on_current_desktop); // hwnd is a window handle acquired previously
g_pvdm.Release();
How could I make this work?
Apparently this interface was not included in the "shobjidl.h" header in mingw64 which I was using, running it in Visual Studio it finds it. So the issue was in the header.

How do I get a Resource ID edit in MFC editor to propagate to code?

I make a button in the resource editor in an MFC program.
I give it an ID.
I use the ID in code with CWnd *tLabel = GetDlgItem(IDC_CHANGETWO);
I am pleased.
I go back to editor
I change the ID
Code does not acknowledge new name, even with rebuild
I change some flag (tabstop)
Code still does not care
In order to get an ID name change to propagate to the code, I have to change the ID AND any other field in the same save. Only then does it realize it is dirty and update the resource table.
This is 100% reproducible on mine and my students' computers. This workaround has kept the class from stalling, but... what the heck is this?
Visual Studio Enterprise 2015
Version 14.0.23107.0 D14REL
If you change the name of a resource control it will not propagate that throughout your source code as you have already learned.
Ideally you need to use something like VisualAssist: http://www.wholetomato.com/
It allows you to rename your resource ID values
What you need to use is refactoring. If you open your resource file as a text file in the IDE (as opposed to the resource editor) and locate your control, you should be able to right-click it and choose Refactor (VA):
Then select Rename. It should preview the changes in the various source code files:
You can use the same procedure for renaming variables and method declarations.
While the answer given is good, it doesn't show what happens behind the scene when you update a resource ID.
All resource IDs go into one header: resource.h
This file is read by C++ compiler, as well as by resource compiler (the .RC file.)
Using resource editor, you just type an ID, and the resource-editor would simply create an entry in resource.h
This header looks like:
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by MFCApplication1.rc
//
#define IDR_MAINFRAME 128
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_MFCAPPLICATION1_DIALOG 102
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 129
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 32771
#endif
#endif
So, when you add a new control on dialog (or any other form), and name it IDC_DOWNLOAD_NOW, and save the resource, this header will get updated like:
#define IDR_MAINFRAME 128
#define IDC_DOWNLOAD_NOW 1000
Also, internal variable (like _APS_NEXT_CONTROL_VALUE gets updated).
Well.. when you have same symbol in other dialog, VS will simply use the same macro with same value. You add another button on third dialog with same name, it doesn't modify resource.h either.
But... when you modify control in these 3 dialogs to name is like IDC_DOWNLOAD_LATER, only .RC and resource.h get updated. Old value, and old usages still exist. You wont get any compiler error (since macros are there!).
#define IDR_MAINFRAME 128
#define IDC_DOWNLOAD_NOW 1000
#define IDC_DOWNLOAD_LATER 1001
In another case, when you remove the button (from any of 3 dialog boxes), program will compile fine, but GetDlgItem, DDX_Control etc will fail at runtime (Since IDC_DOWNLOAD_NOW doesn't exist in current dialog!)
Now think what would happen if you mass rename the symbols using any tool - boom - all resources now have IDC_DOWNLOAD_LATER!
You should use Resource Symbols dialog to find what resource IDs are used by which dialog. From here you can rename and delete also.
Here is a second possible way to handle the specific issue of IDC_STATIC. Your question should be modified to include this.
I have started a temporary dialogue project and selected the default static text:
As you can see, it is labelled IDC_STATIC. I now directly change the ID value in the resource editor itself and hit the enter key:
Then I save it (this updates the resource.h file). Then, this is what we see if I use an application called ResOrg:
As you can see, the resource.h file is correct. It is at this point you now add your variables.
Interestingly, the IDE does not actually allow you to add variables to IDC_STATIC objects anyway. But suppose you have two if them:
You can still rename each one, save the file, re-build, and view your resource file:
As you can see, it is all still good. It is at this point that you can add variables and event handlers now. And it is in this context where VisualAssist would be used to rename variables/ID's used throughout your application.
I was not sure to edit my existing answer with this additional information. Perhaps that might be better?

C++ Error: identifier "CWnd" is not defined

I'm very much a C++ newbie, so please bear with me.
This line of code which resides within a function:
CWnd* pWnd = CWnd::FindWindow("Shell_TrayWnd", "");
CWnd is coming up as "undefined". I know I need to define it in the global scope, but how? What header do I need to include to use this class? Project is MFC.
Using VS 2010.
Here's how to solve this problem independently.
First, Google for "cwnd"
Second, click the first link.
Third, read the page
Requirements
Header: afxwin.h

Input Box in an MFC CWinApp

I want to use a simple input box in vc++ mfc. I did created a dialog called IDD_DIALOG1, and added a text box. I added a public variable for the input box and created a class call CInputDlg. Now I use the following code but I face with error:
CInputDlg dialog;
if (dialog.DoModal() == IDOK)
{
m[nodeTemp][i] = weight;
}
the error is:
Error 2 error C2065: 'CInputDlg' : undeclared identifier c:\users\omid\documents\visual studio 2008\projects\shortest path\shortest path\shortest pathdlg.cpp 294
what's the problem? can anyone help me please?
At the top of the file containing this code (it looks like you've named it shortest pathdlg.cpp):
CInputDlg dialog;
if (dialog.DoModal() == IDOK)
{
m[nodeTemp][i] = weight;
}
You need to add an #include statement that tells the compiler you'll be using things defined in a different source code file. In this case, you need to add the header file that defines the class CInputDlg. Presumably that file is called InputDlg.h. If so, you can simply add the following line:
#include "InputDlg.h"
For more information, please read this MSDN article about #include Directives in C++
Hi i think you not include h file for it. Show yours includes in shortest pathdlg.cpp

Why isn't the dropdown arrow drawn for an CMFCMenuButton?

I ran into this issue when trying to add a CMFCMenuButton to an existing MFC application. It worked properly, and even resized the button to accommodate the dropdown arrow. But it didn't draw the dropdown arrow, and when I hovered over the button, I saw the following debug output:
> Can't load bitmap: 42b8.GetLastError() = 716
> CMenuImages. Can't load menu images 3f01
It turns out that even with Visual Studio 2010 RTM, when you create a brand new MFC Dialog based application, the CMFCMenuButton doesn't draw the arrow and shows the same errors. Initially I assumed that I didn't have something installed or registered correctly. However, the NewControls example from the MFC Feature Pack showed the dropdown arrow perfectly.
What is missing?
The reason I posted this question is because I couldn't find any answers via Google. The closest I came when researching it was a couple hacks that didn't seem to be the real solution. After pouring over the NewControls example, I finally found the culprit.
At the bottom of the default .rc file for a project, there is the following code:
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#include "res\YOUR_PROJECT_NAME.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#endif
The NewControls example's .rc file looks like this:
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE 9, 1
#include "res\NewControls.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#ifndef _AFXDLL
#include "afxribbon.rc" // Ribbon and control bars
#endif
#endif
Adding the afxribbon.rc enables the bitmap resources needed for the controls in the MFC Feature pack update. Now you can't just simply add the missing code to the bottom of the .rc file. If you do that, every time you edit the resource file using the visual designer, your added code will be removed. The solution to the problem is to add this to the bottom of the YOUR_PROJECT_NAME.rc2 file:
#ifndef _AFXDLL
#include "afxribbon.rc" // Ribbon and control bars
#endif
Make sure you have an empty line at the bottom of the file, or the resource compiler will complain. I'm not sure what setting needs to be adjusted in order for the visual designer to automatically include afxribbon.rc like it does in the NewControls example project. But adding it to the .rc2 seems to fix the problem.
Update
Keep in mind that you can use the IDE to modify your RC file:
Right-Click the RC file and select Resource Includes...:
Paste the new code into the Compile-time directives area:
I solve this problem for myself in such way: I add a clause to CMyApp::InitInstance:
BOOL CMyApp::InitInstance()
{
CWinAppEx::InitInstance();
InitCommonControls();
//This!
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
//...
return TRUE;
}