|
Thanks Tomasz for your help.
I was able to solve the problem with your help.
//To Set the Priority of the process from within the app
HANDLE hProcess;
DWORD pid;
pid = GetCurrentProcessId();
hProcess = OpenProcess(PROCESS_SET_INFORMATION,true,pid);
if(hProcess == 0)
AfxMessageBox("Invalid Process handle");
else
{
SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS);
CloseHandle(hProcess);
}
-------------------------------------------
Dashmesh A. Singh
Tata Consultancy Services,
INDIA
e-mail: visions_next@yahoo.co.uk
dashmesha_singh@tcscal.co.in
|
|
|
|
|
Hi,
What is parity in modem setting ?
For example in modem setting: 9600,n,8,1
In this setting i don't use of parity, but if i use of it, what will happend ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
When using 7 bit transfers, you have an eighth bit that can be used for a parity check. The sender can set the bit according to whether the number of bits in the data part of the byte is odd or even. This allows a simple sanity check on the receiving side.
Both sides need to agree on the parity setting (high bit signals odd or high bit signals even), or you'll have problems. Typically, a receiver with 8,n,1 will see a senders 7,E,1 data as partial garbage, since it will be getting some chars with 128 added to them, and some without.
|
|
|
|
|
I'm sure this has already been answered around here somewhere, but I can't find it.
I'll preface this with telling you that I am a long-time VB programmer (amateur) who is
learning VC just for fun.
I want a program with menu and toolbars with multiple different dialogs within it --
i.e. an MDI with multiple child dialogs (which is a total breeze to set up in VB).
I've got the MDI with a child CFormView OK. But where do I load any additional dialogs?
And for that matter, where exactly is the first dialog view being loaded? -- I've wandered
around in the code and don't see where it is happening. I have fiddled with loading
subdialogs in a dialog-based app, but that's not quite what I'm going for here.
Sub-question is: do I want or need to be using the Doc/View architecture? It seems to me
that I don't, but I'm really new to this (and admittedly don't understand the Doc/View
architecture yet). The program will be accessing a MS Jet database (but I don't mind
handling the DB access myself).
Thanks in advance for any suggestions/help.
David.
|
|
|
|
|
I found the info I needed in a book.
(Essential Visual C++ by Mickey Williams, SAMS publishing -- in case you are curious).
|
|
|
|
|
Hi,
That would be interesting for me, since I'm facing the same problem. I tried to find this book here in Brazil but unfortunatelly it will take too long to get it by bying from Amazon or other place.
I'd like to know how to implement this, if you could send me something I'd really apreciate that.
My email is crercio@osite.com.br
Thanks a lot.
Crercio O. Silva
|
|
|
|
|
I'm still learning MFC,
I want to be able to have the program read the PCs regional settings for the language and then use the approriate string table.
|
|
|
|
|
You must make dlls with the resources for each idiom
Then into the program you set the source of the resources with void AfxSetResourceHandle.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Let's say you know for sure what a process's ID is. How would you go about getting a window handle (hwnd) from that process ID? Thanks in advance
Sincerely,
Kanoo
|
|
|
|
|
The thing is that the process can have any number of windows open.
The only thing that comes to mind is that you could walk the window list and compare the process id's of all parent windows to the process id that you have.
It's a bit rough but here's an idea. Note, the I haven't tried it myself.
void GetProcessWindows(DWORD dwProcID)
{
DWORD dwWndProcId;
HWND hwndDesktop, hwndParent;
// start with the desktop
// all parent windows will be a child of the dekstop
hwndDesktop = GetDesktopWindow();
// get first parent window
hwndParent = GetWindow(hwndDesktop, GW_CHILD);
// go through this and all subsequent parent windows comparing their
// process id's with the one we are seeking info on
while(hwndParent) {
GetWindowThreadProcessId(hwndParent, &dwWndProcId);
// does window handle belong to the process we are checking?
if(dwWndProcId == dwProcID) {
// report the handle (or do something meaningful)
TRACE("Process window handle = %08x\n", dwWndProcId);
}
hwndParent = GetWindow(hwndDesktop, GW_HWNDNEXT);
}
}
|
|
|
|
|
I agree with the approach, but not sure app windows will show up as children of the desktop. (er, no I haven't tried it either).
I'd loop by enumerating all the top level windows, starting with HWND hwnd = ::GetTopWindow(NULL); and continuing with hwnd = ::GetNextWindow(hwnd, GW_HWNDNEXT);.
Then, as you say, comparing the process IDs found. The problem remains that apps tend to have more than one top level window, which means more work if you want the 'main' one.
|
|
|
|
|
This is code ripped from one of my apps. I think I got everything.
In the header file, I have this:
const int UWM_FOUNDHWNDADMIN = WM_APP + 1;
class CDlg : public CDialog
{
afx_msg LRESULT OnFoundHwnd(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
private:
PROCESS_INFORMATION* m_pProcessInfo;
HWND m_hwnd;
void RunComponent();
void GetAppHWnd();
};
static BOOL CALLBACK EnumWindowsProcGetHwnd(HWND hwnd, LPARAM lParam);
In the CPP file, I have this:
void CDlg::RunD2RemoteAdmin()
{
CString sFileName = GetProgramPath();
AddBackSlash(sFileName);
sFileName += "MyProgram.exe";
if (FileExists(sFileName))
{
char cmdLine[1024];
strcpy(cmdLine,(const char*)sFileName);
m_pProcessInfo = new PROCESS_INFORMATION;
if (!m_pProcessInfo)
{
CString sMsg;
sMsg = "Could not allocate memory for component process info (not critical)";
AfxMessageBox(sMsg);
return;
}
STARTUPINFO StartupInfo = {0};
StartupInfo.cb = sizeof(STARTUPINFO);
if (::CreateProcess(NULL, cmdLine, NULL, NULL, FALSE,
0, NULL, NULL, &StartupInfo, m_pProcessInfo))
{
WaitForInputIdle(m_pProcessInfo->hProcess, 15000);
GetAppHWnd();
}
}
else
{
CString sMsg;
sMsg = "Could not find executable component";
AfxMessageBox(sMsg);
}
}
void CDlg::GetAppHWnd()
{
DWORD pid = m_pProcessInfo->dwProcessId;
HANDLE ps = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid);
EnumWindows(EnumWindowsProcGetHwnd, pid);
CloseHandle(ps);
}
LRESULT CDlg::OnFoundHwnd(WPARAM wParam, LPARAM lParam)
{
wParam;
lParam;
m_hwnd = (HWND)wParam;
DWORD dwPID = (DWORD)lParam;
if (dwPID == m_pProcessInfo->dwProcessId)
{
}
else
{
}
return 1L;
}
BOOL CALLBACK EnumWindowsProcGetHwnd(HWND hwnd, LPARAM lParam)
{
CString sTitle;
CWnd::FromHandle(hwnd)->GetWindowText(sTitle);
DWORD wndPid;
::GetWindowThreadProcessId(hwnd, &wndPid);
if (wndPid == (DWORD)lParam && !sTitle.IsEmpty())
{
if (sTitle.Find("Remote Admin Monitor") >= 0)
{
theApp.m_pMainWnd->SendMessage(UWM_FOUNDHWNDADMIN, (WPARAM)hwnd, lParam);
}
return FALSE;
}
else
{
return TRUE;
}
}
|
|
|
|
|
I'm using a CListCtrl to display logged data and it can come into the view
quickly. The scroll bar however will jump to the previously highlighted postision or to the 0th Sel each time new data comes in. I would like for the
scroll bar to default to the 0th position but remain where the user left it
if its position changed.
Thankz,
Tim
|
|
|
|
|
Firstly, thanks for all who gave me some ideas in the previous posting. I know it is because there is some problem in GDI resource or something.
Here is the problem...(say again...)
Everything fines in NT...but when i move to Win9x, strange things happened. After the program runs for awhile, fonts change, cannot display colour when i do drawing.....even the Windows system message box font change(i know it because later Windows force me to terminate the program....so u know.....liked some memory problem..)...but everything fines in NT
I didn't use CreateDC. I just use the OnDraw() function provided by MFC in View.cpp file to do drawing(mainly), and i use a GLOBAL CDC pointer to let other file to do drawing too:
CDCPointer->m_hDC = pDC->m_hDC;
CDCPointer->m_hAttribDC = pDC->m_hAttribDC;
And i delete the CDCPointer in the destructor in View.cpp (delete CDCPointer;)
So....i really need a solution...because I need to implement some graphic codes now.
Again...thanks for all giving me advice......thanks alot.!!!!
|
|
|
|
|
What you're describing seems like major GDI resource leak. I'm not sure it's related to your global device context variable. You should get rid of the global variable - just pass CDC pointer as function parameter.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Hello:
I built a map<...> in the way showed below. After running program, I do not know if
data was loaded correctly. To verify this, I wanted to use "cout", but I do
not know how to reference, for example, to the content of dMonto[3] that is in
mpCont.
Is there a charitable codeguru soul by there?
Thanks in advance!!!!
#include <iostream>
#include <string>
#include <utility>
#include
using namespace std;
const int tam=10;
struct stTot {
string stLey;
double dMonto[tam];
};
stTot myTot;
map<string, sttot=""> mpCont;
int main()
{
myTot.stLey = "Text one";
for(int i=0; i<tam; i++)
="" mytot.dmonto[i]="i+11;
" mpcont["one"]="myTot;
" map<string,sttot="">::iterator it = mpCont.find("one");
// I want to put the "cout" here
return 0;
}
|
|
|
|
|
The folowing should do the trick;
cout << (*yourIterator).second << endl;
-Ben
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
So far I've seen two examples using the syntax:
(*iter).second
to look at the content of a map. Is there something
wrong with using the -> operator as in:
iter->second
Thanx
|
|
|
|
|
My STL book ("The C++ Standard Library: A Tutorial and Reference" by Nicolai Josuttis) tells that:In some older environments, operator -> might not work yet for iterators MSVC's STL implementation seems to be an "older environment", using (*iter).member is always safe.
|
|
|
|
|
I have a custom database file (a simple character-delimited text file, if you would like to know) I need to read/write to in a Wizard-made Database program in MSVC++. The project was specified as a single-document database program. I'm having trouble figuring out how to read and write to the file. I assigned a CArchive Serialization function to a button, and when I hit it, I get an Invalid Page Fault. If you feel like laughing, here's the function:
void CDCDBIIView::OnButtonReadFile(CArchive &ar)
{
ar.ReadString(m_FILE); //CArchive object ar created in CDCDBIIDoc::Serialize(CArchive &ar)
UpdateData (FALSE);
}
Something's wrong with my logic in the ar.ReadString line, because that's the only line in the function doing any serious work. (UpdateData just...well, updates the data with the new info.) Right now, I'm not worried about parsing the input I'm getting in the archive, I just have m_FILE assigned to a read-only edit box so I can see if the program is reading from the file at all.
What I need to know is do I need to add a custom function to load/read/write to the open file, or do I add it to one of the many classes the MSVC++ Wizard built? I've read as many tuts as possible on CFile and CArchive, and MSDN isn't helping much. Any help would be greatly appreciated.
-Trying to be as informative as possible while knowing almost nothing at all
|
|
|
|
|
I have done a simial thing. The only difference is that i have used a structured ascii file instead of comma delim. This function uses CFile.
CFile rfile.Open(filename,CFile::modeRead | CFile::shareDenyWrite, &ex);
LogCnt = rfile.GetLength()/sizeof(LOGDATA);//returns how many records in the file
for (int i = 0;i< LogCnt;i++){
rfile.Read(&logdata[i],sizeof(LOGDATA));
///////if you want to use comma delim you would parse your data here
///////////////////////I put a return char on the end if the string in the write function.
rfile.Read(tmp,1);/////////////////used to hold return char
}
|
|
|
|
|
Hi all.
I want to know, for getting data from mscomm i must use of GetInput() or GetOutput() ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Does anyone know how to load small (16x16) versions of the built-in icons, like the information ('i' in a bubble), warning ('!' in a triangle) and error ('X' in a circle) icons?
LoadIcon will only load 32x32 images.
LoadImage loads the icons in question as 32x32 even if I request 16x16 and doesn't load them at all if I don't specify LR_SHARED.
I'm trying to avoid putting the icons in my project as a resource. I'd also rather not load the 32x32 versions and scale them myself. There's gotta be a way, Shirley?
|
|
|
|
|
Try,
HICON hSmallIcon = (HICON) ::LoadImage ( AfxGetInstanceHandle (), MAKEINTRESOURCE(IDR_MY_SMALL_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR );
it always works for me. But, remember that unlike LoadIcon, this one does require a subsequent call to DestroyIcon when your're done with the it.
-Ben
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Thanks for the reply, but I want to load built-in Windows icons and avoid including resources in my project. (Because it's a class I plan on using in several projects.)
For example:
HICON hIcon = (HICON)LoadImage(NULL, IDI_INFORMATION, IMAGE_ICON, 16, 16, LR_SHARED);
This always loads a 32x32 image and fails if LR_SHARED is removed.
BTW, IDI_INFORMATION is the same as MAKEINTRESOURCE(OIC_INFORMATION) but you don't need to #define OEMRESOURCE and can leave out the MAKEINTRESOURCE macro.
|
|
|
|
|