|
Use
tmp.Format("%g", var);
It should work.
|
|
|
|
|
|
And also you can use of wsprintf
|
|
|
|
|
Hi all!
Look.
typedef (WINAPI *TextOutAType)(HDC,int,int,LPCSTR,int);
TextOutAType oldTextOutAaddr=0;
//here is ourself function
BOOL WINAPI MyTextOutA(HDC hdc, int nXStart, int nYStart, LPCSTR string, int cbString)
{
MessageBox(0,string,"aha",0);
return oldTextOutAaddr(hdc,nXStart,nYStart,string,cbString);
}
BOOL HookApiTextOutA(const HMODULE hModule)
{
IMAGE_DOS_HEADER *pdos;
IMAGE_NT_HEADERS *pnt;
IMAGE_DATA_DIRECTORY *pSymbolTable;
IMAGE_IMPORT_DESCRIPTOR *pimport;
pdos=(IMAGE_DOS_HEADER*)hModule;
pnt=(IMAGE_NT_HEADERS*)((DWORD)pdos + pdos->e_lfanew);
pSymbolTable=&pnt->OptionalHeader.DataDirectory[1];
pimport=(IMAGE_IMPORT_DESCRIPTOR*)((DWORD)pdos + pSymbolTable->VirtualAddress);
while(pimport->FirstThunk){
IMAGE_THUNK_DATA *pold,*pnew;
pold = (IMAGE_THUNK_DATA*)((DWORD)pdos + pimport->OriginalFirstThunk);
pnew = (IMAGE_THUNK_DATA*)((DWORD)pdos + pimport->FirstThunk);
while(pold->u1.Function){
if(IMAGE_ORDINAL_FLAG != (pold->u1.Ordinal & IMAGE_ORDINAL_FLAG))
{
IMAGE_IMPORT_BY_NAME *pname;
pname = (IMAGE_IMPORT_BY_NAME*)((DWORD)pdos + *((DWORD*)pold));
PROC *ppfn=(PROC*)(pnew->u1.Function);
if(strcmp("TextOutA",(char*)pname->Name)==0)
{
oldTextOutAaddr=(TextOutAType)(ppfn); //here is system API "TextOutA" address
DWORD addr=(DWORD)MyTextOutA;
DWORD written=0;
DWORD oldProtect=NULL;
VirtualProtect(&pnew->u1.Function,sizeof(DWORD),PAGE_WRITECOPY,&oldProtect);
WriteProcessMemory(GetCurrentProcess(),&pnew->u1.Function, &addr,sizeof(DWORD), &written);
}
}
pold++;
pnew++;
}
pimport++;
}
return TRUE;
}
Now,when we use TextOutA,it's using "MyTextOutA" first in fact.
TO: Mark Salsbery,this isn't a joke.
IcyGaze, hope make friend with you~
|
|
|
|
|
It seems you could solve your problem
|
|
|
|
|
Haha! Cool
So that works for other processes?
Great to know there's no inter-process protection.
Geez no wonder UNIX guys make fun of Windows!
Nice one!
Mark
|
|
|
|
|
I would like to highlight the state of the button when pressed; i.e. show its 'ON' then reset its state when pressed again - 'OFF'. The following code does not quiet do what I require and I have looked at the methods and not found anything that would do.
void CTabOne::OnBnClickedRelayButton()<br />
{<br />
if(m_bRelayState)<br />
{<br />
m_cRelayButton.SetState(FALSE);<br />
m_cRelayButton.SetWindowTextA("OFF");<br />
m_bRelayState = false;<br />
}<br />
else<br />
{<br />
m_cRelayButton.SetState(TRUE);<br />
m_cRelayButton.SetWindowTextA("ON");<br />
m_bRelayState = true;<br />
}<br />
}
Any suggestions please.
Andy.
|
|
|
|
|
you should use either a Radio button or a checkbox button with the pushbutton style.
|
|
|
|
|
you can write this in your void CTabOne::OnBnClickedRelayButton() function
<br />
CString text;<br />
m_cRelayButton.GetWindowText(text);<br />
if(text == "OFF")<br />
{<br />
m_cRelayButton.SetState(TRUE);<br />
m_cRelayButton.SetWindowText(_T("ON"));<br />
} <br />
if(text == "ON")<br />
{<br />
mm_cRelayButton.SetState(FALSE);<br />
m_cRelayButton.SetWindowText(_T("OFF"));<br />
}<br />
i think this should do
hope that it would help
a.hemdan
|
|
|
|
|
If you have a button I sugget use of a checkbox.
|
|
|
|
|
Hi all,
I got this ErrorExit function of the msdn website, that will cause a messagebox to appear with a description of the last error that occured - if any. But the thing is I'm not sure, what the parameter value of LPTSTR lpszFunction must be ??? .
The function:
<code>
void ErrorExit(LPTSTR lpszFunction)
{
TCHAR szBuf[80];
LPVOID lpMsgBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
wsprintf(szBuf,
"%s failed with error %d: %s",
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, szBuf, "Error", MB_ICONHAND);
LocalFree(lpMsgBuf);
ExitProcess(dw);
}
</code>
Thanx in advance
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
By seing the code, it looks like it is the name of the function. So, basically, you call the function and check the return for an error, if there is an error, you call ErrorExit and pass the function name.
|
|
|
|
|
Thanx for the reply .... I thought that would be the case, but had to make sure,
cause I was receiving the same error message the whole time
"The specified module could not be found : error code 126".
May it be that the function (name) can not be found, or why would I receive the same error
messages although I'm using different applications and methods? :confused: ?
-- modified at 4:06 Thursday 12th October, 2006
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
From where is this message ? And, no, it's not a problem that a 'function' cannot be found: if the function didn't exist, you'll get a compilation error (no declaration and no definition) or a linker error (a declaration exist but no definition). If you could explain from where this message is coming and give more details, then we might help you. But here, we don't have any information...
|
|
|
|
|
O.k, I'll try and explain again. So I call the function and send it a value of a function
that exists and is part of the same application. Then I let a error occur so that I can test the function and the output the messagebox will give me. As shown below.
<br />
wsprintf(szBuf,"%s failed with error %d: %s",lpszFunction, dw, lpMsgBuf); <br />
MessageBox(NULL, szBuf, "Error", MB_ICONHAND); <br />
And the output of the messagebox is:
<functionname> specified module could not be found : error code 126
But the error I caused, as mentioned earlier, was something like this:
<br />
bool a = true;<br />
printf("Value of a %s :",a);<br />
Makes sense??
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
First, please don't use the pre tag to format simple text, it screws the look of your message (need to use the scroll bar to read your message). Pre is used to post code that is quite long.
Programm3r wrote: Then I let a error occur so that I can test the function and the output the messagebox will give me
Which error ? How do you provoke this error ? How do you call the function ? Please post some code because it is totally unclear what you are doing.
Programm3r wrote: bool a = true;
printf("Value of a %s :",a);
This won't set any value for the GetLastError function... It's just a bug but this won't change the return of GetLastError. Some functions only will save an error code that can be retrieved by GetLastError and printf is not. If the function save the error, then it is explicitely stated in the documentation.
Here you are simply retrieving your previous error.
|
|
|
|
|
Huh?
Besides the problems Cédric mentioned...
You say this code...
wsprintf(szBuf,"%s failed with error %d: %s",lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, szBuf, "Error", MB_ICONHAND);
...produced this in a message box:
specified module could not be found : error code 126
???
And what happened here:
bool a = true;
printf("Value of a %s :",a);
Isn't printf going to expect "a" to be a pointer to a character string?
That's not good
Mark
|
|
|
|
|
In my start-up i have a splash-screen which waits for 30 seconds and then the main application starts up.
Now i have to do this :--
Within this interval if any keyboard key is pressed i want to hide/close the splash-screeen and move to the application directly
I have implemented the splash-screen as :
BOOL CSplashWnd::ShowSplashScreen(UINT uTimeOut, UINT uBitmapID, CWnd* pParentWnd /*= NULL*/)
{
ASSERT(uTimeOut && uBitmapID);
if (!m_bShowSplashWnd || m_pSplashWnd != NULL) {
return FALSE;
}
// Allocate a new splash screen, and create the window.
m_pSplashWnd = new CSplashWnd;
if (!m_pSplashWnd->m_bitmap.LoadBitmap(uBitmapID)) {
return FALSE;
}
BITMAP bm;
m_pSplashWnd->m_bitmap.GetBitmap(&bm);
CString strWndClass = AfxRegisterWndClass(0,
AfxGetApp()->LoadStandardCursor(IDC_ARROW));
if (!m_pSplashWnd->CreateEx(0, strWndClass, NULL, WS_POPUP | WS_VISIBLE,
0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL))
{
TRACE0("Failed to create splash screen.\n");
delete m_pSplashWnd;
return FALSE;
}
// Center the window.
m_pSplashWnd->CenterWindow();
m_pSplashWnd->UpdateWindow();
// Set a timer to destroy the splash screen.
m_pSplashWnd->SetTimer(1, uTimeOut, NULL);
return TRUE;
}
where CSplashWnd is derived from CWnd
Can any body plz tell me how to do it?
|
|
|
|
|
Well one simple solution would be using WM_KEYDOWN message or OnKeyDown() in MFC which i hope you already know.
Another way out is to use Keyboard Hook. When the splash screen is created, create a keyboard hook and use a callback function to trap any(really any) key pressed. Destroy the Splash Screen window in the callback function. And also don't forget to unhook the Keyboard callback as soon as the splash screen is destroyed (important).
Refer to following functions in MSDN:
SetWindowsHookEx()
KeyboardProc()
UnhookWindowsHookEx()
|
|
|
|
|
Good morning
how can I add a bitmap into a button
|
|
|
|
|
Hi,
Hope this might help.
<a href="http://www.flounder.com/bitmapbutton.htm">http:
<a href="http://www.codeguru.com/cpp/controls/buttonctrl/bitmapbuttons/article.php/c5163/">http:
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
first go to button properties and change the properties at the styles tab to
icon.
Then create a CButton variable for the IDC_BUTTON name
and then just use seticon()
|
|
|
|
|
See CButton::SetBitmap on MSDN it has an example.
|
|
|
|
|
How to send Trace message to file instead of debugger in Visual Studio 6.00?
ccp
|
|
|
|
|
Hi,
Hope this might help.
<a href="http://www.codeproject.com/debug/xytrace.asp?print=true">http:
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|