|
I am using MFC.
I've added the OnCtlColor() event and it changes the color, but the backgrounds of the edit box and static text box remain grey instead of transparent:
HBRUSH S2000_CP_DLG::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch ( pWnd->GetDlgCtrlID() )
{
case IDC_FW_VERSION: //Static Text box
case IDC_MESSAGES: //Edit Control
pDC->SetTextColor(rgbColor_RED);// Set the text color to red
pDC->SetBkMode(TRANSPARENT);// Set the background mode for text to transparent
break;
}
return hbr;
}
I made sure the WINVER is defined to 0x0501 to compile for XP, but still, the background is not see-through.
Is there a fix for the background transparency ?
|
|
|
|
|
You need to return a handle to a brush that you've created/obtained
instead of returning the default brush...
CBrush m_RedBrush;
...
m_RedBrush.CreateSolidBrush(RGB(0xFF,0x00,0x00));
...
HBRUSH S2000_CP_DLG::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
switch ( pWnd->GetDlgCtrlID() )
{
case IDC_FW_VERSION:
case IDC_MESSAGES:
pDC->SetTextColor(rgbColor_RED);
pDC->SetBkMode(TRANSPARENT);
break;
}
return m_RedBrush;
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
using the solid red brush makes the static text and edit control backgrounds red.
What I really wanted is have the bitmap on the Dialog visible through the Static Text and Edit Control.
|
|
|
|
|
You could return a NULL brush:
return (LRESULT)::GetStockObject(NULL_BRUSH);
This works on static controls, but I have not got it to work on edit controls.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I just tested - returning a NULL brush works unless XP visual styles are enabled.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes you need to respond to the WM_CTLCOLOREDIT message. Google for that and look it up on MSDN you should be able to find some code samples.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
Hi,
I am getting cmpilation error "Cannot convert parameter from 'int' to 'HANDLE'" on 64 bit windows for stackwalk64 code. I am porting 32 bit code to 64 bit windows. Could you please any one tell me why compiler is throwing these errors ? MS VS2005 is being used. Down below is code snippet.
stackwalkerTest.h
-----------------
typedef BOOL (__stdcall * STACKWALKPROC)
( DWORD, HANDLE, HANDLE, LPSTACKFRAME, LPVOID,
PREAD_PROCESS_MEMORY_ROUTINE,PFUNCTION_TABLE_ACCESS_ROUTINE,
PGET_MODULE_BASE_ROUTINE, PTRANSLATE_ADDRESS_ROUTINE );
typedef DWORD (__stdcall *SYMSETOPTIONSPROC)(DWORD);
typedef BOOL (__stdcall *SYMGETSYMFROMADDRPROC)
( HANDLE, DWORD, PDWORD, PIMAGEHLP_SYMBOL );
typedef BOOL (__stdcall *SYMGETLINEFROMADDRPROC)
( HANDLE, DWORD, PDWORD, PIMAGEHLP_LINE );
typedef BOOL (__stdcall * SYMINITIALIZEPROC)( HANDLE, LPSTR, BOOL );
typedef BOOL (__stdcall *SYMCLEANUPPROC)( HANDLE );
typedef LPVOID (__stdcall *SYMFUNCTIONTABLEACCESSPROC)( HANDLE, DWORD );
typedef DWORD (__stdcall *SYMGETMODULEBASEPROC)( HANDLE, DWORD );
STACKWALKPROC _StackWalk64;
SYMSETOPTIONSPROC _SymSetOptions;
SYMGETSYMFROMADDRPROC _SymGetSymFromAddr;
SYMGETLINEFROMADDRPROC _SymGetLineFromAddr;
SYMINITIALIZEPROC _SymInitialize;
SYMCLEANUPPROC _SymCleanup;
SYMFUNCTIONTABLEACCESSPROC _SymFunctionTableAccess;
SYMGETMODULEBASEPROC _SymGetModuleBase;
stackwalkerTest.cpp
-------------------
_StackWalk64 = (STACKWALKPROC)::GetProcAddress(m_hImageHlp, "StackWalk64");
if ( ! _StackWalk64( IMAGE_FILE_MACHINE_AMD64,
GetCurrentProcess(),
GetCurrentThread(),
&sf,
pContext,
0,
_SymFunctionTableAccess,
_SymGetModuleBase,
0 ) )
{
....
}
Error 1 error C2664: 'BOOL
(DWORD,HANDLE,HANDLE,LPSTACKFRAME64,LPVOID,PREAD_PROCESS_MEMORY_ROUTINE64,PFUNCTION_TABLE_ACCESS_ROUTINE64,PGET_MODULE_BASE_ROUTINE64,PTRANSLATE_ADDRESS_ROUTINE64)' : cannot convert parameter 2 from 'int' to 'HANDLE' d:\Work\src\Lib\Util\StackWalkerTest.cpp
Error 2 error C2664: 'BOOL
(DWORD,HANDLE,HANDLE,LPSTACKFRAME64,LPVOID,PREAD_PROCESS_MEMORY_ROUTINE64,PFUNCTION_TABLE_ACCESS_ROUTINE64,PGET_MODULE_BASE_ROUTINE64,PTRANSLATE_ADDRESS_ROUTINE64)' : cannot convert parameter 3 from 'int' to 'HANDLE' d:\Work\src\Lib\Util\StackWalkerTest.cpp
Error 3 error C2664: 'BOOL
(DWORD,HANDLE,HANDLE,LPSTACKFRAME64,LPVOID,PREAD_PROCESS_MEMORY_ROUTINE64,PFUNCTION_TABLE_ACCESS_ROUTINE64,PGET_MODULE_BASE_ROUTINE64,PTRANSLATE_ADDRESS_ROUTINE64)' : cannot convert parameter 5 from 'int' to 'LPVOID'
Error 4 error C2664: 'BOOL
(DWORD,HANDLE,HANDLE,LPSTACKFRAME64,LPVOID,PREAD_PROCESS_MEMORY_ROUTINE64,PFUNCTION_TABLE_ACCESS_ROUTINE64,PGET_MODULE_BASE_ROUTINE64,PTRANSLATE_ADDRESS_ROUTINE64)' : cannot convert parameter 7 from 'int' to 'PFUNCTION_TABLE_ACCESS_ROUTINE64'
Error 5 error C2664: 'BOOL
(DWORD,HANDLE,HANDLE,LPSTACKFRAME64,LPVOID,PREAD_PROCESS_MEMORY_ROUTINE64,PFUNCTION_TABLE_ACCESS_ROUTINE64,PGET_MODULE_BASE_ROUTINE64,PTRANSLATE_ADDRESS_ROUTINE64)' : cannot convert parameter 6 from 'int' to 'PREAD_PROCESS_MEMORY_ROUTINE64'
Error 6 error C2664: 'BOOL
(DWORD,HANDLE,HANDLE,LPSTACKFRAME64,LPVOID,PREAD_PROCESS_MEMORY_ROUTINE64,PFUNCTION_TABLE_ACCESS_ROUTINE64,PGET_MODULE_BASE_ROUTINE64,PTRANSLATE_ADDRESS_ROUTINE64)' : cannot convert parameter 4 from 'int' to 'LPSTACKFRAME64'
Any help would be highly appreciated.
Thanks in advance.
John
|
|
|
|
|
John Oliviers wrote: Cannot convert parameter from 'int' to 'HANDLE'" on 64 bit windows for stackwalk64 code
You have to use these types[^] to cast.
Maxwell Chen
|
|
|
|
|
Thanks for your reply.
I have gone through the link, there is no type to cast int to HANDLE(long *). one more thing, both function declaration and parameter are of same type HANDLE, how did the type int came into the picture.
------
typedef BOOL (__stdcall * STACKWALKPROC)
( DWORD, HANDLE, HANDLE, LPSTACKFRAME, LPVOID,
PREAD_PROCESS_MEMORY_ROUTINE,PFUNCTION_TABLE_ACCESS_ROUTINE,
PGET_MODULE_BASE_ROUTINE, PTRANSLATE_ADDRESS_ROUTINE );
--------
_StackWalk64( IMAGE_FILE_MACHINE_AMD64,
GetCurrentProcess(),
GetCurrentThread(),
&sf,
pContext,
0,
_SymFunctionTableAccess,
_SymGetModuleBase,
0 )
Here 2nd parameter GetCurrentProcess() too returns HANDLE type. Then why this error occurs cannot convert parameter 2 from 'int' to 'HANDLE'
Could you please help me ?
Thanks in advance.
Thanks in advance.
John
|
|
|
|
|
Cast int to INT_PTR , then cast INT_PTR to HANDLE .
The principle is:
Under 64-bit environment, int is still 32 bits, but pointers are 64 bits.
There is alignment issue with number values...
-- modified at 14:04 Friday 24th August, 2007
Read this!
Rules for Using Pointers (64-bit Computing, MSDN)[^].
Maxwell Chen
|
|
|
|
|
Modified as HANDLE(INT_PTR(GetCurrentProcess())) but still getting compilation error that cannot convert int to HANDLE.
Thanks in advance.
John
|
|
|
|
|
Hmm... I don't have 64-bit compiler at home, otherwise I could give you a working code snippet...
Maxwell Chen
|
|
|
|
|
Just curious to know that why casting required on return value of GetCurrentProcess()?
GetCurrentProcess return value is HANDLE. I have some knowledge about 64 bit windows that int,long are 32 bit size whereas pointer is of size 64 bit, so casting is required between int,long to pointer and vice versa.
Why do you we need casting on this case ?
I really appreciate your helping tendency and your time.
Thanks in advance.
John
|
|
|
|
|
Yeah... HANDLE should also have been typedef ed...
Maxwell Chen
|
|
|
|
|
Yeah. It has been typedef as long*. But still no need for casting. Right?
Thanks in advance.
John
|
|
|
|
|
Wait...
Could you use [Go to definition], and paste the code snippet for
#ifdef AMD64 // Or x64 something
typedef PVOID HANDLE;
#else // WIN32
#endif
Maxwell Chen
|
|
|
|
|
Hi,
Previously suggestion is also not working. I still got stuck with compilation error.
Any suggestion would be highly appreciated.
Thanks in advance.
Thanks in advance.
John
|
|
|
|
|
I am at office now. I just copied your code snippet and compiled with VC++2005 Pro in x64 mode. It compiles without errors.
typedef BOOL (__stdcall * STACKWALKPROC)
( DWORD, HANDLE, HANDLE );
void main(int argc, char *argv[])
{
STACKWALKPROC _StackWalk64;
_StackWalk64 = (STACKWALKPROC)::GetProcAddress(NULL, "StackWalk64");
1>------ Build started: Project: KeyFD, Configuration: Release x64 ------
1>Compiling...
1>main.cpp
1>Linking...
1>Generating code
1>Finished generating code
1>Embedding manifest...
1>Build log was saved at "file://e:\Wrkshp\KeyFD\x64\Release\BuildLog.htm"
1>KeyFD - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Maxwell Chen
|
|
|
|
|
Hi,
I have a win 32 console application which will spawn a telnet window (Telnet.exe -l username) by using CreateProcess() API call and then pass the password (read from a file by the parent process) to the child process (Telnet window) using anonymous pipes. I have tried with the following code which i got from MSDN and partially modified , but could not get the result.
Please help me how can i pass data to telnet window so that it will logon automatically.
#include <stdio.h>
#include <windows.h>
#define BUFSIZE 4096
HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup,
hChildStdoutRd, hChildStdoutWr, hChildStdoutRdDup,
hInputFile, hStdout, hStdInput,hProcess;
PROCESS_INFORMATION piProcInfo;
BOOL CreateChildProcess(VOID);
VOID WriteToPipe(VOID);
VOID ReadFromPipe(VOID);
VOID ErrorExit(LPTSTR);
VOID ErrMsg(LPTSTR, BOOL);
DWORD main(int argc, char *argv[])
{
SECURITY_ATTRIBUTES saAttr;
BOOL fSuccess;
// Set the bInheritHandle flag so pipe handles are inherited.
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
// Get the handle to the current STDOUT.
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
hStdInput = GetStdHandle(STD_INPUT_HANDLE);
// Create a pipe for the child process's STDOUT.
if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0))
ErrorExit("Stdout pipe creation failed\n");
// Create noninheritable read handle and close the inheritable read
// handle.
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdoutRd,
GetCurrentProcess(), &hChildStdoutRdDup , DUPLICATE_SAME_ACCESS,
FALSE,
DUPLICATE_SAME_ACCESS);
if( !fSuccess )
ErrorExit("DuplicateHandle failed");
CloseHandle(hChildStdoutRd);
// Create a pipe for the child process's STDIN.
if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0))
ErrorExit("Stdin pipe creation failed\n");
// Duplicate the write handle to the pipe so it is not inherited.
fSuccess = DuplicateHandle(GetCurrentProcess(), hChildStdinWr,
GetCurrentProcess(), &hChildStdinWrDup, DUPLICATE_SAME_ACCESS,
FALSE, // not inherited
DUPLICATE_SAME_ACCESS);
if (! fSuccess)
ErrorExit("DuplicateHandle failed");
CloseHandle(hChildStdinWr);
// Now create the child process.
fSuccess = CreateChildProcess();
if (! fSuccess)
ErrorExit("Create process failed");
// Get a handle to the parent's input file.
if (argc == 1)
ErrorExit("Please specify an input file");
hInputFile = CreateFile(argv[1], GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
if (hInputFile == INVALID_HANDLE_VALUE)
ErrorExit("CreateFile failed\n");
// Write to pipe that is the standard input for a child process.
WriteToPipe();
// Read from pipe that is the standard output for child process.
// ReadFromPipe();
hProcess = piProcInfo.hProcess;
WaitForSingleObject(hProcess,INFINITE);
CloseHandle(piProcInfo.hProcess);
CloseHandle(piProcInfo.hThread);
return 0;
}
BOOL CreateChildProcess()
{
STARTUPINFO siStartInfo;
BOOL bFuncRetn = FALSE;
const char* lpAppName ="C:\\Windows\\System32\\Telnet.exe";
char* lpCmd = "open 10.41.37.239 -l guest";
// Set up members of the PROCESS_INFORMATION structure.
ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
// Set up members of the STARTUPINFO structure.
ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
siStartInfo.cb = sizeof(STARTUPINFO);
siStartInfo.hStdError = hChildStdoutRdDup;
siStartInfo.hStdOutput = hChildStdoutRdDup;
siStartInfo.hStdInput = hChildStdinWrDup;
// Create the child process.
bFuncRetn = CreateProcess(lpAppName,
lpCmd, // command line
NULL, // process security attributes
NULL, // primary thread security attributes
TRUE, // handles are inherited
CREATE_NEW_CONSOLE, // creation flags
NULL, // use parent's environment
NULL, // use parent's current directory
&siStartInfo, // STARTUPINFO pointer
&piProcInfo); // receives PROCESS_INFORMATION
if (bFuncRetn == 0)
{
ErrorExit("CreateProcess failed");
}
else
{
//CloseHandle(piProcInfo.hProcess);
//CloseHandle(piProcInfo.hThread);
return bFuncRetn;
}
return 0;
}
VOID WriteToPipe(VOID)
{
DWORD dwRead, dwWritten;
CHAR chBuf[BUFSIZE];
memset(chBuf,0,BUFSIZE);
// Read from a file and write its contents to a pipe.
ReadFile(hInputFile, chBuf, BUFSIZE, &dwRead, NULL);
WriteFile(hStdInput, chBuf, dwRead, &dwWritten, NULL);
// Close the pipe handle so the child process stops reading.
if (! CloseHandle(hChildStdinWrDup))
ErrorExit("Close pipe failed");
}
VOID ReadFromPipe(VOID)
{
DWORD dwRead, dwWritten;
CHAR chBuf[BUFSIZE];
memset(chBuf,0,BUFSIZE);
// Close the write end of the pipe before reading from the
// read end of the pipe.
if (!CloseHandle(hChildStdoutWr))
ErrorExit("CloseHandle failed");
// Read output from the child process, and write to parent's STDOUT.
ReadFile( hChildStdoutRdDup, chBuf, BUFSIZE, &dwRead,
NULL);
WriteFile(hStdout, chBuf, dwRead, &dwWritten, NULL);
}
VOID ErrorExit (LPTSTR lpszMessage)
{
fprintf(stderr, "%s\n", lpszMessage);
ExitProcess(0);
}
Thanks in advance.
Best Regards
Viswa
Visweswara Koduri
|
|
|
|
|
Hi, I'm developing a Windows Application with MFC and C++. I've added to the solution a Visual Studio Setup Project and it's installing everything ok. The problem is that now I want to configure the installer so it sets some permissions (I need "everyone full control") in my application folder, inside "Program Files", and I don't find how to do it.
I would really appreciate any clue that could help me to solve this problem.
Thanks!
Federico
PS: I'm using Visual Studio .NET 2003
|
|
|
|
|
i've wierd question in mind ...but as im naive to VC so askin it....is it possible to make a code portable for both embedded systems written in WINCE evc4 mfc and vc++ mfc in winx p
|
|
|
|
|
Yes definitely. I develop WinCE MFCish software and most of the development is done on XP. The very great majority of the code runs fine on XP built with VS2005 ( We used to use VC6 ) and on CE built with EVC4. You have to be a little careful which CRT functions you call as the CRT on CE is a bit limited and keep the MFC as simple as possible but it works without too many issues.
One thing to watch is that threading is handled completely differently on CE. It has a deterministic priority based threading model so no low priority thread ever gets a look in if a higher priority one is busy looping.
If you want portable code across CE and XP then develop for CE and port to XP is the way to go. EVC4 is also a stricter compiler in some ways than MSVC so you'll probably get unexpected warnings if you go the other way. I'm not sure why you'd want to do this except for development purposes but if you've got some killer app that everyone's goign to want on their PDAs and their desktops then why not.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Thanks alot for clearifying my query... actually my work is bit different , i am working for software development for a PC104 board( kind of embedded PC having processor ,seriral ports ,usb stuff like that) which got WINCE installed.. Now i am not getting the idea that for its software development Is EVC4.0 is compatibale or not...or its just for the PDA's...if U can Guide me it would be great..thanks
-- modified at 16:00 Friday 24th August, 2007
|
|
|
|
|
Yes, but WinCE is limited as you can see in help documentation.
Code for WinCE using EVC first, then migrate to XP. Should be painless.
Gary
|
|
|
|
|
Hi All,
I am using ListCtrl on my dialogbox. In this ListCtrl I load JPEG images
When I select any image in ListCtrl then selected image gets disapper. I want JPEG images should not be disapper when user select it. So if any have solution to this ,then please forward it.
Thanks in Advance
Atul
|
|
|
|
|