|
|
What is the best way for a control program to communicate with a system service that I am writing? I have seen that you can send a custom control code, but how can you pass parameters.
How is this generally done? Is it via registry entries?
|
|
|
|
|
I have used MSMQ with a lot of success. Or, you can use remoting from a server. I like the MSMQ solution better because it has built-in solutions to reduce data loss and it scales easily.
-- modified at 10:23 Saturday 18th February, 2006
|
|
|
|
|
Hi,
Need some help translating some structures from Pascal to C++.
Any help would be appreciated.
TWideText = record<br />
Text: array[1..20] of WideChar;<br />
Len: Byte;<br />
end;<br />
<br />
TWideComment = record<br />
Text: array[1..255] of WideChar;<br />
Len: Byte;<br />
end;<br />
<br />
TChar = record<br />
Pixels: array[0..9, 0..44] of Byte;<br />
RTop: Byte;<br />
Width, Height: Byte;<br />
Text: TWideText;<br />
Style: Byte;<br />
deleted: boolean;<br />
end;<br />
<br />
TChMatrix = record<br />
Modified: boolean;<br />
FileName: WideString;<br />
Comment: TWideComment;<br />
Char: array of TChar;<br />
end;
Patrik
|
|
|
|
|
Example:
struct TChar
{
unsigned char Pixels[10][45];
unsigned char RTop, Width, Height;
TWideText Text;
unsigned char Style;
bool deleted;
}; C array indexes always start at 0, so the code that accesses those 1-based arrays will have to change too.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Thanks for the answer Mike.
What about WideChar and WideString? These must be data types in DelphiPascal?
WideChar = TCHAR?
So the first struct would be:
struct WideText
{
TCHAR[20] Text;
Byte Len;
}; But with WideString I have no idea.
//Patrik
|
|
|
|
|
I assume WideChar is a Unicode character, in C that is wchar_t . For a Unicode string, use std::wstring unless you're comfortable with C-style strings.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi.
I'm trying to get the text from the text-editor of another process (VS.Net) but it return nothing.
This is my code:
<br />
HWND hwnd = (HWND)0x008803AC;
<br />
char Data[500];<br />
SendMessage(hwnd, WM_GETTEXT, (WPARAM)500, (LPARAM)Data);<br />
MessageBox(NULL, Data, "The Control Text", MB_OK);
<br />
any idia why the WM_GETTEXT doesn't work ?
Thanx
|
|
|
|
|
|
Thanks for the respond.
I've tried both ways: SendMessage and GetWindowText, although GetWindowText doesn't work for controls outside the calling process.
both return an empty string
Maybe this is because the text doesn't resides on that "special place" and the only way accessing VsTextEditPane is through the COM interface?
|
|
|
|
|
Virtek wrote:
Maybe this is because the text doesn't resides on that "special place" and the only way accessing VsTextEditPane is through the COM interface?
That'd be my guess.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi,
I have created an MFC owner drawn control (Derived from CButton) that needs to do some initialization after it is created or subclassed. If the user explicitly calls MyCtrl.Create( .... ), I can handle the OnCreate() message in my control, so no problems.
However, if the user attaches the control through DDX, this results in SubclassWindow being called and OnCreate() is never called. I know you can handle PreSubclassWindow() before the window is actually subclassed, but I need to do some initialization after it is subclassed. So Is there anyway in my class to know after it has subclassed a window?
Thanks in advance for any help.
|
|
|
|
|
|
Say I have a binary resource / text file . Is there a way i can embedded this as part of my VC 6 created DLL .
Now I have a similar project which can be compiled as a static library . TO be able to access the resource (.rc)
I need to access the resources by obtaining the Application handle by doing something like
AfxGetApp()->LoadResource
For a static lib this will point to the application that links using this library . Is there a way I can still access my embedded resources ?
Engineering is the effort !
|
|
|
|
|
Sorry, I don't mean to hijack your thread but I have a similar question along the same lines.
I want to export a very small class into a dll, which would also contain a .rc file with 30 or so wav files. Most of the tutorials on this website are either just too complicated to understand or are MFC related. In simple terms, how do you create a win32 dll, containing a .rc file and and a class?
|
|
|
|
|
I'm not completely sure what your asking as the message as it isn't really clear...
If looking to load a resource from your library and not the calling executable you can use the GetModuleHandle[^] API passing NULL as the module name, this will then return a handle to your library. You can then use the LoadResource[^] API as per usual.
Gavin Taylor
w: http://www.gavspace.com
|
|
|
|
|
May I ask you all how to make an item moves randomly in a board game pls?
|
|
|
|
|
use rand() to generate two random numbers and set the coordinates of the window using SetWindowPos() .
That's all buddy.
*Of course you will have to set a timer to change the position in a specified interval of time
Wishes.
Anshuman Dandekar
Dare to Dream,
Care to Achieve.............
|
|
|
|
|
Hello,
I am trying to understand recursion by using the following example.
<br />
#include <iostream><br />
#include <iomanip><br />
<br />
using namespace std;<br />
<br />
unsigned long factorial( unsigned long );
int main()<br />
{<br />
for ( int i = 0; i <= 4; i++ )<br />
{<br />
cout << "\n i = " << i << endl;<br />
cout << endl << setw( 2 ) << i << "! = " << factorial( i ) << endl;<br />
}<br />
return 0;
<br />
}
unsigned long factorial( unsigned long number )<br />
{<br />
if ( number <= 1 ) <br />
{<br />
return 1;<br />
}<br />
else <br />
{<br />
cout << endl << "number = " << number << " factorial(number - 1) = " << factorial(number - 1) <br />
<< " number * factorial(number - 1) = " << number * factorial( number - 1 ) << endl; <br />
return number * factorial( number - 1 );<br />
}<br />
}
<br />
I do understand that when i = 0, the base case is true, therefore 1 is returned. 0! = 1
When i = 1, the base case is true and 1 is returned. 1! = 1
When i = 2, the base case is not true, so number * factorial( number - 1 ) is returned, which is 2 * factorial( 1 ). 2 * 1 = 2. 2 is returned. 2! = 2
At this point, I have a question. The next line says i = 3. Then it says number = 2. How does number become 2 if i = 3?
Thanks,
Eric
|
|
|
|
|
The recursive calls have to complete before the output can be sent to cout . So what you're seeing is the output from the deepest recursive call first.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hasn't the output already been sent to cout? The program already output 2! = 2 and i = 3.
At the point in the program where i = 3 is output, doesn't that signify the beginning of a new iteration?
Thanks,
Eric
|
|
|
|
|
OK, I still don't get it. I changed the code a little to make the invocations easier to see.
<br />
#include <iostream><br />
#include <iomanip><br />
using namespace std;<br />
<br />
unsigned long factorial( unsigned long );
int count = 0;<br />
<br />
int main()<br />
{ <br />
for ( int i = 0; i <= 2; i++ )<br />
{<br />
cout << "\n i = " << i << endl;<br />
cout << endl << setw( 2 ) << i << "! = " << factorial( i ) << endl;<br />
cout << endl << "--------------------------------------------" << endl;<br />
}<br />
return 0;
<br />
}
unsigned long factorial( unsigned long number )<br />
{ <br />
count++;<br />
cout << endl << "factorial was invoked for the " << count << " time "<br />
<< " number = " << number << endl;<br />
<br />
if ( number <= 1 ) <br />
{<br />
cout << endl << "number <= 1" << endl;<br />
return 1;<br />
}<br />
else <br />
{<br />
cout << endl << "number = " << number <br />
<< " factorial(number - 1) = " << factorial(number - 1) <br />
<< " " <br />
<< number << " * " << factorial( number - 1 ) << " = " <br />
<< number * factorial( number - 1 ) << endl; <br />
<br />
return number * factorial( number - 1 );<br />
}<br />
}
OUTPUT:
<br />
<br />
i = 0<br />
<br />
factorial was invoked for the 1 time number = 0<br />
<br />
number <= 1<br />
<br />
0! = 1<br />
<br />
--------------------------------------------<br />
<br />
i = 1<br />
<br />
factorial was invoked for the 2 time number = 1<br />
<br />
number <= 1<br />
<br />
1! = 1<br />
<br />
--------------------------------------------<br />
<br />
i = 2<br />
<br />
factorial was invoked for the 3 time number = 2<br />
<br />
factorial was invoked for the 4 time number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 5 time number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 6 time number = 1<br />
<br />
number <= 1<br />
<br />
number = 2 factorial(number - 1) = 1 2 * 1 = 2<br />
<br />
factorial was invoked for the 7 time number = 1<br />
<br />
number <= 1<br />
<br />
2! = 2<br />
<br />
--------------------------------------------<br />
Press any key to continue<br />
*/<br />
Please walk me through the following:
<br />
i = 2<br />
<br />
factorial was invoked for the 3 time number = 2<br />
<br />
factorial was invoked for the 4 time number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 5 time number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 6 time number = 1<br />
<br />
number <= 1<br />
<br />
number = 2 factorial(number - 1) = 1 2 * 1 = 2<br />
<br />
factorial was invoked for the 7 time number = 1<br />
<br />
number <= 1<br />
<br />
2! = 2<br />
Thanks!
|
|
|
|
|
It appears that you are calling factorial() three times within itself (one for the algorithm itself, and two for the cout statements). With all of those cout statements, that may be leading to the confusion.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
If you are trying to track the stages of recursion with the cout line then I suggest that you minimise your confusion by calling your recursive function just ONCE and storing the result to use in your cout line and to return, I think that this will you help dissect what is going on?
Good luck I´m sure it will just click and you will go "Ah!"
|
|
|
|
|
OK, thanks to all of the great feedback, I have a better understanding about recursion.
I am now attempting to apply it and I have come across a problem that I can't seem to pinpoint.
I have written the "eight queens" program, but for some reason, I get an infinite loop. I think my base case is ok. Can someone help me figure out what I am doing wrong here?
Thanks in advance,
Eric
<br />
#include <iostream><br />
<br />
using namespace std;<br />
<br />
<br />
const int BOARD_SIZE = 8;<br />
<br />
void fillBoard( int [], int, int );<br />
bool noConflict( int [], int, int );<br />
void printBoard( int [], int );<br />
<br />
<br />
int main()<br />
{<br />
int chessboard[ BOARD_SIZE ];
int column = 0; <br />
int count = 0;
<br />
fillBoard( chessboard, column, count );
<br />
return 0;
}
<br />
<br />
void fillBoard( int board[ BOARD_SIZE ], int c, int cnt )<br />
{<br />
for( int r = 0; r <= 7; r ++ )
{<br />
board[ c ] = r;
<br />
<br />
if( noConflict( board, r, c ) )
{<br />
if( c == 7 )
{<br />
printBoard( board, cnt);
}<br />
<br />
else <br />
{<br />
fillBoard( board, c + 1, cnt );
}<br />
}<br />
}<br />
}
<br />
<br />
bool noConflict( int board[ BOARD_SIZE ], int r, int c )<br />
{<br />
for( int col = c - 1; col >= 0; col-- )
{<br />
if( board[ col ] == r
|| board[ col ] == r + c - col
|| board[ col ] == r + col - c )
{<br />
return false;
}<br />
else<br />
{<br />
return true;
}<br />
}<br />
return true;
}
<br />
<br />
void printBoard( int board [ BOARD_SIZE ], int cnt )<br />
{<br />
cout << "Count = " << ++cnt << endl;
<br />
for( int r = 0; r <= 7; r++ )
{<br />
for( int c = 0; c <= 7; c++ )
{<br />
if( board[ c ] == r )
{ <br />
cout << "Q ";
}<br />
<br />
else<br />
{<br />
cout << "- ";
}<br />
}<br />
cout << endl;<br />
}<br />
cout << endl;<br />
}
<br />
|
|
|
|