Quantcast
Channel: Visual C forum
Viewing all 15302 articles
Browse latest View live

How to get dialog box ComboBox selection item in VC++ MFC?

$
0
0

I add one dialog to menuItem click.

when i click the menuItem. it shows one dialog box which contains one comboBox and OK , CANCEL button.

i want to get ComboBox selected item. when i click the OK button.

help me..



Wanted: executable example of decltype(auto) with C++11 and C++14

$
0
0

I'm studying the book "Effective Modern C++" and on page 28 I see the following two code fragments:

template<typename Container, typename Index> // final
decltype(auto)                               // C++14
authAndAccess(Container&& c, Index i)        // version
{
  authenticateUser();
  return std::forward<Container>(c)[i];
}

template<typename Container, typename Index> // final
auto                                         // C++11
authAndAccess(Container&& c, Index i)        // version
-> decltype(std::forward<Container>(c)[i])
{
   authenticateUser();
   return std::forward<Container>(c)[i];
}

Can someone help me write a main program to call this code so I can see it execute in the new Visual Studio 2015 CTP debugger that I just downloaded and compare it with earlier versions?

I'm having trouble because I don't fully understand std::forward and how to select classes for the template argument Container and Index.

Thanks

Siegfried


siegfried heintze

Prevent MapiInitialize from displaying a MessageBox

$
0
0

I've hit a frustrating problem with MAPI and Outlook. I have code that calls MapiInitialize to detect if MAPI (Outlook) is avaialable for sending e-mail.

If it is the function returns TRUE, if it isn't it hangs and displays a message box, when the user closes that message box the function finally returns with FALSE.

Surely there's a way to prevent MapiInitialize from displaying this message box? why is this behavior forced rather than being some kind of runtime option when we call MapiInitialize?

I want a solution that is not tied to this or that windows version if possible...

Any help much appreciated

Cap'n



Memory problems when using ProgIDFromCLSID

$
0
0

Hi all,

I tried to implement a function that converts a GUID to either a uuid string or a prog id. The program steadily increased its memory usage during the runtime. Breaking down the problem I came to this peace of code which simply creates random guis and tries to convert them to prog ids:

#include "stdafx.h"
#include <string>
#include <windows.h>
#include <iostream>
#include <conio.h>
#pragma comment(lib, "Rpcrt4.lib");

int _tmain(int argc, _TCHAR* argv[])
{
    for (int i = 0; i < 10000000; i++) {
        GUID guid;
        UuidCreate(&guid);
        LPOLESTR str = nullptr;
        //-----> The next two lines cause the memory to steadily increase
        ProgIDFromCLSID(guid, &str);
        CoTaskMemFree(str);
    }

    std::cout << "Press any key to quit." << std::endl;
    _getch();
    return 0;
}

When running the code the memory steadily increases, but commenting out the two lines beneath the comment, the memory consumption stays stable. Am I doing something wrong here?

Thanks for your help,
Thomas

When navigating HTML URL, the HTML page is not occupying entire CDHTMLDialog

$
0
0

Hi,

I have a modeless child CDTMLDialog in one of the propertypage.When navigating same HTML page sometimes the html page occupies entire dialog but sometimes it doesn't.below are screenshots.In 2nd image the html page is not occuping entire page.Please anyone help to make html always occupies entire dialog.

Where is WCHAR defined?

$
0
0

I created a console app to assist in testing a short utility.  In there I wrote:

Const WCHAR dir_name[] = L”C:\\TEMP”;

The compiler says Error1             error C4430: missing type specifier - int assumed. Note: C++ does not support default-int               e:\code\delete_all_files_in_a_directory\delete_all_files_in_a_directory\delete_all_files_in_a_directory.cpp 12               Delete_All_Files_In_A_Directory

I used the defaults and the project properties shows: Use Unicode Character Set.

I used Google and Bing and the phrase:  visual studio where is WCHAR defineddoes not solicit the answer.

Here is the msdn page on WCHAR: https://msdn.microsoft.com/en-us/library/gg269344(v=exchg.10).aspx

It does not say where WCHAR is defined.

