|
If you read here[^], you find WM_CTLCOLORDLG[^] and WM_CTLCOLORSTATIC[^], maybe try handling these messages instead of WM_CTLCOLOR, aside of that, the documentation also states this for WM_CTLCOLOR:
lParam
A handle to a child window (control).
This is the handle of the control asking for the color information, you could use that to filter out the controls you wish to change the background color.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Thanks,
please tell how can i color the background of formview.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
hi All
I m writing a directshow application in vc++ 2005. My problem is that I m trying to merge two or more videos clips but i can't get any help from anywhere please help me how do i this.
please help me
Thanks in advance
|
|
|
|
|
What do you mean by merge?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I'm new to C++.
I try to build the Simple application in Microsoft's detours project in VS08.
Detours is used to inject dlls into API processes or into applications. You can find it at:
http://research.microsoft.com/en-us/projects/detours/
I managed to build:
detoured.dll
detours.lib
Simple.dll (That's the hook)
setdll.exe (The program that injects the hook)
sleep5.exe (The exe that uses the hooked API)
When I try to run the hook:
setdll /d:simple.dll
I get the error message:
Error: simple.dll does not export function with ordinal #1.
It's because Simple.dll doesn't export anything.
Detoured.dll does export the function detoured.
detoured.h:
#ifdef DETOURED_EXPORTS
#define DETOURED_API __declspec(dllexport)
#else
#define DETOURED_API __declspec(dllimport)
#endif
HMODULE DETOURED_API WINAPI Detoured();
detoured.cpp:
#include <windows.h>
#include "detoured.h"
static HMODULE s_hDll;
HMODULE WINAPI Detoured()
{
return s_hDll;
}
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
(void)reserved;
if (dwReason == DLL_PROCESS_ATTACH) {
s_hDll = hinst;
DisableThreadLibraryCalls(hinst);
}
return TRUE;
}
</windows.h>
But simple.cpp is just this in the package:
#include <stdio.h>
#include <windows.h>
#include "detours.h"
static LONG dwSlept = 0;
static VOID (WINAPI * TrueSleep)(DWORD dwMilliseconds) = Sleep;
VOID WINAPI TimedSleep(DWORD dwMilliseconds)
{
DWORD dwBeg = GetTickCount();
TrueSleep(dwMilliseconds);
DWORD dwEnd = GetTickCount();
InterlockedExchangeAdd(&dwSlept, dwEnd - dwBeg);
}
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
LONG error;
(void)hinst;
(void)reserved;
if (dwReason == DLL_PROCESS_ATTACH) {
printf("simple.dll: Starting.\n");
fflush(stdout);
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)TrueSleep, TimedSleep);
error = DetourTransactionCommit();
if (error == NO_ERROR) {
printf("simple.dll: Detoured Sleep().\n");
}
else {
printf("simple.dll: Error detouring Sleep(): %d\n", error);
}
}
else if (dwReason == DLL_PROCESS_DETACH) {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)TrueSleep, TimedSleep);
error = DetourTransactionCommit();
printf("simple.dll: Removed Sleep() (result=%d), slept %d ticks.\n",
error, dwSlept);
fflush(stdout);
}
return TRUE;
}
</windows.h></stdio.h>
So I tried to make it similar to detoured.dll:
simple.h:
#ifdef SIMPLE_EXPORTS
#define SIMPLE_API __declspec(dllexport)
#else
#define SIMPLE_API __declspec(dllimport)
#endif
HMODULE SIMPLE_API WINAPI Simple();
Simple.cpp:
#include <stdio.h>
#include <windows.h>
#include "..\detours\detours.h"
#define SIMPLE_EXPORTS
static LONG dwSlept = 0;
static VOID (WINAPI * TrueSleep)(DWORD dwMilliseconds) = Sleep;
static HMODULE s1_hDll;
HMODULE WINAPI Simple()
{
return s1_hDll;
}
VOID WINAPI TimedSleep(DWORD dwMilliseconds)
{
DWORD dwBeg = GetTickCount();
TrueSleep(dwMilliseconds);
DWORD dwEnd = GetTickCount();
InterlockedExchangeAdd(&dwSlept, dwEnd - dwBeg);
}
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
LONG error;
(void)reserved;
if (dwReason == DLL_PROCESS_ATTACH) {
s1_hDll = hinst;
printf("simple.dll: Starting.\n");
fflush(stdout);
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)TrueSleep, TimedSleep);
error = DetourTransactionCommit();
if (error == NO_ERROR) {
printf("simple.dll: Detoured Sleep().\n");
}
else {
printf("simple.dll: Error detouring Sleep(): %d\n", error);
}
}
else if (dwReason == DLL_PROCESS_DETACH) {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)TrueSleep, TimedSleep);
error = DetourTransactionCommit();
printf("simple.dll: Removed Sleep() (result=%d), slept %d ticks.\n",
error, dwSlept);
fflush(stdout);
}
return TRUE;
}
</windows.h></stdio.h>
But Simple.dll still doesn't export anything, because SIMPLE_EXPORTS is undefined. How to build this project correctly?
|
|
|
|
|
Put the line
#define SIMPLE_EXPORTS
before the line
#include "simple.h"
«_Superman_»
|
|
|
|
|
Thanks, that worked. But I still don't know, why detoured.dll exported without "#define DETOURED_EXPORTS".
|
|
|
|
|
The pre-processor definitions can also be given as a project settings instead of putting it inside the code file.
Check the PreprocessorDefinitions key inside .vcproj file.
It could be there.
«_Superman_»
|
|
|
|
|
Bingo!
I copied it from an other project and I forgot about it. Man, it's so complicated!
|
|
|
|
|
Hi,
I wanted to open a media file thru 'IWMMetadataEditor' struct variable in C++. After opening this file , I am initialising the 'IWMHeaderInfo' struct variable so that I can collect the meta data of media file(audio/video) through it's properties..
Can anybody tell me how to get the file name which is being played in WMP which will be input to 'IWMMetadataEditor' (pEditor->Open(???))
Regards,
Supriya Tonape.
|
|
|
|
|
Hi all!
I'm on a ciphering Win32 project and i have the following problem:
I have created the thread and I don't use SendMessage calls inside the thread procedure. I use PostMessage with user defined messages to display progress information on the main window. But when the thread starts the whole program dead locks. Is that means that it needs a Sleep function or something else that you could suggest me?
Thanks!
|
|
|
|
|
Show code. Could be anything, you could -maybe- be flooding your GUI thread with messages, or maybe your thread is a run-away thead (it eats up all the CPU time so your GUI has no chanche to do anything), or it could be a deadlock caused by a cross-lock problem, or or or...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
The code is:
void DataCryptMain ::ProcessCrypt()
{
...
cryptthread.Start(_staticThreadProc, this)
...
}
DWORD WINAPI _staticThreadProc(LPVOID lpData)
{
DataCryptMain *dcr = reinterpret_cast<datacryptmain>(lpData);
return dcr->CryptThreadProc(NULL);
}
DWORD WINAPI DataCryptMain::CryptThreadProc(LPVOID lpData)
{
int iErrorOrInfo = INFO_PROCESS_DONE;
iErrorOrInfo = CryptoRijnDaelProcess();
Notify_Progress_GUI(NOTIFY_PROGRESS_END, NULL, iErrorOrInfo);
return 0;
}
void DataCryptMain::Notify_Progress_GUI(int iNotificationType, WPARAM wParam, LPARAM lParam)
{
if (iNotificationType == NOTIFY_PROGRESS_RUNNING)
{
PostMessage(hWnd, WM_PROGRESS_RUNNING, wParam, lParam);
}
else
{
PostMessage(hWnd, WM_PROGRESS_END, wParam, lParam);
}
}
bool _ProgressBarProc(PRBDATA *prbdata)
{
DataCryptMain *dcr = reinterpret_cast<datacryptmain>(prbdata->lpOtherData);
return dcr->ProgressBarProc(prbdata);
}
bool DataCryptMain::ProgressBarProc(PRBDATA *prbdata)
{
if (cryptthread.WaitToExit()) return TRUE;
PRBDATA *_prbdata = new PRBDATA;
memcpy(_prbdata, prbdata, sizeof(PRBDATA));
Notify_Progress_GUI(NOTIFY_PROGRESS_RUNNING, NULL, (LPARAM)_prbdata);
return FALSE;
}
int DataCryptMain::CryptoRijnDaelProcess()
{
int iErrorOrInfo = OK;
RijnDaelCrypto *rdc = new RijnDaelCrypto;
...
...
SetProgressFunc(_ProgressBarProc, (LPVOID)this);
------------------- Here this function loops through the file encryption
if (rdc->Encrypt(wcgFileNameIn, wcgFileNameOut, cryptParams.iCipherMode) < 0)
iErrorOrInfo = ERR_PROCESS_STOPPED_BY_USER;
_DELETE(rdc);
return iErrorOrInfo;
}
bool DataCryptMain::OnProgressRunning(WPARAM wParam, LPARAM lParam)
{
float fPercent[3];
char sTemp[64];
PRBDATA *prbdata = reinterpret_cast<prbdata>(lParam);
fPercent[0] = ((float)prbdata->iReadBytesIncByFuncRead / (float)prbdata->dwSize) * 100.0f;
fPercent[1] = ((float)prbdata->iBlocksIncrement / (float)prbdata->iBlocksNum) * 100.0f;
fPercent[2] = (fPercent[0] + fPercent[1]) / 2;
SendDlgItemMessage(hWnd, IDC_PROGRESSSTATUS, PBM_SETPOS, (WPARAM)fPercent[2], 0);
sprintf_s(sTemp, "%0.1f %%", fPercent[2]);
SetDlgItemText(hWnd, IDC_PERCENT1, sTemp);
sprintf_s(sTemp, "%d bytes", prbdata->dwSize);
SetDlgItemText(hWnd, IDC_FILESIZE, sTemp);
sprintf_s(sTemp, "%d bytes", prbdata->iReadBytesIncByFuncRead);
SetDlgItemText(hWnd, IDC_READBYTES, sTemp);
sprintf_s(sTemp, "%d block/s", (int)prbdata->iBlocksIncrement);
SetDlgItemText(hWnd, IDC_BLOCKSPROCESSED, sTemp);
_DELETE(prbdata);
return FALSE;
} </prbdata></datacryptmain></datacryptmain>
modified on Thursday, January 29, 2009 9:03 AM
|
|
|
|
|
At the first look i don't see any obvious errors (althorough they might be there and i am a blind mouse). Try pausing your (DEBUG build) programs's execution in VS (with the pause button on the toolbar for example) and check what your threads are doing, you might find out what your GUI thread seems to be waiting for. You could also try placing a sleep here and there to see if the situation gets any better or not, if it does then most likely it's the "run away thread" thing, or try removing the PostMessage from the thread temporarily, or make it Post a message every 100th time it is called and run your program to see if your GUI is reponsive or not, if it is, than it is likely you are flooding it with the "status-report" messages.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
If it works as i've shown it uses about 86% of CPU, the changes are displayed but I can't, for example, move the window or push a button.
If i place a sleep function then it works OK
About the first you'said, i didn't understand "you might find out what your GUI thread seems to be waiting for"
|
|
|
|
|
Dennis L wrote: About the first you'said, i didn't understand "you might find out what your GUI thread seems to be waiting for"
I mean, when you break the execution of your program you can check out where that execution was in your code (assuming you have debug information) so you can see where your GUI thread gets stuck, the debugger shows you, it will point at the place where the program was halted. But if everything works with a sleep then for now you can forget about this part.
Where did you place the sleep? Does this sleep slow down the thread that is posting the messages towards your GUI thread? If yes, then i'd say you are flooding your GUI with messages. Try to decrease the number of messages sent to your GUI, for example, send only every 10th status report, or check when you sent the last report and if a given amount of time (like,for exaple 100 ms) didn't ellapse yet then skip sending the message, OR perform the percentage calculation in your thread and only send a message towards the GUI if the new percentage is different from the previous one, this should reduce the messages heading towards the GUI to not more than around a 100 messages per run, which shouldn't be too much, unless you are some very low end hardware.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I have placed the Sleep in the progress callback function as:
bool DataCryptMain::ProgressBarProc(PRBDATA *prbdata)
{
...
Notify_Progress_GUI(NOTIFY_PROGRESS_RUNNING, NULL, (LPARAM)_prbdata);
Sleep(1);
}
You said: "Try to decrease the number of messages sent to your GUI, for example, send only every 10th status report, or check when you sent the last report and if a given amount of time (like,for exaple 100 ms) didn't ellapse yet then skip sending the message, OR perform the percentage calculation in your thread and only send a message towards the GUI if the new percentage is different from the previous one, this should reduce the messages heading towards the GUI to not more than around a 100 messages per run, which shouldn't be too much, unless you are some very low end hardware"
All these i'll try them by using PostMessage or SendMessage?
|
|
|
|
|
The code you posted is horribly formatted and missing < and > symbols and what's between them.
Steve
|
|
|
|
|
Please post code snippets..
Regards,
Sandip.
|
|
|
|
|
I wrote a simple app that hooks WH_MOUSE events. The application receives a stream of events when the mouse is moved over most windows. However it does not get any events from:
- the Command (MSDOS) application
- the menu bar of old (16-bit?) applications such as Calculator or Paint.
- the title bar of all apps
How can catch mouse messages in these cases?
--
Goop
|
|
|
|
|
Please mention the problem clearly.
|
|
|
|
|
Mmm, I thought I had
It seems that the Command/MSDOS window is capturing mouse movements before my application. As my application was started from that window, I assumed that my app would be earlier in the hook list and therefore receive messages first. But the app does not see the mouse movements for the Command window.
I guess the problem goes deeper, because I want to see ALL mouse movements, wherever my hook is in the hooks list. So I guess I need to get the messages before any hook functions.
Hope that is clearer
Regards
--
Goop
|
|
|
|
|
Command/DOS applications do not have a message loop.
But you should get mouse messages on title bars of Windows apps using this hook.
If not you should try WH_MOUSE_LL .
«_Superman_»
|
|
|
|
|
Thanks for your reply. You are right, messages really are received on title bars. I needed to test for the Non-Client messages, WM_NCRBUTTONDOWN, as well as for WM_RBUTTONDOWN. This also fixes it for the menu bars of Calculator/Paint.
But the Command/MSDOS window still somehow captures messages - I see none of them, even for the title bar. How does it do this (ie. which API)? Does this mean that keyloggers also cannot intercept text typed into the Command window? This would imply that an application should grab the keyboard events directly (as in Command) to avoid snooping, eg during password entry.
Regards
--
Goop
|
|
|
|
|
Hi
In my project, the controls have to be created depending on the user input, which will be made at the beginning.
Depending on the user input, the controls have to be created at Runtime.
How to create Resource ID for Form View, Static Control, Tool Bar, Menu, Dialog Bar in VC++ at the Runtime?
Thank you
Preethi
|
|
|
|
|