|
i use CreateToolhelp32Snapshot function to seach all the process id ,
but i can not use process id to look for the main frame hwnd!!
can anyone tell me how to find that
Thanks
hi
|
|
|
|
|
Use EnumWindows to enumerate all top level windows. For each window enumerated use the GetWindowThreadProcessId function to filter the windows to those belonging to the desired process.
Steve
|
|
|
|
|
There are a lot of hWnds in a top level window, such as Static, Button, EditBox etc. Using EnumWindow to look for hWnd wastes a lot of resources of system, and makes the system slowly.
Can anybody give me a good idea!! thanks.
hi
|
|
|
|
|
EnumWindows only enumerates top level windows. The procedure I outlined doesn't waste system resources - It's how it's done!
Steve
|
|
|
|
|
|
Here's an example that uses the technique:
------------------------------------------
// Win32App.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <assert.h>
#include <vector>
#include <algorithm>
#include <malloc.h>
typedef std::vector<HWND> HWNDS;
namespace
{
struct EnumInfo
{
DWORD dwProcessID;
HWNDS *pHWNDS;
};
BOOL CALLBACK EnumWindowsProc( HWND hWnd, LPARAM lParam )
{
const EnumInfo *pInfo = reinterpret_cast<const EnumInfo *>(lParam);
DWORD dwProcessID;
GetWindowThreadProcessId(hWnd, &dwProcessID);
if ( dwProcessID == pInfo->dwProcessID )
{
pInfo->pHWNDS->push_back(hWnd);
}
return TRUE;
}
}
BOOL GetProcessTopLevelWindows( DWORD dwProcessId, HWNDS *pOut )
{
assert(pOut);
EnumInfo ei = {dwProcessId, pOut};
return EnumWindows(&EnumWindowsProc, reinterpret_cast<LPARAM>(&ei));
}
struct ShowWindowTitle
{
bool operator()(HWND hWnd) const
{
int Len = GetWindowTextLength(hWnd);
if ( Len>0 )
{
char *pText = reinterpret_cast<char*>(_alloca(Len+1));
GetWindowText(hWnd, pText, Len+1);
MessageBox(NULL, pText, "Window title", MB_OK);
return true;
}
return false;
}
};
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWNDS wins;
if ( GetProcessTopLevelWindows(2216, &wins) ) // PID HARDCODED!
{
std::for_each(wins.begin(), wins.end(), ShowWindowTitle());
}
return 0;
}
Steve
|
|
|
|
|
class AFX_EXT_CLASS ConDlg : public CDialog
{
// Construction
public:
ConDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(ConDlg)
enum { IDD = IDD_DIALOG1 };
CDTPicker m_DateP1;
CDTPicker m_DateP2;
CDTPicker m_TimeP1;
CDTPicker m_TimeP2;
CString m_TypePk;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(ConDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
struct M_Cage my_cage;
CString m_String;
Confused:
why m_cage could be touch while another vaiables such as m_DateP1 and m_String could not?
Lee
-- modified at 23:58 Monday 3rd April, 2006
|
|
|
|
|
Because it is protected. The others are public.
|
|
|
|
|
you did not read his post ...
|
|
|
|
|
Hi,friends,When I debug a propram in VC6.0,the complier report the error:
'CJsqApp::delete' is ambiguous
CJsqApp is a mulinherence class.
Please help me,Thank you in advance.
|
|
|
|
|
there are multiple delete() in the class and compiler doesn't know which one should be used - u should defind one more delete() which matches parameters as u called.
A special image tool for Windows C++ programmers, don't miss it!
The world unique Software Label Maker is waiting for you and me ...
A nice hyper tool for optimizing your Microsoft html-help contents.
|
|
|
|
|
I export a class from a extention dll and define a instance in another project,but,I could not see it's memeber variable except a struct variable defined in dll,what cause this? also,when i define the class instance in .H,the complier takes error as "the instuction '****' memory'****',could not read",what's mean?
Lee
-- modified at 23:59 Monday 3rd April, 2006
|
|
|
|
|
Hi,
I am using the DSOFramer control in an MFC dialog to display an excel chart. I have figured out how to run it and start with an excel worksheet and chart that I can modify to look how I want. Now I need two more tabs added (one with a worksheet and one with a chart)...I am using the following and it gives me an error that the Add function failed.
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
_Workbook wb;
Worksheets wsSet;
_Worksheet ws;
LPDISPATCH lpDisp = m_FrameControl.GetActiveDocument();
wb.AttachDispatch(lpDisp);
wsSet = wb.GetWorksheets();
ws = wsSet.Add(covOptional,covOptional,covOptional,COleVariant("Excel.Sheet"));
Thanks in advance for your help!
Jen
|
|
|
|
|
I have a programming project for one of my classes, but I have no idea where to start. Any help would be TREMENDOUSLY appreciated!
Program description:
Design and implement a Visual C++ .NET program that creates a simple “spreadsheet”. Your spreadsheet will contain 5 rows by 5 columns of updateable cells. There will be a 6th row and column that will display the total of the respective row or column. When the program executes it will display the spreadsheet with zeros in all cells and all totals. The program will prompt the user to enter 1 to update the spreadsheet or 0 to quit. When the user enters 1 to update the spreadsheet the program should prompt the user to enter the row and column to update. The row will be an integer 1 thru 5 and the columns will be characters A/a thru E/e. (1a is the upper left cell) The program should continue to prompt for row and column until a valid input is received. Next the program will prompt the user for the new value to go into cell X (replace X with appropriate row/ column reference, see sample run). After the value is entered the program will reprint the updated sheet and once again prompt enter 1 to update 0 to quit.
Assumptions:
-Eight digits will be enough width for the cells (tab). Cell values will not exceed 9,999,999.
-The prompt for edit or quit will only be 1 or 0. No other values will be used.
-For your testing purposes, a sample data file (data.txt) will be posted to WebCT. You can open this file, copy the data, run your program and right click your mouse to paste it to your program window. Press enter and the program should process the data as shown in the sample run below.
-This project will be much easier if you use an array. Remember that the first index in an array is zero
|
|
|
|
|
|
My apologies, I should have been more specific. The project is to be done in win32.
|
|
|
|
|
A game to transform letters read from a file to a prime number. Do and enjoy it!
The goal of this is to construct a C++ program that will read all letters from a specified file and transform them to a prime number.
The tasks you have to perform are:
(A) Read letters in sequence from a specified file, which contains 1 sentence. Transform each letter to the corresponding ASCII value.
For example, if the file contains “What?” then
‘W’ corresponds to 87
‘h’ corresponds to 104
‘a’ corresponds to 97
‘t’ corresponds to 116
(B) Calculate and output r1=the sum of all obtained integers (e.g. r1=87+104+97+116=404)
(C) Calculate and output r2=the length of Syracuse sequence seeded by r1.
Let n be a positive integer and f(n) be the transformation that sends n to n/2 if n is even and sends n to 3n+1 if n is odd. Starting with a positive value u called the seed, the sequence of integers iteratively generated by f and u is called a Syracuse sequence.
For example, starting with the seed u = 1, the subsequent terms of the sequence are 4, 2, and 1. The length of the sequence (excluding the seed) is therefore 3.
For u = 4, the next terms are 2 and 1. The length is 2.
For u = 404, the next terms are 202, 101, 304, 152, 76, 38, 19, 58, 29, 88, 44, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, and 1. The length is 27.
It is conjectured (this means that we do not have a proof of this fact, only strong evidences) that for any positive seed the sequence will always reach to 1. In fact, computations show that for any seed u less than or equal to 3*2^53, the corresponding sequence always reaches 1. The general case is unknown.
(D) Calculate and output r3=the largest prime factor of r2.
A prime factor of n is a factor of n which is a prime number. A prime number is any integer greater than 1 and only divisible by itself and 1 (e.g. 2, 3, 5, 7, 11, 13, 17 etc). For example, 3 is the largest prime factor of 27 and 7 is the largest prime factor of 49.
Here are some example
Example 1
Enter the name of the input file: in1.txt
963
49
7
Press CTR-C to Leave...
|
|
|
|
|
Errr.... Do you have a question or are you posting your homework for our enjoyment?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
|
He must be very desparate. This is the second post of the same homework assignment. Very annoying to pollute this message board.
|
|
|
|
|
I have the following code in my .h file
<br />
ForecastStruct Forecast[24];
CList<ForecastStruct *, ForecastStruct *> m_WeatherList;<br />
Basically what I want is a Linked list of Forecasts stored in m_WeatherList. The Forecast variable is an array for each hour of the day. I want to store this variable in the list m_WeatherList List.
to do that I do
<br />
m_WeatherList.AddTail((ForecastStruct *)Forecast);<br />
Forecast is correct. I can see all 24 indexes and each holds the right data. When I look at m_WeatherList after the line above, the data is wrong. I do not see my appended Forecast object.
Does anyone know what I am doing wrong?
Thanks!
-- modified at 18:48 Monday 3rd April, 2006
|
|
|
|
|
You need to tell us what m_WeatherList is. I'm guessing its a
CTypedPtrArray.
If that's the case, then you have added 1 element to the List.
If you wanted to add all 24, you need to do:
CTypePtrArray<CPtrArray, Forecast *> m_wList;
for (int i = 0; i < 24; i++)
m_wList.AddTail ( &(Forecast[n]) );
Iain.
|
|
|
|
|
m_WeatherList is a CList. Based on what is written above I would rather have the objects separated then at intervals of 24. That is what I would like is an object that holds Forecast objects as a whole in a linked list.
m_WeatherList Head Object
Forecast[0]..
Forecast[1]..
..
..
m_WeatherList Next Object
Forecast[0]..
Forecast[1]..
..
..
Thanks!
|
|
|
|
|
Hi,
I am having a project written in VC++6. I am including an updated header file from one of our research board manufacturers (NI). When I try to compile the project it is giving me errors like -
1)error C2632: 'char' followed by 'char' is illegal
2)error C2632: 'short' followed by 'short' is illegal
3)error C2632: 'short' followed by 'int' is illegal
4)error C2632: 'long' followed by 'long' is illegal
These header files are written in ANSI C and the code where this error occurs is like -
#ifndef _NI_int8_DEFINED_
#define _NI_int8_DEFINED_
typedef signed char int8; <--- error(1)
#endif
#ifndef _NI_int16_DEFINED_
#define _NI_int16_DEFINED_
typedef signed short int16; <--- error(2)(3)
#endif
#ifndef _NI_int32_DEFINED_
#define _NI_int32_DEFINED_
typedef signed long int32; <--- error(4)
#endif
Can someone help me out from this issue???
thanks,
-Pav
|
|
|
|
|
i did a test for u, int8 is not defined in my code,
then i add the 2 lines
#define int8 char
typedef signed char int8;
and get same error as you have, so it means int 8 has been defined somewhere before your include.
//add the line u will not have error 1
#define _NI_int8_DEFINED_
//then
#include "the_very_very_ugly_file.h"
do same for all errors.
A special image tool for Windows C++ programmers, don't miss it!
The world unique Software Label Maker is waiting for you and me ...
A nice hyper tool for optimizing your Microsoft html-help contents.
|
|
|
|
|