This page: https://social.msdn.microsoft.com/Forums/vstudio/en-us/750e1b3c-1b8f-4b64-9f9b-ee9bdedbfd34/char-wchar-tchar-galore?forum=vclanguage

Describes WCHAR but does not say where it is declared.

So,...,

1. What include file is needed for WCHAR?

2. Why is this so difficult to find?  (A rhetorical question.  Microsoft provides an incredible wealth of information.  But it is sometimes so incredibly difficult to find.)


~jag77 We need to know what a dragon is before we study its anatomy. (Bryan Kelly, 2010)

Internet Explorer displays a blank page when opening a local file while running unattended

$
0
0
Hi everyone:

I'm making a small MFC module that should generate a report (formatted using HTML) and then display it for a user on schedule at 8:30 AM every day. Pretty straightforward stuff.

I compose my report and then save it as a local HTML file in the CSIDL_APPDATA folder. I then use the following calls to display it using the default web browser (Internet Explorer in this case):

Code:
//Error checks are omitted for brevity
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
ShellExecute(NULL, NULL, strSaveFileTo, NULL, NULL, SW_SHOWNORMAL);
This module is run on schedule from the Task Scheduler. (The task is set up to run when a user is logged on, which is all the time for that PC. It is never turned off, put to sleep, etc. That computer has only one user that is never logged off either.)

This works perfectly fine when I test it by setting the task a minute or so in the future. But when the actual task is supposed to run at 8:30 AM, when the user wakes the screen all they see is a blank Internet Explorer page. (Note that if someone refreshes that page by hitting F5, only then my report is shown on the screen.)

So I started looking into it:

1) I checked that the file is properly saved (before calling ShellExecute) by reading it back and by comparing it with the original HTML markup that I saved earlier. It's all correct there.

2) I then checked the power saving options. That computer is set up to show screensaver after 5 minutes and to turn off screen after 25 minutes.

3) The web browser that causes this issue is IE version 11, with the latest updates installed. The operating system is Windows 7 Professional.

So I'm curious, what am I missing here? And why is IE showing a blank page only when computer is running unattended?

Tooltips stopped working after migrating from VS 2005 to VS 2010

$
0
0

Hi,

My code in a C/C++ app to create and update tooltips stopped working between VS 2005 and VS 2010. The tooltip was created using:

hwndTT = CreateWindow(TOOLTIPS_CLASS, TEXT(""), WS_POPUP,CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, W_USEDEFAULT, NULL, (HMENU)NULL, hinstDrawbase, NULL);

This succeeds in VS 2005 and in VS 2010. If I then setup the tooltip structure and add the tooltip using:

SendMessage(hwndTT,TTM_ADDTOOL,0,(LPARAM)&ti);

This succeeds in VS 2005 and in VS 2010. If I then setup the tooltip structure to get the tooltip info using:

SendMessage( hwndTT, TTM_GETTOOLINFO, (WPARAM)0, (LPARAM)&ti );

This succeeds in VS 2005 but fails in VS 2010. The failure in VS 2010 gives last error as 0 (indicating S_OK) when using

dwError = GetLastError();

I have been using one tooltip window whose owner is a frame window whose child is an MDI window. This MDI window becomes the parent of multiple static text and edit control child windows. I was updating and activating/deactivating the tooltip window as the mouse moved over the static text and edit control child windows. I tried ignoring the error from the SendMessage to get tool info since last error says S_OK and tried sending messages to update the tool info and activate the tooltip anyway, but to no effect. So the "key" falure seems to be related to the TTM_GETTOOLINFO failure.

Can anyone help?

Thanks, Chris


Mixed C Function Parameter Style

$
0
0

I am recently working with a quite old C libraries with VS2013.

I am puzzled with the different C function declarations.

here is some sample code:

/*
kr_style(factor) float factor; {
  printf("k&r_style:%f\n", factor);
}

void ansi_style(float factor) {
  printf("ansi_style:%f\n", factor);
}
*/

void test_kr_style() {
  kr_style(4.0f);
}

void test_ansi_style() {
  ansi_style(4.0f);
}

