|
First, when you call InvalidateRect(), don't pass NULL. Calculate the correct rect of the bitmap and pass that.
Second, when you call InvalidateRect(), don't pass FALSE. You don't need to erase the background, this only causes the region to be painted twice.
Third, Use double buffering. Do all your drawing off screen then draw everything back to the screen in one go.
|
|
|
|
|
You can also use from a avi file in your program with create your graphic files into a avi file
|
|
|
|
|
Thanks, I thought so at first, however, MFC for CE does not support CAnimationCtrl... Indeed, I solved the problem by creating a CWnd-derived window, and I placed the animation in there. Since it's a window in its own, it does not flicker at all.
Regards,
Fernando.
A polar bear is a bear whose coordinates has been changed in terms of sine and cosine.
|
|
|
|
|
I have added the options Enable Profiling and Generate Mapfile to the link options of the resp projects I would like to profile and rebuilt the proj. But still I do not have the profile menu item in my build menu activated. cud someone point me out where I am going wrong?
Also what is the procedure to enable profiling in VS9.0, cud someone provide me the step-wise procedure?
Thanks and in anticipation of an early reply.
|
|
|
|
|
Hi,
We know some TWAIN SDK in VS C++???
I need it... Or some samples for the TWAIN?
Thanks
|
|
|
|
|
|
But I need something for commercial purposes...
|
|
|
|
|
|
Hi all,
Im trying the following, I have a character pointer and a char array, I'm trying to assing the value of the pointer to the array, with no luck, please help??
char* variable = "what ever";
functionExample(variable);
void functionExample(char* variable)
{
char Value[] = variable;
}
Thanx in advance ....
Only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
|
|
|
|
|
Programm3r wrote: char Value[] = variable;
that is not legal C++.
the easiest way to do this is with a string class of some kind:
CString Value = variable;
or
std::string Value = variable;
or, if you have to use a char array:
int iLen = strlen(variable);
char Value = new char [ iLen + 1 ];
strcpy(Value, variable);
Value[iLen] = 0;
...
delete [] Value;
|
|
|
|
|
|
CString is not the STL std::string class. it comes from MFC.
|
|
|
|
|
|
couldn't you just search the MSDN[^] ... ?
|
|
|
|
|
|
hello! All
i want to ask about a modifiction of the below line i want to know is it right or wrong and why?
Programm3r wrote: char Value[] = variable;
first:Programm3r has made a mistake here that he assigned a value var to a pointer.
second: i think it may be
char value[];<br />
&value[0] = variable;
thanks for your reply
******************
******************
** Ahmed Ismail **
******************
******************
|
|
|
|
|
I am developing an SDI application that communicates with an instrument. The application have 2 threads: GUI and a communication thread. Until now I have used the following method to deliver data from the comm-thread to the GUI:
ViewWnd = ((CFrameWnd *)AfxGetApp()->m_pMainWnd)->GetActiveView();
ViewWnd->PostMessage(WM_MY_MESSAGE, 0, (LPARAM)PostString);
Is this a good solution? If not? What do You suggest?
|
|
|
|
|
Did it work?
Please post more detailed code.
Ovidiu Cucu
Microsoft MVP - Visual C++
|
|
|
|
|
It does work. I just wondered if this is good solution.
Here's more detailed code:
commthread:
ViewWnd = ((CFrameWnd *)AfxGetApp()->m_pMainWnd)->GetActiveView();
CString *PostString = new CString;
*PostString = "This is a test";
ViewWnd->PostMessage(WM_DATA_UPDATED, 0, (LPARAM)PostString);
GUI:
ON_MESSAGE(WM_DATA_UPDATED, OnDataUpdated)
long CZFGMCommunicatorView::OnDataUpdated(UINT wParam, LONG lParam)
{
CString* InString= (CString*)lParam;
GetStatusBar()->SetPaneText(0, str1 + *InString, 1);
delete InString;
}
What I wanted to know:
Is the view is the best class to handle this or is the frame a better choise. Or if it is better to just write a member function in the gui and access this via a pointer to gui...
|
|
|
|
|
In my opinion an alternative solution to PostMessage is adding of a member function to your view, and then calling it directly:
CMyView * ViewWnd = (CMyView*)(((CFrameWnd *)AfxGetApp()->m_pMainWnd)->GetActiveView());
ViewWnd->MyUpdateFunction(PostString);
I think this works faster comparing with PostMessage .
I hope this helps.
|
|
|
|
|
That's fine, you just have to make sure PostString persists long enough (and unaltered) to be handled by the GUI thread. One way to do this is alloc PostString in comm thread, and free PostString in GUI thread. If you are sending a _lot_ of strings then the repeated alloc/free overhead _may_ become an issue.
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Hi all.
How I can get control's id "(Name)" property of a control of other process (vb6 app) via windows api?
Please, help me.
Thx in advance.
Best Regards,
Marco Alves.
|
|
|
|
|
|
first, thank you for your reply.
Sorry, because I've a bad english. But trying to do my best.
Okay, suppose I have a VB6 app. I put a listview on my form and name it lvwProducts. Now, I compile and run this simple app.
Now, in another app (a C# .NET 2005 app) I want do get the name of that listview, i.e., the name of the listview that is on another process (my vb6 app). First, I got the handle. with the listview handle I want to get its name.
get it?
Ah, I've downloaded a code from http://blogs.msdn.com/brianmcm/ but it only works if the listview is on an .NET process. but, in my case, the other process was written in vb6.
to use that code I do something like that:
string controlName = GetWinFormsId.WinFormsUtilities.GetWinFormsId(hWnd) // where hWnd is the handle of my listview.
the code is here (sorry, I don't know how to format the code here):
**********************
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Text;
namespace GetWinFormsId
{
///
/// Summary description for WinFormsUtilities.
///
public class WinFormsUtilities
{
private static int GetControlNameMessage = 0;
static WinFormsUtilities()
{
GetControlNameMessage = NativeMethods.RegisterWindowMessage("WM_GETCONTROLNAME");
}
public static string GetWinFormsId(IntPtr hWnd)
{
return XProcGetControlName(hWnd, GetControlNameMessage);
}
protected static string XProcGetControlName(IntPtr hwnd, int msg)
{
//define the buffer that will eventually contain the desired window's WinFormsId
byte[] bytearray = new byte[65535];
//allocate space in the target process for the buffer as shared memory
IntPtr bufferMem = IntPtr.Zero; //base address of the allocated region for the buffer
IntPtr written = IntPtr.Zero; //number of bytes written to memory
IntPtr retHandle = IntPtr.Zero;
bool retVal;
//creating and reading from a shared memory region is done differently in Win9x then in newer OSs
IntPtr processHandle = IntPtr.Zero;
IntPtr fileHandle = IntPtr.Zero;
if (!(Environment.OSVersion.Platform == PlatformID.Win32Windows))
{
try
{
uint size; //the amount of memory to be allocated
size = 65536;
processHandle = NativeMethods.OpenProcess(NativeMethods.PROCESS_VM_OPERATION | NativeMethods.PROCESS_VM_READ | NativeMethods.PROCESS_VM_WRITE, false, GetProcessIdFromHWnd(hwnd));
if (processHandle.ToInt64() == 0)
{
throw new Win32Exception();
}
bufferMem = NativeMethods.VirtualAllocEx(processHandle, IntPtr.Zero, new UIntPtr(size), NativeMethods.MEM_RESERVE | NativeMethods.MEM_COMMIT, PageProtection.ReadWrite);
if (bufferMem.ToInt64() == 0)
{
throw new Win32Exception();
}
//send message to the control's hWnd for getting the specified control name
retHandle = NativeMethods.SendMessage(hwnd, msg, new IntPtr(size), bufferMem);
//now read the TVITEM's info from the shared memory location
retVal = NativeMethods.ReadProcessMemory(processHandle, bufferMem, bytearray, new UIntPtr(size), written);
if (!retVal)
{
throw new Win32Exception();
}
}
finally
{
//free the memory that was allocated
retVal = NativeMethods.VirtualFreeEx(processHandle, bufferMem, new UIntPtr(0), NativeMethods.MEM_RELEASE);
if (!retVal)
{
throw new Win32Exception();
}
NativeMethods.CloseHandle(processHandle);
}
}
else
{
try
{
int size2; //the amount of memory to be allocated
size2 = 65536;
fileHandle = NativeMethods.CreateFileMapping(new IntPtr(NativeMethods.INVALID_HANDLE_VALUE), IntPtr.Zero, PageProtection.ReadWrite, 0, size2, null);
if (fileHandle.ToInt64() == 0)
{
throw new Win32Exception();
}
bufferMem = NativeMethods.MapViewOfFile(fileHandle, NativeMethods.FILE_MAP_ALL_ACCESS, 0, 0, new UIntPtr(0));
if (bufferMem.ToInt64() == 0)
{
throw new Win32Exception();
}
NativeMethods.MoveMemoryFromByte(bufferMem, ref bytearray[0], size2);
retHandle = NativeMethods.SendMessage(hwnd, msg, new IntPtr(size2), bufferMem);
//read the control's name from the specific shared memory for the buffer
NativeMethods.MoveMemoryToByte(ref bytearray[0], bufferMem, 1024);
}
finally
{
//unmap and close the file
NativeMethods.UnmapViewOfFile(bufferMem);
NativeMethods.CloseHandle(fileHandle);
}
}
//get the string value for the Control name
return ByteArrayToString(bytearray);
}
private static uint GetProcessIdFromHWnd(IntPtr hwnd)
{
uint pid;
NativeMethods.GetWindowThreadProcessId(hwnd, out pid);
return pid;
}
private static string ByteArrayToString(byte[] bytes)
{
if (Environment.OSVersion.Platform == PlatformID.Win32Windows)
{
// Use the Ansii encoder
return Encoding.Default.GetString(bytes).TrimEnd('0');
}
else
{
// use Unicode
return Encoding.Unicode.GetString(bytes).TrimEnd('0');
}
}
}
///
/// Summary description for NativeMethods.
///
public class NativeMethods
{
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(uint dwDesiredAccess, bool bInheritHandle,
uint dwProcessId);
[DllImport("kernel32.dll")]
public static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress,
UIntPtr dwSize, uint flAllocationType, PageProtection flProtect);
[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("kernel32.dll")]
public static extern bool VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress,
UIntPtr dwSize, uint dwFreeType);
[DllImport("kernel32.dll")]
public static extern bool CloseHandle(IntPtr hObject);
[DllImport("kernel32.dll")]
public static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, uint
dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow,
UIntPtr dwNumberOfBytesToMap);
[DllImport("kernel32.dll")]
public static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr CreateFileMapping(IntPtr hFile,
IntPtr lpFileMappingAttributes, PageProtection flProtect, int dwMaximumSizeHigh,
int dwMaximumSizeLow, string lpName);
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll")]
public static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,
[Out] byte[] lpBuffer, UIntPtr nSize, IntPtr lpNumberOfBytesRead);
[DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)]
public static extern void MoveMemoryFromByte(IntPtr dest, ref byte src, int size);
[DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)]
public static extern void MoveMemoryToByte(ref byte dest, IntPtr src, int size);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int RegisterWindowMessage(string lpString);
//=========== Win95/98/ME Shared memory staff===============
public const int STANDARD_RIGHTS_REQUIRED = 0xF0000;
public const short SECTION_QUERY = 0x1;
public const short SECTION_MAP_WRITE = 0x2;
public const short SECTION_MAP_READ = 0x4;
public const short SECTION_MAP_EXECUTE = 0x8;
public const short SECTION_EXTEND_SIZE = 0x10;
public const int SECTION_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_WRITE | SECTION_MAP_READ | SECTION_MAP_EXECUTE | SECTION_EXTEND_SIZE;
public const int FILE_MAP_ALL_ACCESS = SECTION_ALL_ACCESS;
//============NT Shared memory constant======================
public const short PROCESS_VM_OPERATION = 0x8;
public const short PROCESS_VM_READ = 0x10;
public const short PROCESS_VM_WRITE = 0x20;
public const long PROCESS_ALL_ACCESS = 0x1F0FFF;
public const short MEM_COMMIT = 0x1000;
public const short MEM_RESERVE = 0x2000;
public const short MEM_DECOMMIT = 0x4000;
public const int MEM_RELEASE = 0x8000;
public const int MEM_FREE = 0x10000;
public const int MEM_PRIVATE = 0x20000;
public const int MEM_MAPPED = 0x40000;
public const int MEM_TOP_DOWN = 0x100000;
public const int INVALID_HANDLE_VALUE = -1;
}
[Flags]
public enum PageProtection : uint
{
NoAccess = 0x01,
Readonly = 0x02,
ReadWrite = 0x04,
WriteCopy = 0x08,
Execute = 0x10,
ExecuteRead = 0x20,
ExecuteReadWrite = 0x40,
ExecuteWriteCopy = 0x80,
Guard = 0x100,
NoCache = 0x200,
WriteCombine = 0x400,
}
}
**********************
best regards,
marco alves.
-- modified at 10:20 Monday 4th September, 2006
|
|
|
|
|
|