|
I am facing problem in reading data from clipboard with 16-bit settings. I able to read and save image in 32 bit settings. I want to convert 16-bit clipboard image to 24-bit or 32-bit BMP file.
Sethuraman.K
|
|
|
|
|
If you want to do the conversion yourself, the docs for the BITMAPINFOHEADER[^]
struct explains the various ways 16-bit pixel data is formatted.
You can also use GDI or GDI+ to convert the format by drawing the bitmap to a new bitmap.
It's a shame the GDI+ Bitmap::ConvertFormat() method isn't available except on Vista+.
With that, you could do the conversion in a couple lines of code
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hai,
I am Calling a Dialog from a main Dialog & I want to get the text typed in that dialog to the main dialog
Thanks In Advance
-- modified at 7:43 Tuesday 15th May, 2007
|
|
|
|
|
Maybe this code will be helpful for you
CMain* m_Main=(CMain*)GetParent();
m_Main->variables(on the another dialog)
|
|
|
|
|
Hi,
U can access the child dialog variable from main dialog.
eg:
CChildDlg cdlg;
cdlg.DoModal();
var_MainDlg=dclg.var=//var should declare in CChildDlg as public
-- modified at 7:59 Tuesday 15th May, 2007
If U Have Interest, U Can...
Sherin Iranimose
|
|
|
|
|
IS it possible in the reverse manner . . .
child to access parents variables
Proud To Be an Indian
|
|
|
|
|
Keep the text in a string variable [inside the child dialog]. Then inside the main dialog, get the string value when the child is closed. It might be smth like this;
CMySecondDlg dlg;
if (dlg.DoModal() == IDOK)
{
CString text = dlg.m_strText;
}
If your second dialog is modeless, you should get the main dialog handler (GetParent or pass it directly) and do PostMessage inside the child dialog.
--
=====
Arman
|
|
|
|
|
Use a memory mapped file.
|
|
|
|
|
What are function pointers?
i have heard about the chat *ptr.
But what is function pointer.
i read it in the vb.net article based on the delegates.
the line that article included is
"A delegate is a reference type that refers to a Shared method of a type or to an instance method of an object. The closest equivalent of a delegate in other languages is a function pointer, but whereas a function pointer can only reference Shared functions, a delegate can reference both Shared and instance methods."
|
|
|
|
|
|
I give you an example:
int mySqr(int i){ return i*i;}
int myAbs(int i){ return i < 0 ? -i : i;}
int main(int argc, char* argv[])
{
int (*pFun)(int);
int i=-5;
pFun = mySqr;
printf( "pFun=mySqr\n");
printf( "pFun(%d)=%d\n", i, pFun(i));
pFun = myAbs;
printf( "pFun=myAbs\n");
printf( "pFun(%d)=%d\n", i, pFun(i));
getchar();
return 0;
}
in the code above, pFun is a function pointer, i.e. a variable that can hold the address of a function, allowing to make calls to different functions dynamically.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
I'm working on a fatal error which make our application crash! I can not reproduce it in my environment, so I tried to get the Dr.Watson's dump log and it indicate such error:
380861d0 da742430 fidiv dword ptr [esp+0x30] ss:00c0977f=a0b900c1
FAULT ->380861d4 d95e58 fstp dword ptr [esi+0x58] ds:00c0983a=c1eed825
I have found the code corresponding to the asm instruction:
i = float (m_rect.Width()) / float(m_rect.Height());
Just two floats' division!
I'm sure denominator is not Zero! I can not understand why the fstp give such a fatal message:
Exception code: c0000090 (FLT_INVALID_OPERATION)
Who can give me advices? Thanks a lot, a lot...
|
|
|
|
|
Are you using VC7.1 or VC8 release canditate. As far as I remember, this is a bug on those IDEs.
--
=====
Arman
|
|
|
|
|
Im tryin to write a VC++ application to encrypt any file the user selects.
I have done it for a binary file. But have no idea about how to do it if its a video or picture file.
What do i do?
Jesus Loves Us Just the way we are! Invite Him into your life today!
|
|
|
|
|
No difference. Those files are binary too.
--
=====
Arman
|
|
|
|
|
But then wat about loading the contents of the file to encrypt and stuff...
do i do it the same way??
cuz i tried using the same method and the encrypted stuff is not the same as the source...
Jesus Loves Us Just the way we are! Invite Him into your life today!
|
|
|
|
|
Then what's the purpose of your encryption? What encryption method are you using?
--
=====
Arman
|
|
|
|
|
This is the code snippet for the original binary file encryption program.
I just need to convert this so that it can accept any file. Im using the RIjnael class for the encryption and decryption.
The purpose is to encrypt and decrypt any file using the same key.
<br />
void CFileEnDecryptionDlg::Char2Hex(const unsigned char ch, char *szHex)<br />
{<br />
unsigned char byte[2];<br />
byte[0] = ch/16;<br />
byte[1] = ch%16;<br />
for(int i=0; i<2; i++)<br />
{<br />
if(byte[i] >= 0 && byte[i] <= 9)<br />
szHex[i] = '0' + byte[i];<br />
else<br />
szHex[i] = 'A' + byte[i] - 10;<br />
}<br />
szHex[2] = 0;<br />
}<br />
<br />
void CFileEnDecryptionDlg::Hex2Char(const char *szHex, unsigned char &rch)<br />
{<br />
rch = 0;<br />
for(int i=0; i<2; i++)<br />
{<br />
if(*(szHex + i) >='0' && *(szHex + i) <= '9')<br />
rch = (rch << 4) + (*(szHex + i) - '0');<br />
else if(*(szHex + i) >='A' && *(szHex + i) <= 'F')<br />
rch = (rch << 4) + (*(szHex + i) - 'A' + 10);<br />
else<br />
break;<br />
}<br />
}<br />
<br />
<br />
<br />
void CFileEnDecryptionDlg::CharStr2HexStr(const char *pucCharStr, char *pszHexStr, int iSize)<br />
{<br />
int i;<br />
char szHex[3];<br />
pszHexStr[0] = 0;<br />
for(i=0; i<iSize; i++)<br />
{<br />
Char2Hex(pucCharStr[i], szHex);<br />
strcat(pszHexStr, szHex);<br />
}<br />
}<br />
<br />
void CFileEnDecryptionDlg::HexStr2CharStr(const char *pszHexStr, char *pucCharStr, int iSize)<br />
{<br />
int i;<br />
unsigned char ch;<br />
for(i=0; i<iSize; i++)<br />
{<br />
Hex2Char(pszHexStr+2*i, ch);<br />
pucCharStr[i] = ch;<br />
}<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnEncryptBtn() <br />
{<br />
<br />
h = 0;<br />
<br />
tag:<br />
<br />
CWnd *input, *output, *result; <br />
CWnd *msgbox;<br />
CString key,text, message;<br />
char buf[300],hex[600]; <br />
<br />
memset(buf,0,300);<br />
memset(hex,0,600);<br />
<br />
<br />
input = GetDlgItem(IDC_SOURCE_FILE_CONTENTS);<br />
output = GetDlgItem(IDC_KEY);<br />
msgbox = GetDlgItem(IDC_MSGBOX);<br />
result = GetDlgItem(IDC_RESULT);<br />
<br />
result->SetWindowText("");<br />
<br />
output->GetWindowText(key);<br />
input->GetWindowText(text);<br />
<br />
int flag = 0;<br />
if(key.GetLength()==0)<br />
{<br />
output->SetWindowText("1234567890123456");<br />
msgbox->SetWindowText("Default Value of key used");<br />
<br />
}<br />
<br />
if(text.GetLength() == 0){<br />
input->SetWindowText("Scolis Technologies Pvt. Ltd.");<br />
<br />
output->GetWindowText(key);<br />
input->GetWindowText(text);<br />
flag = 1;<br />
}<br />
<br />
<br />
<br />
rijndael.MakeKey ((LPCTSTR)key);<br />
<br />
int length = text.GetLength();<br />
<br />
<br />
if((text.GetLength() % 16) != 0)<br />
{<br />
<br />
while((text.GetLength() % 16) != 0)<br />
{<br />
text.Insert(length,'0');<br />
length++;<br />
}<br />
if (flag == 0)<br />
msgbox->SetWindowText("Zeroes have been padded to make the length of string divisible by 16 ");<br />
else<br />
<br />
msgbox->SetWindowText("I'm taking default values since you provided none. Note: Zeroes have been padded to make the length of string divisible by 16");<br />
} <br />
<br />
rijndael.Encrypt((LPCTSTR)text, buf, text.GetLength());<br />
<br />
CharStr2HexStr(buf, hex, strlen(buf));<br />
result->SetWindowText(hex);<br />
<br />
if (h == 0)<br />
{ <br />
h=1; <br />
goto tag;<br />
}<br />
<br />
<br />
CFile OFile;<br />
OFile.Open(m_DestinationFileName, CFile::modeWrite | CFile :: modeCreate);<br />
<br />
CArchive ar(&OFile, CArchive::store);<br />
ar << (CString)hex;<br />
ar.Close();<br />
<br />
memset(buf,0,300);<br />
memset(hex,0,600);<br />
<br />
<br />
OFile.Close();<br />
msgbox -> SetWindowText("Encrypted Content has been Written to file!");<br />
<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnDecryptBtn() <br />
{<br />
CWnd *key,*cipher,*result, *msgbox;<br />
CString key_text, cipher_text;<br />
char buf[300],buf1[300];<br />
<br />
key_text = '\0';<br />
cipher_text = '\0';<br />
key = NULL;<br />
<br />
memset(buf,0,300);<br />
memset(buf1,0,300);<br />
<br />
<br />
<br />
key = GetDlgItem(IDC_KEY);<br />
cipher = GetDlgItem(IDC_SOURCE_FILE_CONTENTS);<br />
result= GetDlgItem(IDC_RESULT);<br />
msgbox = GetDlgItem(IDC_MSGBOX);<br />
<br />
<br />
key->GetWindowText(key_text);<br />
cipher->GetWindowText(cipher_text);<br />
<br />
if( cipher_text.GetLength()==0){<br />
cipher->SetWindowText("C9377FD2C4D57AA3BD84B247EF0995264CB4378A4E0EA21DA98B7016F64B121C");<br />
cipher->GetWindowText(cipher_text);<br />
}<br />
<br />
<br />
if(key_text.GetLength() == 0 ){<br />
msgbox->SetWindowText("Ciphertext or Key, decrypting using default values");<br />
key->SetWindowText("1234567890123456");<br />
key->GetWindowText(key_text);<br />
<br />
}<br />
<br />
<br />
<br />
rijndael.MakeKey ((LPCTSTR)key_text);<br />
<br />
HexStr2CharStr((LPCTSTR)cipher_text, buf1, cipher_text.GetLength ());<br />
<br />
rijndael.Decrypt((LPCTSTR)buf1, buf, strlen(buf1));<br />
<br />
result->SetWindowText(buf);<br />
<br />
CFile OFile;<br />
OFile.Open(m_DestinationFileName, CFile::modeWrite | CFile :: modeCreate);<br />
<br />
CArchive ar(&OFile, CArchive::store);<br />
ar << (CString)buf;<br />
ar.Close();<br />
<br />
memset(buf,0,300);<br />
memset(buf1,0,300);<br />
<br />
OFile.Close();<br />
msgbox -> SetWindowText("Decrypted Content has been Written to file!");<br />
<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnDefaultBtn() <br />
{<br />
m_SourceFileContents="Scolis Technologies Pvt. Ltd.";<br />
<br />
m_Key= "1234567890123456";<br />
CWnd *result, *msgbox;<br />
<br />
result= GetDlgItem(IDC_RESULT);<br />
msgbox = GetDlgItem(IDC_MSGBOX);<br />
<br />
result->SetWindowText("");<br />
<br />
UpdateData(FALSE);<br />
msgbox->SetWindowText("Default Contents Entered");<br />
<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnInBrowse() <br />
{<br />
CFile TextFile;<br />
<br />
char strFilter[]={ "Binary Files (*.bin)|*.bin||" };<br />
<br />
CFileDialog FileDlg( TRUE, "*.bin", NULL, 0, strFilter);
<br />
if( FileDlg.DoModal() == IDOK)<br />
{<br />
if( TextFile.Open(FileDlg.GetFileName(), CFile::modeRead) == FALSE )<br />
{<br />
return;<br />
}<br />
<br />
CArchive ar( &TextFile, CArchive::load);
ar >> m_SourceFileContents;
ar.Close();<br />
}<br />
else<br />
{<br />
return;<br />
}<br />
<br />
TextFile.Close();<br />
<br />
this -> UpdateData(FALSE);<br />
<br />
<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnOutBrowse() <br />
{<br />
CWnd *name;<br />
<br />
name = GetDlgItem(IDC_DESTINATION_FILE_NAME);<br />
<br />
CFile TextFile;<br />
<br />
char strFilter[]={ "Binary Files (*.bin)|*.bin||" };<br />
<br />
CFileDialog FileDlg( TRUE, "*.bin", NULL, 0, strFilter);
<br />
if( FileDlg.DoModal() == IDOK)<br />
{<br />
if( TextFile.Open(FileDlg.GetFileName(), CFile::modeWrite | CFile::modeCreate) == FALSE )<br />
{<br />
return;<br />
}<br />
m_DestinationFileName = FileDlg.GetPathName();<br />
<br />
}<br />
else<br />
{<br />
return;<br />
}<br />
<br />
TextFile.Close();<br />
<br />
this -> UpdateData(FALSE);<br />
<br />
}<br />
<br />
void CFileEnDecryptionDlg::OnCancel() <br />
{<br />
exit(0);<br />
<br />
CDialog::OnCancel();<br />
}
Jesus Loves Us Just the way we are! Invite Him into your life today!
|
|
|
|
|
Ok, if your purpose is solely encrypt/decrypt, then this code will do. Only do open the file in binary mode, read bytes from there and pass them to your enryption algorythm. If after encryption and a corresponding decryption you cannot get what you had before, than your algorythms are wrong; no matter you have used video, image or other types of files.
--
=====
Arman
|
|
|
|
|
hey thanks duude
it worked
Jesus Loves Us Just the way we are! Invite Him into your life today!
|
|
|
|
|
Hi All,
Currently I'm developing a tool, for that purpose i have to know all other processes running on the computer and achieve the handle of specified process.There are some functions in VB and but i need to write in MFC only... How can get it?
bye
kamalesh
kamalesh
|
|
|
|
|
See the APIs Process32First, Process32Next from include header <tlhelp32.h>
--
=====
Arman
|
|
|
|
|
|
Does EnumProcesses helpful?
|
|
|
|
|
Pls Find answer to your code....
I dont know how i can attach a file to code project message. there fore please copy from the message...
/* Header File for the Class /*
#include "stdafx.h"
#include "psapi.h"
#pragma pack(16)
#define FOUND_WJRU 0
#define WJRU_NOTFOUND 1
class CProcessMonitor
{
private:
DWORD mAvailableProcesses[1024], cbNeeded, cProcesses;
public:
UINT getTotalAvailableProcesses();
UINT getProcessTimes();
BOOL FindProcessandMemoryDetails(DWORD processID,CString Processname,PROCESS_MEMORY_COUNTERS& psmemCounters);
BOOL IsProcessMatchingNameAndID( DWORD processID, UINT index );
HANDLE GetProcessHandle(DWORD processID, CString Processname);
HANDLE GetHandleToProcess(CString Processname);
void GetJRUStatus(int&nStatus, PROCESS_MEMORY_COUNTERS& psMemInfo);
};
#pragma pack()
/// CPLUSS PLUS FILE....
#include "stdafx.h"
#include "psapi.h"
#include "EnumProcess.h"
BOOL CProcessMonitor::IsProcessMatchingNameAndID( DWORD processID, UINT index )
{
char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH] = "Wjru.exe";
PROCESS_MEMORY_COUNTERS psmemCounters;
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
if(strcmp(szProcessName,szTargetProcessName) ==0)
{
GetProcessMemoryInfo(hProcess,&psmemCounters,sizeof(PROCESS_MEMORY_COUNTERS));
return TRUE;
}
else
{
return FALSE;
}
}
}
return FALSE;
}
BOOL CProcessMonitor::FindProcessandMemoryDetails(DWORD processID, CString Processname,PROCESS_MEMORY_COUNTERS& psmemCounters)
{
char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH];
strcpy(szTargetProcessName,Processname.GetBuffer(50));
Processname.ReleaseBuffer();
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
if(strcmp(szProcessName,szTargetProcessName) ==0)
{
GetProcessMemoryInfo(hProcess,&psmemCounters,sizeof(PROCESS_MEMORY_COUNTERS));
return TRUE;
}
else
{
return FALSE;
}
}
}
return FALSE;
}
void CProcessMonitor::GetJRUStatus(int& nStatus, PROCESS_MEMORY_COUNTERS& psMemInfo)
{
ULONG lCpuusage = 0;
UINT index;
//Find Total Number of Processes;
if (!EnumProcesses( mAvailableProcesses, sizeof(mAvailableProcesses), &cbNeeded ) )
return;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
if(cProcesses > 1000)
{
AfxMessageBox("There are Too Many applications Running on PC.");
}
PROCESS_MEMORY_COUNTERS psTempMemInfo;
for ( index = 0; index < cProcesses; index++ )
{
if(FindProcessandMemoryDetails(mAvailableProcesses[index],"Wjru.exe",psTempMemInfo)== TRUE)
{
nStatus = FOUND_WJRU;
psMemInfo = psTempMemInfo;
return;
}
}
nStatus = WJRU_NOTFOUND;
}
HANDLE CProcessMonitor::GetProcessHandle(DWORD processID, CString Processname)
{
char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH];
strcpy(szTargetProcessName,Processname.GetBuffer(50));
Processname.ReleaseBuffer();
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process name.
if ( hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, szProcessName,
sizeof(szProcessName) );
if(strcmp(szProcessName,szTargetProcessName) ==0)
{
return hProcess;
}
else
{
return NULL;
}
}
}
return NULL;
}
HANDLE CProcessMonitor::GetHandleToProcess(CString ProcessName)
{
HANDLE hProcess;
hProcess = NULL;
char szProcessName[MAX_PATH] = "unknown";
char szTargetProcessName[MAX_PATH];
strcpy(szTargetProcessName,ProcessName.GetBuffer(50));
ProcessName.ReleaseBuffer();
ULONG lCpuusage = 0;
UINT index;
//Find Total Number of Processes;
if (!EnumProcesses( mAvailableProcesses, sizeof(mAvailableProcesses), &cbNeeded ) )
return hProcess;
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
if(cProcesses > 1000)
{
AfxMessageBox("There are Too Many applications Running on PC.");
}
for ( index = 0; index < cProcesses; index++ )
{
hProcess= GetProcessHandle(mAvailableProcesses[index],szTargetProcessName);
if(hProcess != NULL)
{
return hProcess;
}
}
return hProcess;
}
Haribabu....
|
|
|
|
|