If I just uncomments the two functions, everything is right, both kr_style and ansi_style will print 4.0

But if I put the two functions (kr_style and ansi_style) in a separate c file, the things changed, The kr_style will print 4.0, but ansi_style will print 0.0

If the kr_style prints 0.0, I can accept, but the ansi_style prints 0.0 breaks the my believes on Visual Studio.



MDI child window appearance

$
0
0

When you create an MFC MDI application in Visual Studio 2012 by selecting "Multiple Documents", clearing the "Tabbed documents" checkbox, and selecting "MFC Standard" for the project style, you get a traditional MDI application with a main frame window and multiple child windows.

However, while the frame window gets the new flat Windows 8 look, the child windows still have a Windows7 style, with a 3D type light blue frame and a glossy close button in the top-right corner. Is there a way to get the child windows to have the same flat look as the main frame window?

Thanks in advance for any advice.

microsoft visual c++ runtime library error system32.rundll32.exe

$
0
0

I've tried serching for this specific issue to no avail.  This message seems to pop up frequently and I'm not tech savy enough to know what it's in regards to.  The message is "Microsoft Visual C++ Runtime Library    Runtime Error  -Program C:\Windows\System32\rundll32.exe."  Sometimes when I hit ok it disappears. but other times, it just keeps coming back.  Do I need to reinstall something or remove something?  Thanks for any help you can provide.

Robert

how to get click event message of CButton?

$
0
0

am able to create CButton dynamically on other applications(like firefox or chrome), but am unable to get click event handler for that button,  

if any one have any idea please share with me

Thanks in Advance

Error C2039: 'max' : is not a member of 'std'

$
0
0

I am trying to build and run this C++ sample

I am presented with the following errors: ERRORS

How do I fix them?

Thanks!

Can you use a static library built in vs2012 in vs2008?

$
0
0

I have a third party lib, that I need to use in VS2008, but after linking to the library and turning off Whole Program Optimization, I am still getting the following error:

fatal error C1900: Il mismatch between 'P1' version '20100826' and 'P2' version '20080116'
LINK : fatal error LNK1257: code generation failed

The first question I need to ask is; Is it possible to use static libraries built in VS2012 with older versions of visual Studio? 

and if Yes what steps are required?

At this point I do not know what settings the third party build their library with, and moving to vs2012 is not an option.

Dialog box scrollbars

$
0
0

Hi

I was wondering if anybody could tell me how to add variables to the scrollbars on a dialog box so I can have access to them and control them.

For example. You add a new dialog resource. You then go into it's properties and set Horizontal Scrollbar = True and Vertical Scrollbar = True. This then gives you a scrollbar on the right side and bottom. How do I now add a variable to them such as m_VertScrollbar, m_HorzScrollbar.

I'm using Visual Studio C++ 2013

Thank you


Unusual lParam behavior upon creating a thread

$
0
0

Hello,

I need some help passing a struct as a parameter to my thread.

I have a few variables in a structure and what happens is that only 2 specific values change their values upon calling CreateThread(...). I will post the code here to simplify the explanation:

struct ThreadParams {
	HINSTANCE hInstance; // duh
	HANDLE *hevent; // pointer to an array of 3 event handles
	HWND *hwnd; // pointer to an array of 2 valid window handles
};

And the piece of code where the error occurs:

tParams.hInstance = hInstance; // tParams is a ThreadParams struct
tParams.hwnd = hwnd; // In the main(calling) thread I have a pointer to a 2 dimensional array(to avoid confusion: it points to the first HWND element) and I just copy the address to the pointer inside the struct.
tParams.hevent = hevent;
htrd[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)render_thread_proc, (LPVOID)&tParams, 0, NULL);
htrd[1] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)compute_thread_proc, (LPVOID)&tParams, 0, NULL);

So to the problem:

Using the debugger, upon executing this line:

htrd[0] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)render_thread_proc, (LPVOID)&tParams, 0, NULL);

the value of the object(s) pointed to by hwnd change. The address is correct in the child and main thread, it's only their values. And as far as I can tell, nothing else happens, even in the child thread no statement has been executed. But in any case, here is the beginning of the child thread proc:

