Hi,
How to make edit control as not editable without using setreadonly function?
Hi,
How to make edit control as not editable without using setreadonly function?
When using CMake to write a cross-platform application, I have one codebase, and then Cmake compiles the codebase for the target architecture when i tell it to compile.
I'm new to VS for C++, but it looks like the "recommended" approach to making a cross-platform application is two create one project for each OS. In each such project, you can have configurations for different architectures, but you basically need at least 2 projects. If you want to share code, you need a third project using the "shared items" project type. Is this correct?
hi
I try to setup C++ 2015 redistributable x64 but its failed with 0*80240017!! the log file :
[0824:1228][2018-12-05T19:27:03]i001: Burn v3.7.3813.0, Windows v6.3 (Build 9600: Service Pack 0), path: C:\Users\Ali\Downloads\vc_redist.x64.exe, cmdline: ''I use DirectX11 and want to get ImageData by Map function.
I created the Texture like below.
////////////////////////////////////////////////////////////////////////////////
D3D11_TEXTURE2D_DESC Desc;
ZeroMemory(&Desc, sizeof(D3D11_TEXTURE2D_DESC));
Desc.ArraySize = 1;
Desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
Desc.Usage = D3D11_USAGE_DEFAULT;
Desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
Desc.Width = m_nSize.x;
Desc.Height = m_nSize.y;
Desc.MipLevels = 1;
Desc.SampleDesc.Count = 1;
Desc.SampleDesc.Quality = 0;
////////////////////////////////////////////////////////////////////////////////
But Map fuction of the context return fail.
Is there any way to get ImageData of Target Texture?
Hi All,
I want to save a icon to a file in VC++. Please find the below code that I'm using. I could save all the icons being saved successfully. But when I try to save the grabbing icon to the local hard disk there is a black background around the image.
Please find the below code snippet.
CURSORINFO ci;
ci.cbSize = sizeof(ci);
GetCursorInfo(&ci);
HICON hico = ci.hCursor;
ICONINFO iconInfo;
GetIconInfo(ci.hCursor, &iconInfo);
BYTE buf[4096];
LONG cbSize = 0;
PICTDESC pd = {sizeof(pd), PICTYPE_ICON};
pd.icon.hicon = ci.hCursor;
CComPtr<IPicture> pPict = NULL;
CComPtr<IStream> pStrm = NULL;
BOOL res = FALSE;
res = SUCCEEDED( ::CreateStreamOnHGlobal(NULL, TRUE, &pStrm) );
res = SUCCEEDED( ::OleCreatePictureIndirect(&pd, IID_IPicture, FALSE, (void**)&pPict) );
res = SUCCEEDED( pPict->SaveAsFile( pStrm, TRUE, &cbSize ) );
if( res )
{
// rewind stream to the beginning
LARGE_INTEGER li = {0};
pStrm->Seek(li, STREAM_SEEK_SET, NULL);
// write to file
HANDLE hFile = ::CreateFile("E:\\abc.jpeg", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
if( INVALID_HANDLE_VALUE != hFile )
{
DWORD dwWritten = 0, dwRead = 0, dwDone = 0;
while( dwDone < cbSize )
{
if( SUCCEEDED(pStrm->Read(buf, sizeof(buf), &dwRead)) )
{
::WriteFile(hFile, buf, dwRead, &dwWritten, NULL);
if( dwWritten != dwRead )
break;
dwDone += dwRead;
}
else
break;
}
_ASSERTE(dwDone == cbSize);
::CloseHandle(hFile);
}
}
Please find the below grabbing icon.
Thank you in advance for the help.
Hi,
We have tested a Scenario where we just installed a new windows server 2012 and there was VC++ 2005 and 2008 installed.
I removed both components and installed SQL 2012 and found the VC++ 2005 and 2008 installed again.
Then removed both components and the next day I found the components re-installed automatically after removal.
Is there a recovery point for those components or does SQL 2012 require VC++ 2005 or 2008 ?
The reason for removal is that MS does not support the VC++ 2005 and 2008 anymore as they are out of support components and doesn't send any new security fixes for them.
Have search internet long and hard for answer to this but to no avail:
Have an internally developed exe (64-bit C++ program) which we're trying to run on a Windows Server 2012 R2 box, but fails immediately with the following exception (key parts):
Problem Event Name: BEX64
Fault Module Path: c:\windows\system32\ucrtbase.dll
Fault Module Version: 10.0.10586
Exception Code: c0000409
We believe there is no issue with our app because it runs fine on another WinSrv2012R2 box of a similar build, and have checked and can confirm that the dll is present in the system32 folder (and syswow64 folder). Any help would be greatly appreciated.
Thank you.
When I try to start a new program for example:
#include "stdafx.h"
#include <iostream> int main() { std::cout<< "Hello world and all that" << std::endl; return 0; }
I have a problem:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------ 1> Source.cpp 1>c:\users\lm\source.cpp(2): warning C4627: '#include <iostream>': skipped when looking for precompiled header use 1> Add directive to 'stdafx.h' or rebuild precompiled header 1>c:\users\lm\source.cpp(9): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? 1> ConsoleApplication1.cpp 1>c:\users\lm\consoleapplication1.cpp(4): warning C4627: '#include <iostrem>': skipped when looking for precompiled header use 1> Add directive to 'stdafx.h' or rebuild precompiled header 1>c:\users\lm\consoleapplication1.cpp(13): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? 1> Generating Code... ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Hi All,
I want to create a icon using SetDIBits() but it returns me a black rectangle. It seems to me like the below line code is returning me a NULL HBITMAP handle.
bmpcolor = CreateDIBSection(dc.GetSafeHdc(), &bmInfo, DIB_RGB_COLORS,(void**)&bits,0, 0);
Please find the entire code below. #include<iostream> #include<stdio.h> #include <afx.h> #include <afxwin.h> #include <atlbase.h> #include <vector> // for vector #include <iterator> // for std::istream_iterator and std::ostream_iterator #include <algorithm> // for std::copy #include <string> #include <fstream> #include <sstream> #include<Windows.h> #include<list> int _tmain(int argc, _TCHAR* argv[]) { int nColorBits = 32; CURSORINFO ci; ci.cbSize = sizeof(ci); GetCursorInfo(&ci); HCURSOR hcursor = ci.hCursor; struct ICONDIRENTRY { UCHAR nWidth; UCHAR nHeight; UCHAR nNumColorsInPalette; // 0 if no palette UCHAR nReserved; // should be 0 WORD nNumColorPlanes; // 0 or 1 WORD nBitsPerPixel; ULONG nDataLength; // length in bytes ULONG nOffset; // offset of BMP or PNG data from beginning of file }; ASSERT(nColorBits == 4 || nColorBits == 8 || nColorBits == 24 || nColorBits == 32); if (offsetof(ICONDIRENTRY, nOffset) != 12) { return false; } CDC dc; dc.Attach(::GetDC(NULL)); // ensure that DC is released when function ends // Write header: UCHAR icoHeader[6] = {0, 0, 1, 0, 1, 0}; // ICO file with 1 image // Get information about icon: ICONINFO iconInfo; GetIconInfo(ci.hCursor, &iconInfo); BITMAPINFO bmInfo = {0}; bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmInfo.bmiHeader.biBitCount = 0; // don't get the color table if (!GetDIBits(dc, iconInfo.hbmColor, 0, 0, NULL, &bmInfo, DIB_RGB_COLORS)) { return false; } // Allocate size of bitmap info header plus space for color table: int nBmInfoSize = sizeof(BITMAPINFOHEADER); if (nColorBits < 24) { nBmInfoSize += sizeof(RGBQUAD) * (int)(1 << nColorBits); } CAutoVectorPtr<UCHAR> bitmapInfo; bitmapInfo.Allocate(nBmInfoSize); BITMAPINFO* pBmInfo = (BITMAPINFO*)(UCHAR*)bitmapInfo; memcpy(pBmInfo, &bmInfo, sizeof(BITMAPINFOHEADER)); // Get bitmap data: ASSERT(bmInfo.bmiHeader.biSizeImage != 0); CAutoVectorPtr<UCHAR> bits; bits.Allocate(bmInfo.bmiHeader.biSizeImage); pBmInfo->bmiHeader.biBitCount = nColorBits; pBmInfo->bmiHeader.biCompression = BI_RGB; if (!GetDIBits(dc, iconInfo.hbmColor, 0, bmInfo.bmiHeader.biHeight, (UCHAR*)bits, pBmInfo, DIB_RGB_COLORS)) { return false; } // Get mask data: BITMAPINFO maskInfo = {0}; maskInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); maskInfo.bmiHeader.biBitCount = 0; // don't get the color table if (!GetDIBits(dc, iconInfo.hbmMask, 0, 0, NULL, &maskInfo, DIB_RGB_COLORS)) { return false; } ASSERT(maskInfo.bmiHeader.biBitCount == 1); CAutoVectorPtr<UCHAR> maskBits; maskBits.Allocate(maskInfo.bmiHeader.biSizeImage); CAutoVectorPtr<UCHAR> maskInfoBytes; maskInfoBytes.Allocate(sizeof(BITMAPINFO) + 2 * sizeof(RGBQUAD)); BITMAPINFO* pMaskInfo = (BITMAPINFO*)(UCHAR*)maskInfoBytes; memcpy(pMaskInfo, &maskInfo, sizeof(maskInfo)); if (!GetDIBits(dc, iconInfo.hbmMask, 0, maskInfo.bmiHeader.biHeight, (UCHAR*)maskBits, pMaskInfo, DIB_RGB_COLORS)) { return false; } // Write directory entry: ICONDIRENTRY dir; dir.nWidth = (UCHAR) pBmInfo->bmiHeader.biWidth; dir.nHeight = (UCHAR) pBmInfo->bmiHeader.biHeight; dir.nNumColorsInPalette = (nColorBits == 4 ? 16 : 0); dir.nReserved = 0; dir.nNumColorPlanes = 0; dir.nBitsPerPixel = pBmInfo->bmiHeader.biBitCount; dir.nDataLength = pBmInfo->bmiHeader.biSizeImage + pMaskInfo->bmiHeader.biSizeImage + nBmInfoSize; dir.nOffset = sizeof(dir) + sizeof(icoHeader); // Write DIB header (including color table): int nBitsSize = pBmInfo->bmiHeader.biSizeImage; pBmInfo->bmiHeader.biHeight *= 2; // because the header is for both image and mask pBmInfo->bmiHeader.biCompression = 0; pBmInfo->bmiHeader.biSizeImage += pMaskInfo->bmiHeader.biSizeImage; // because the header is for both image and mask HBITMAP bmpmask = NULL; HBITMAP bmpcolor = NULL; unsigned char* lpBitmapBits = NULL; bmpcolor = CreateDIBSection(dc.GetSafeHdc(), &bmInfo, DIB_RGB_COLORS,(void**)&bits,0, 0); bmpmask = CreateDIBSection(NULL, &maskInfo, DIB_RGB_COLORS,(void **)&maskBits, NULL, 0); int mask = SetDIBits(NULL, bmpmask, 0, maskInfo.bmiHeader.biHeight, (UCHAR*)maskBits, pMaskInfo, DIB_RGB_COLORS); int colo = SetDIBits(NULL, bmpcolor, 0, bmInfo.bmiHeader.biHeight, (UCHAR*)bits, pBmInfo, DIB_PAL_COLORS); ICONINFO in; HICON ii = NULL; in.hbmColor = bmpcolor;// iconinfo.hbmColor; in.hbmMask = bmpmask;// iconinfo.hbmMask; in.fIcon = TRUE; ii = CreateIconIndirect(&in); if(ii == NULL) MessageBox(NULL,L"Couldn't create Cursor NULL",L"NULL",0); ::SetSystemCursor((HCURSOR)ii,32512); getchar(); }
Could you please let me know why the bmpcolor is returning NULL ? or is there anything I'm passing is wrong.
Thanks,
Vinay
while (reader.Read()) {int i1 = reader.GetInt32(0), i2 = reader.GetInt16(1), i3 = 0;if (!reader.IsDBNull(2)) { i3 = reader.GetInt32(2); bolNullFound = false;//str3 = Convert.ToString(i3); }else bolNullFound = true; ++counter1; // Console.WriteLine(reader.GetInt16(1)); //Start of TEST DataRow row = ds2.Tables["T1Test"].NewRow(); row["EventID"] = i1; row["EventCode"] = i2;if (bolNullFound == false) { row["DebtID"] = i3; }else row["DebtID"].Equals(DBNull.Value); ds2.Tables["T1Test"].Rows.Add(row); }
in C++ we have:
CDatabase cd; CRecordset sourcers(&cd); CString DSNString = _T("DSN=database;UID=sa;PWD=password;"), SQLString = _T("SELECT EventID, EventCode, Debtid FROM Events WHERE Eventcode IN (10, 16)");try { cd.OpenEx(DSNString, NULL ); }catch(CDBException *e ) { AfxMessageBox(_T("Didn't open ODBC database.\n") + e->m_strError);throw; }try { sourcers.Open( CRecordset::snapshot , SQLString ); }catch(CDBException *e ) { AfxMessageBox(_T("failed opening ODBC CRecordset ") + e->m_strError);throw; }int fieldcount = sourcers.GetODBCFieldCount( ), i, rec; CDBVariant varValue;//CString tstring;longint tc = 0; printf("Starting...\n"); CTime starttime = CTime::GetCurrentTime();if ( !sourcers.IsEOF() ) sourcers.MoveFirst();while ( !sourcers.IsEOF()) {for ( i = 0; i < fieldcount; ++ i ) // do nothing other than load field into tstring sourcers.GetFieldValue(i, varValue); ++tc;// } // end for rectry { sourcers.MoveNext(); }catch( CDBException *e ) { AfxMessageBox( _T("MoveNext Failed: ") + e->m_strError);throw; } } // end while
Hi
We would like to force the scale factor to 100% on the screen linked to the win 10 computer where our product is installed...But we Don't find how to do that in C++/C#
with winuser.h we succeed to retrieve the information of the scale factor but not to change it to 100% especially
we are the only software launched on the computer...the computer is dedicated to our software. When we link the screen to the box and the resolution is too high Windows put automatically the scale to 150% but we want to force the 100% everytime we Don'twant to let Windows to adapt the DPI (because we broadcast Something on the screen and we Don't need to have more than 100% otherwise it is not broadcasted correctly), so we need to stop the auto scaling or to force the 100% when our soft is launched.
and we need to modify dpi directly because we need that the dpi is 100% for our process but also for IE process that we can use.
does anyone already do that?
thanks
_Pair_base(_Other1&& _Val1, _Other2&& _Val2)
: first(_STD forward<_Other1>(_Val1)),
second(_STD forward<_Other2>(_Val2))
error occurs here > {
// construct from moved values
}
_Ty1 first;
// the first stored value
_Ty2 second;
// the second stored value
};
template
<class _Ty1,
class _Ty2>
any help would be great.Hi!
Something happened to my "traditional"Windows app project (I don't want to use ATL nor MFC with this project). It just switched to Multibyte char set, and changing the setting in Project properties (GUI) would not help.
I also tried #define UNICODE in header file, no luck, all WinApis default to A which creates huge problem.
I thought that maybe some global setting kicked in in my Visual Studio installation, so I opened another Windows app project, and this time it defaulted to UNICODE, and would not switch to Multibyte. Strange.
Would you have any idea what might happen, and where I could start looking to have this fixed?
Thank you!
Hi,
Is it possible I can send input and get output through sendmessage() api.
If I pass index to sendmessage, I have to get int or cstring or pointer as return data?
Hi,
I have an application that has many plugins and all added as forms into one window (as sheets of a tabbed pane). The thing is there are many components on each of plug ins and some of these components cause time consuming jobs due to processing of windows messages. There is one message pump (message loop, excuse me if I do not use the terminology correctly). Time consuming jobs on one of the plugins cause complete application to lag.
I am aware that I can try to get rid of time consuming jobs in processing messages. That is at hand, but what I want is different message pumps to run for each plug in and in this way a lag occurring in windows message pump of a plugin will not cause lag in main window.
When I read following in Microsoft documentation:
https://docs.microsoft.com/en-us/windows/desktop/LearnWin32/window-messages
"For each thread that creates a window, the operating system creates a queue for window messages. This queue holds messages for all the windows that are created on that thread. The queue itself is hidden from your program. You cannot manipulate the queue directly. However, you can pull a message from the queue by calling theGetMessage function."
I thought that if I create each window in separate thread, it will be enough. I tried, create 2 windows in separate threads and saw that their message pumps are not effecting one another. But these 2 windows are completely separated.
When I created one of them as child of the other, although the message pumps are separate, if there is a time consuming job in message loop of child, the parent is also lagged. Somehow the operating system is pausing the message queue of parent window. Below is the way I do it.
Is it possible what I want? Can I create a child window that has a separate message pump and not lagging the parent. And is it the correct way? If not what is the correct way to separate message pumps between parent and child windows?
Note: I try to use win32 api
#ifndef UNICODE #define UNICODE #endif #define _CRT_SECURE_NO_WARNINGS #include <windows.h> #include "resource.h" #include <stdio.h> LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); HWND _hwnd1; HWND _hwnd2; DWORD WINAPI threadSvc(LPVOID lpParam); DWORD WINAPI threadSvc_1(LPVOID lpParam); DWORD WINAPI threadSvc_2(LPVOID lpParam); int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) { /*Start a thread for trial*/ #if 1 DWORD dwThreadId1 = NULL; HANDLE myThread1 = CreateThread(NULL, // default security attributes 0, // use default stack size threadSvc_1, // thread function name /*pDataArray[i]*/&hInstance,// argument to thread function 0, // use default creation flags &dwThreadId1); // returns the thread identifier if (myThread1 == NULL) OutputDebugStringA("thread 1 failed to start\n"); else OutputDebugStringA("thread 1 started\n"); #endif Sleep(2000); #if 1 DWORD dwThreadId2 = NULL; HANDLE myThread2 = CreateThread(NULL, // default security attributes 0, // use default stack size threadSvc_2, // thread function name /*pDataArray[i]*/&hInstance,// argument to thread function 0, // use default creation flags &dwThreadId2); // returns the thread identifier if (myThread2 == NULL) OutputDebugStringA("thread 2 failed to start\n"); else OutputDebugStringA("thread 2 started\n"); #endif // wait while (1) Sleep(1000); // Run the message loop. - no need for a message loop as it is does not have a window. // MSG msg = { }; // while (GetMessage(&msg, NULL, 0, 0)) // { // TranslateMessage(&msg); // DispatchMessage(&msg); // } return 0; } //wWinMain returns LRESULT CALLBACK WindowProc1(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { DWORD threadId = GetCurrentThreadId(); char buf[512] = {}; sprintf(&buf[0], "barman: WindowProc1 [threadId=%08ul] [msgId=%04u]\n", threadId, uMsg); OutputDebugStringA(buf); switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_SETCURSOR: OutputDebugStringA("WM_SETCURSOR \n"); return 0; #if 1 case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1)); EndPaint(hwnd, &ps); } return 0; #endif } // to default window processor return DefWindowProc(hwnd, uMsg, wParam, lParam); } LRESULT CALLBACK WindowProc2(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { DWORD threadId = GetCurrentThreadId(); char buf[512] = {}; sprintf(&buf[0], "barman: WindowProc2 [threadId=%08ul] [msgId=%04u]\n", threadId, uMsg); OutputDebugStringA(buf); switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 5)); EndPaint(hwnd, &ps); } return 0; #if 0 case WM_NCHITTEST: { PostMessage(_hwnd1, WM_NCHITTEST, wParam, lParam); } return DefWindowProc(hwnd, uMsg, wParam, lParam); #endif case WM_LBUTTONDOWN: { sprintf(&buf[0], "barman: MOUSE CLICKED... [threadId=%ul]\n", threadId); OutputDebugStringA(buf); #if 1 /*To create a lag in msg queue 100 millions*/ for (long i = 0; i < 100000000; i++) { printf("de"); } #endif } return 0; } // switch case ends // to default window processor return DefWindowProc(hwnd, uMsg, wParam, lParam); } /*useless thread*/ DWORD WINAPI threadSvc(LPVOID lpParam) { while (1) { OutputDebugStringA("thread running\n"); Sleep(500); } return 0; } // start a window and register it then process its message queue DWORD WINAPI threadSvc_1(LPVOID lpParam) { WNDCLASS wc1 = { }; const wchar_t CLASS_NAME_1[] = L"First sample window class "; wc1.lpfnWndProc = WindowProc1; // win proc for the message pump wc1.hInstance = *((HINSTANCE*)lpParam); wc1.lpszClassName = CLASS_NAME_1; RegisterClass(&wc1); _hwnd1 = CreateWindowEx(0, // ex style id DWORD CLASS_NAME_1, // class name L"Learn to Program Windows 1 ", // window name WS_OVERLAPPEDWINDOW // style | WS_CLIPCHILDREN, // for parent not to overpaint the child window. CW_USEDEFAULT, // Size and position CW_USEDEFAULT, // Size and position CW_USEDEFAULT, // Size and position CW_USEDEFAULT, // Size and position NULL, // parent window NULL, // ?? hMenu *((HINSTANCE*)lpParam), // hInstance NULL); // lpParam - type LPVOID->long pointer of type void if (_hwnd1 == NULL) { return 0; } ShowWindow(_hwnd1, 5); MSG msg = { }; #if 1 char buf[512] = {}; BOOL getMessageResult = false; while (getMessageResult = GetMessage(&msg, NULL, 0, 0) != 0) { if (getMessageResult == -1) { sprintf(&buf[0], "task 1 message loop get message returned error [threadID:%04ul]\n", GetCurrentThreadId()); OutputDebugStringA(buf); return 0; } else { sprintf(&buf[0], "Thread-1 before Dispatch Message [threadId:%04ul] [WHND:%d]\n", GetCurrentThreadId(), msg.hwnd); OutputDebugStringA(buf); TranslateMessage(&msg); DispatchMessage(&msg); } sprintf(&buf[0], "Thread-1 after Dispatch Message [threadId:%04ul] [WHND:%d]\n", GetCurrentThreadId(), msg.hwnd); OutputDebugStringA(buf); } #endif #if 0 //PeekMessage loop example while (WM_QUIT != msg.message) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) > 0) //Or use an if statement { TranslateMessage(&msg); DispatchMessage(&msg); } } #endif return 0; } DWORD WINAPI threadSvc_2(LPVOID lpParam) { WNDCLASS wc2 = { }; const wchar_t CLASS_NAME_2[] = L"Second sample window class"; wc2.lpfnWndProc = WindowProc2; wc2.hInstance = *((HINSTANCE*)lpParam); wc2.lpszClassName = CLASS_NAME_2; RegisterClass(&wc2); _hwnd2 = CreateWindowEx(0, CLASS_NAME_2, L"Learn to Program Windows 2 ", WS_CHILD // Styles that are used. | WS_VISIBLE //| WS_CAPTION //| WS_SYSMENU //| WS_THICKFRAME //| WS_MINIMIZEBOX //| WS_MAXIMIZEBOX /* WS_OVERLAPPEDWINDOW*/, // Size and position CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, _hwnd1 /*NULL*/, // parent window NULL, *((HINSTANCE*)lpParam), NULL); if (_hwnd2 == NULL) { return 0; } ShowWindow(_hwnd2, 5); MSG msg = { }; #if 1 while (GetMessage(&msg, NULL, 0, 0)) { if (msg.hwnd == _hwnd2) { TranslateMessage(&msg); OutputDebugString(L"Thread-2 before Dispatch Message\n"); DispatchMessage(&msg); OutputDebugString(L"Thread-2 after Dispatch Message\n"); } else { OutputDebugString(L"Thread-2 ignored a msg\n"); } } #endif #if 0 //PeekMessage loop example while (WM_QUIT != msg.message) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) > 0) //Or use an if statement { TranslateMessage(&msg); DispatchMessage(&msg); } } #endif return 0; }
Hello, I have problem with CreateProcess and Telnet. The main question is why telnet.exe file contains:
'telnet' is not recognized as an internal or external command,
operable program or batch file.
I checked on PC telnet is installed. Where is problem?
void SaveResult(const wchar_t *fileName, const wchar_t *commandLine) { SECURITY_ATTRIBUTES sa; sa.nLength = sizeof(sa); sa.lpSecurityDescriptor = NULL; sa.bInheritHandle = TRUE; HANDLE h = CreateFile(fileName, FILE_WRITE_DATA, FILE_SHARE_WRITE | FILE_SHARE_READ, &sa, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if(h == INVALID_HANDLE_VALUE) return; PROCESS_INFORMATION pi = { 0 }; STARTUPINFO si = { sizeof(si) }; si.dwFlags |= STARTF_USESTDHANDLES; si.hStdInput = NULL; si.hStdError = h; si.hStdOutput = h; wchar_t *writable_cmdline = _wcsdup(commandLine); BOOL success = CreateProcess(NULL, writable_cmdline, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi); bool finished = false; //wait for 1 second for(int i = 0; i < 10; i++) { if(WaitForSingleObject(pi.hProcess, 100) <= 0) { finished = true; break; } } if(success) { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } CloseHandle(h); free(writable_cmdline); if(!finished) printf("Process didn't finish\n"); } int main() { SaveResult(L"telnet.txt", L"C:\\windows\\system32\\cmd.exe /c telnet"); SaveResult(L"ipconfig.txt", L"C:\\windows\\system32\\cmd.exe /c ipconfig"); return 0; }
Hi Folks:
Developing on Windows 10 Pro, VS 2017 Community, all C++, Win32, no MFC.
My application produces a report. The same function draws the report on a display or to a printer.
A user might produce multiple reports during the time the program is running.
Lines are drawn to separate sections of the report and practically every number is surrounded by a black rectangle.
This starts out fine, and can work great for a lot of reports. Then, for some reason, the lines and rectangles stop being displayed.
I have code to simulate a user in order to test the application. Thousands of reports can be generated while running a test. These start out fine, but after 5, 10 or 100 reports, all of the lines and rectangles disappear while the text in the reports is just fine.
I've proceeded a call to Rectangle() with the following in an effort to figure out what's causing this:
#ifdef _DEBUG COLORREF current_pen_color = SetDCPenColor(hdc, 0x00); if (current_pen_color != 0) { int test_x = 0; } SetDCPenColor(hdc, current_pen_color); #endif Rectangle(hdc, rectangle_frame.left, rectangle_frame.top, rectangle_frame.right, rectangle_frame.bottom);
My plan is to see when the pen color stopped being black, but a break point at thetest_x = 0 line is never triggered.
Suggestions on what I'm doing wrong, or how I might track down the issue are appreciated.
Thanks
Larry
Hello,
I am attempting to write a program that will need to paint fillRectangles to a tabPage anytime the user selects a specific tabPage. I am having trouble figuring out how to do this, as it seems like I would need to somehow manually call the tabPage_Paint event, but I'm not even sure if that's what I'd have to do.
In essence, the code should look like this:
private: System::Void TabControl1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) { if(TabControl1->SelectedTab==tabPage1) { //Draw a fillRectangle on tabPage1 } }
I have a simple app that monitors and lists all clipboard formats available on the system clipboard whenever the clipboard is updated. It works totally fine in almost all scenarios. The only problem is that when the app is ran as Local System AND the clipboard is updated with registered formats (i.e. copying RTF text in MS Word), the list of formats I get from iterating over EnumCLipboardFormats is incomplete. The iterated calls to EnumClipboardFormats ends after grabbing the very first format (which is always "DataObject" - 49161) because the subsequent call always returns 0 with ERROR_SUCCESS (meaning there is no more format to return). According to the test case where the app is running as the logged-on user, copying the exact same data (RTF text in this case) should have resulted in listing >5 formats. Also, when I am dealing with standard clipboard formats (i.e. copying plain-text from notepad), I don't have this issue at all. Regardless of which user the app is running as, the list I get returned from the iterated calls to EnumClipboardFormats is always the same. It's super weird. To me, it seems like the other formats that are not getting returned from the enum call is "hidden" in some sense, but I was unable to find any documentation providing clues to explain this behavior, and I have not found any article or thread talking about this issue.
I've already tried impersonating the logged-on user, but that did not help. Impersonation was successful, but the iteration over EnumClipboardFormats still ended after giving me the first format.
For clarity, these are the test cases:
1. Run the app as the logged-on user + update the clipboard with a standard format (plain-text from notepad) = Iterated enum returns the full list of formats
2. Run the app as the logged-on user + update the clipboard with a registered format (RTF text from MS Word) = Iterated enum returns the full list of formats
3. Run the app as Local System + update the clipboard with a standard format (plain-text from notepad) = Iterated enum returns the full list of formats
4. Run the app as Local System + update the clipboard with a registered format (RTF text from MS Word) = Iterated enum returns an imcomplete list (always iterated over for only a single format)
Does anyone know what is causing this inconsistency and what the solution is to fix it?