ThreadParams p = *(ThreadParams*)tParams;
LARGE_INTEGER currentTime;
LARGE_INTEGER prevDrawTime;
LARGE_INTEGER frequency;
LARGE_INTEGER frameTime;
prevDrawTime.QuadPart = 0;
QueryPerformanceFrequency(&frequency);
frameTime.QuadPart = (frequency.QuadPart * DRAW_TIME) / 1000000;

WaitForMultipleObjects(2, &(p.hevent[1]), TRUE, INFINITE);

I hope someone can help me with this little problem and I thank you in advance.


Enabling Debug Exceptions from OpenCV in VS2012 c++/cli

$
0
0

I am using VS2012 c++/cli on a Win 8.1 machine, 64 bit with OpenCV 2.4.9.

One issue I have is catching exceptions issued by OpenCV in try/catch blocks.

When I run my app in Debug mode from within VS2012, I never get an OpenCV exception.

However, when I run the exe generated by VS2012 in Debug mode outside of VS2012 (by just navigating in Explorer to the exe), exceptions are being generated by OpenCV and caught by mt try/catch blocks.

What do I need to set so that I can see these exceptions when running in Debug mode form within VS2012?

Any help greatly appreciated.

Regards,

James

High-resolution timer-based code execution on separate thread

$
0
0

Hello,

So I am working on a Windows CLR Project in Visual Studio that acts as a GUI, and this GUI is going to be used to manipulate variables which then need to be written over USB to an Arduino, but I'm running into an issue with the time resolution. I tried implementing both a System::Windows::Forms::Timer and a System::Timers::Timer, and in both cases I incremented a variable each tick of the timer and then sent the value of that variable to be displayed every Tick of a Windows forms timer. So both ticks were tied to a single variable, but only the System::Timers::Timer actually modified the variable. The Forms timer displayed it. I tried setting the interval to a value of 1ms, but the rate of incrementing is much slower (qualitatively the timer seems to run at <100Hz). Does anyone know how to implement a faster timer, ideally one running on a separate thread? I ran across the QueryPerformanceCounter which seems like a high-resolution timing solution, but I don't know how to execute code repeatedly using it. If someone could point me in the right direction I would much appreciate it.

Thank you,

Jordan

How to drag-and-drop D2D1 PathGeometry object in Visual C++?

$
0
0

I'd like to know how to drag-and-drop objects created with D2D1PathGeometry in my Visual C++ Win32 application. I havn't found good information about it in Google and in MSDN papers. I've created using D2D1PathGeometry two geometries. See them below:

// Drawing function.
    HRESULT MyClass::OnRender()
    {
            HRESULT hr = S_OK;
            . . . . .
        // Create the first geometry (m_pDirect2dFactory is ID2D1Factory instance created before).
        hr = m_pDirect2dFactory->CreatePathGeometry(&m_pMyGeom_1);
	    if (SUCCEEDED(hr))
    	{
                    // pSink is ID2D1GeometrySink instance created before.
		    hr = pMyGeom_1->Open(&pSink);
		    if (SUCCEEDED(hr))
		    {
			    pSink->SetFillMode(D2D1_FILL_MODE_WINDING);
			    // Add arc.
			    pSink->BeginFigure(m_InitialPoint_1, D2D1_FIGURE_BEGIN_FILLED);
			    pSink->AddArc(D2D1::ArcSegment(m_EndPoint_1, m_Radius, 0.0f, D2D1_SWEEP_DIRECTION_CLOCKWISE, D2D1_ARC_SIZE_SMALL));
			    pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
			    // Add line.
			    pSink->BeginFigure(m_InitialPoint_1, D2D1_FIGURE_BEGIN_HOLLOW);
			    pSink->AddLine(m_EndPoint_1);
			    pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
		    }
		    hr = pSink->Close();
	    }
	    // Create the second geometry.
	    hr = m_pDirect2dFactory->CreatePathGeometry(&m_pMyGeom_2);
	    if (SUCCEEDED(hr))
	    {
		    hr = m_pMyGeom_2->Open(&pSink);
		    if (SUCCEEDED(hr))
		    {
			    pSink->SetFillMode(D2D1_FILL_MODE_WINDING);
			    // Add arc.
			    pSink->BeginFigure(m_InitialPoint_2, D2D1_FIGURE_BEGIN_FILLED);
			    pSink->AddArc(D2D1::ArcSegment(m_BackEndPoint_2, m_Radius, 0.0f, D2D1_SWEEP_DIRECTION_CLOCKWISE, D2D1_ARC_SIZE_SMALL));
			    pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
			    // Add line.
			    pSink->BeginFigure(m_InitialPoint_2, D2D1_FIGURE_BEGIN_HOLLOW);
			    pSink->AddLine(m_EndPoint_2);
			    pSink->EndFigure(D2D1_FIGURE_END_CLOSED);
		    }
		    hr = pSink->Close();
	    }
            . . . . .
            SafeRelease(&pSink);
	    // Begin drawing (m_pRenderTarget is an ID2D1HwndRenderTarget instance).
	    m_pRenderTarget->BeginDraw();
            . . . . .
        m_pRenderTarget->FillGeometry(m_pMyGeom_1, m_pMidnightBlueBrush);
	    m_pRenderTarget->FillGeometry(m_pMirror_2, m_pMidnightBlueBrush);
            . . . . .
        hr = m_pRenderTarget->EndDraw();
    }
I've added WM_LBUTTONDOWN, WM_MOUSEMOVE and WM_LBUTTONUP messages in WndProc function of my application and define appropriate handlers for these messages in my application.They are: OnLButtonDown(int pixelX, int pixelY, DWORD flags), OnMouseMove(int pixelX, int pixelY, DWORD flags) and OnLButtonUp(). But the bodyes of these handlers are empty now because I don't know how can I programm drag-and-drop of my D2D1PathGeometry geometries. (Here ptMouse is D2D1_POINT_2F buffer for current mouse coordinate - the member of MyClass and PixelsToDips function translates phisical pixels in system DPI - this function is also the member of MyClass. f_DragMode is bool variable only and the member of MyClass.)
void MyClass::OnLButtonDown(int pixelX, int pixelY, DWORD flags)
{
	POINT mouseLocation;
	mouseLocation.x = pixelX;
	mouseLocation.y = pixelY;
	if (DragDetect(m_hwnd, mouseLocation))
	{
		ptMouse = PixelsToDips(pixelX, pixelY);
		SetCapture(m_hwnd);
		f_DragMode = true;
	}
}

// Обработывает события "Мышь переместилась".
void MyClass::OnMouseMove(int pixelX, int pixelY, DWORD flags)
{
	if ((flags & MK_LBUTTON) && f_DragMode)
	{
		const D2D1_POINT_2F dips = PixelsToDips(pixelX, pixelY);

                // ???WHAT SHOULD I WRITE HERE???		        // I don't know now.
                ptMouse = dips; // Save current mouse location.
		InvalidateRect(m_hwnd, NULL, FALSE);
	}
}
I need if I drag-and-drop m_pMyGeom_1 it doesn't affect to m_pMyGeom_2. And vice-versa (so if I drag-and-drop one geometry then the other one must stay on its place).How to programmatically detect that the mouse is just over the geometry? And how to identify which geometry (of two existed) is under mouse cursor? I've occupied in Direct2D for 6 days only. Please help me to write OnLButtonDown and especially OnMouseMove handlers. I'll be very thankful for any help.







error MSB6006: "CL.exe" exited with code -1073741819

$
0
0

Hi,

I recently got a new machine with Windows 7 and Visual Studio 2012 (my company has no plan to upgrade so we have to use this version). The problem is when I tried to compile my code, I've got an error "error MSB6006: "CL.exe" exited with code -1073741819" which I don't know what cause it.

I don't have the adminstrator right in this machine.

The code is compiled successfully on the other machine (Windows 7 and VS2012).

Have someone experience this before ? Please advise what should I do to get the code compile.

Thank you.


Wutipong W.

Viewing all 15302 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>