|
Thanks David,
I think I'm making it more difficult and I think you've answered my question
CDialog one("IDD_DIALOG1", this);
CDialog two(IDD_DIALOG1, this);
Both of these work. So the answer is the template resource name is just the string representation of the ID.
If I derive a class from CDialog, I have to make sure that my constructor in the derived class would accomodate the string using the MAKEINTRESOURCE macro.
How did I do?
Thanks again. I learned something.
|
|
|
|
|
mx483 wrote:
If I derive a class from CDialog, I have to make sure that my constructor in the derived class would accomodate the string using the MAKEINTRESOURCE macro.
How did I do?
What is it that you are wanting to do that a CDialog -derived class does not already do? I must say that in 12+ years of using MFC, I've never used CDialog 's constructor that takes a string. Maybe you have an example that shows its usefullness.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Nope, I haven't seen one either. Just took the opportunity to learn something new. Thanks again. Jay
|
|
|
|
|
Compiled resources may be identified numerically (this is the usual case) or with a string. For example, you could have the following in your .RC file:
IDD_DLG1 DIALOG 0, 0, 210, 150
...
"DIALOG2" DIALOG 0, 0, 200, 200
... In the first case, you have a #define in your resource.h file for the value IDD_DLG1 .
In the second case, you would use the lpszTemplateName form of the constructor, passing the string "DIALOG2" .
The MAKEINTRESOURCE macro converts an integer resource identifier to a form that the resource loading logic recognizes, returning it as a string type.
Software Zen: delete this;
|
|
|
|
|
Perfect! Thanks a bunch. It was a conceptual question. I have no reason to use a string but thought I should at least understand the concept. Thank you.
|
|
|
|
|
Howdy folks
Having a problem getting my COM port to talk to a piece of hardware using a 9-bit data protocol. I am using Visual Studio .NET 2003 and developing in C++ using the standard Win32 serial communications techniques. Specifically I have:
- Used CreateFile to get a Handle on my COM port
- Created a DCB structure to send 8-bit with PARITY bit making up the ninth bit
- Bytes are then sent to the hardware using WriteFile
When I wish to send a byte with the ninth bit as '1' I call GetCommState change the DCB to have MARK Parity then SetCommState to reinitialise the COM Port. Likewise to send a byte with the ninth bit as '0' I call GetCommState change the DCB to have SPACE Parity then SetCommState to reinitialise the COM Port.
This all works fine and my COM port talks to the hardware as required.
My problem is that it is very slow. Each time GetCommState & SetCommState are used to change the DCB parity it takes about 10ms. At the baud rates I am using a byte only takes 50us to transmit so this delay to switch parity makes a big difference.
Does anyone have an idea to speed up the parity change or a better method of obtaining a ninth bit.
Many Thanks
b_b
|
|
|
|
|
That 9-bit is definitely non-standard, so it might take some more detailed alteration of the structure. You might have to look closely at that DCB structure, to make sure that the specified protocol supports it. From what you have said, it sounds like it is sending back a nawk repeatedly or some other error code and then retransmitting until some timeout occurs. Change the timeout to a lower value to see if this speeds it up. This is not the solution - just confirmation of this theory.
|
|
|
|
|
Hello
I don't think I agree.
Really all I am doing is sending 8-bit data with a Parity bit and one Stop bit. The parity bit just happens to be being used as data bit 8 by the recieving hardware.
Using a serial port monitor to look at behaviour of the COM port the delay seems to happen when SetCommState() is executing. There are no error codes being output. It is simply reinitialising the COM port albeit slowly.
Thanks for your response
b_b
|
|
|
|
|
I Search the message when a dialog is covered by other windows.
I want to close the dialog when the user hide this with the mouse when he selects a other application for example.
Thanks
|
|
|
|
|
Check out the WM_ACTIVATE and WM_ACTIVATEAPP messages.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
THANKS
void CDialog::OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized )
{
if(nState==WA_INACTIVE)
{
CDialog::OnOK();
}
CDialog::OnActivate(nState, pWndOther, bMinimized);
}
|
|
|
|
|
if a file is printed,I can monitor the file ,include
the file's path,the file size ,the file's content.
thanks!
|
|
|
|
|
szcococut wrote:
if a file is printed,I can monitor the file ,include
the file's path,the file size ,the file's content.
Ok, now that you've told us what you can do, what is it that you want to do? Do any of these help?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
what I want to do is:
in my computor.
when someone prepare for printing a file or had printed a file.
my app which I want to do can monitor the file(the file's path).
thanks DavidCrow
|
|
|
|
|
The only thing you can do is monitor the queue while the print job is in it. When an application is preparing to print a file, only that application knows about it. After an application has printed a file, only that application knows about it. Make sense?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hello All
I want to use my own CButton-derived control in a CFileDialog (well, in fact I want to use a CEdit-derived one, a CComboBox-derived, and so on, but I'm starting with the button to simplify)
At this momment I have a CFileDialog derived class (CMyFileDialog) where I have declared two member variables:
CMyButton m_btnOk;
CMyButton m_btnCancel;
In the OnInitDialog function
BOOL CMyFileDialog::OnInitDialog()
{
CFileDialog::OnInitDialog();
m_btnOk.SubclassDlgItem(IDOK,GetParent());
m_btnCancel.SubclassDlgItem(IDCANCEL,GetParent());
return TRUE;
}
The dialog behaviour is as expected, but when Cancel or Ok button are pressed this assert happens:
LRESULT CALLBACK
AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
if (nMsg == WM_QUERYAFXWNDPROC)
return 1;
CWnd* pWnd = CWnd::FromHandlePermanent(hWnd);
ASSERT(pWnd != NULL);
ASSERT(pWnd->m_hWnd == hWnd);
if (pWnd == NULL || pWnd->m_hWnd != hWnd)
return ::DefWindowProc(hWnd, nMsg, wParam, lParam);
return AfxCallWndProc(pWnd, hWnd, nMsg, wParam, lParam);
}
If I only subclass the IDOK button this assert does not occurs. Any idea?
|
|
|
|
|
Hi,
I created 3 toolbars in mainframe and I need to get the resource ID (for exp. ID_BUTTON1) from the toolbar button when I click on it. I only have the CPoint member (the point where I clicked on the toolbar button).
I tried with something like this but it doesn't return the right ID;
void CMainFrame::OnParentNotify(UINT message, LPARAM lParam)
{
CMDIFrameWnd::OnParentNotify(message, lParam);
/*if(message == WM_LBUTTONDOWN)
{
int xpos = LOWORD(lParam);
int ypos = HIWORD(lParam);
CPoint pt;
pt.x = xpos; pt.y = ypos;
CWnd* pChild = ChildWindowFromPoint(pt);
int nID = pChild->GetDlgCtrlID();
}
}
Is there any other way to resolve this???
Thanks.
|
|
|
|
|
Hi friends,
I have unsigned string in which the word "MJ" is occuring multiple times. I want the pointer of last "MJ" string. Is there any inbuild api for this (like strstr).
Thank
|
|
|
|
|
Something like this should work:
1) Point to the next-to-last character in the string
2) Compare two characters in string to "MJ" (memcmp )
3) If they match, break
4) Move pointer two places to the left
5) Go to step 2
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I think:
4) Move pointer one place to left
is better.
old 6502 coder
|
|
|
|
|
Thanks!
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
StrRStrI will return the last pointer to last occurance of "MJ" string.
|
|
|
|
|
We have a ISAPI from a third-party company running on Windows 2000 Server, the same ISAPI isn't running on Windows Server 2003, do you have any information about ISAPI incompatibility with Windows Server 2003 ?
Thanks for any tip.
GuimaSun
www.nexsun.com.br
NEXSUN TechZone
|
|
|
|
|
I'm writing an application that requires some BCH ECC (Error Correction Coding).
I found some code on the net but the result of calculation is different with the results from MATLAB.
Is there anyone that has some experience in this field?
The MATLAB code is as follow:
n =31
k=21
%gf is Galois field
msg=gf([1 1 1 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 1])
cbch=bchenc(msg, n, k)
cbch Array elements =
1 1 1 0 0 1 1 1 1 0 0
0 0 1 1 0 0 1 1 0 1 1
0 1 0 0 1 0 1 0 1
Here is the C code (console app):
#include "StdAfx.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int m = 5, n = 31, k = 21, t = 2, d = 5;
int length = 31;
int p[6];
int alpha_to[32], index_of[32], g[11];
int recd[31], data[21], bb[11];
int numerr, errpos[32], decerror = 0;
int seed;
void
read_p()
{
p[0] = p[2] = p[5] = 1; p[1] = p[3] = p[4] =0;
}
void
generate_gf()
{
register int i, mask;
mask = 1;
alpha_to[m] = 0;
for (i = 0; i < m; i++) {
alpha_to[i] = mask;
index_of[alpha_to[i]] = i;
if (p[i] != 0)
alpha_to[m] ^= mask;
mask <<= 1;
}
index_of[alpha_to[m]] = m;
mask >>= 1;
for (i = m + 1; i < n; i++) {
if (alpha_to[i - 1] >= mask)
alpha_to[i] = alpha_to[m] ^ ((alpha_to[i - 1] ^ mask) << 1);
else
alpha_to[i] = alpha_to[i - 1] << 1;
index_of[alpha_to[i]] = i;
}
index_of[0] = -1;
}
void
gen_poly()
{
register int ii, jj, ll, kaux;
int test, aux, nocycles, root, noterms, rdncy;
int cycle[15][6], size[15], min[11], zeros[11];
cycle[0][0] = 0; size[0] = 1;
cycle[1][0] = 1; size[1] = 1;
jj = 1;
do {
ii = 0;
do {
ii++;
cycle[jj][ii] = (cycle[jj][ii - 1] * 2) % n;
size[jj]++;
aux = (cycle[jj][ii] * 2) % n;
} while (aux != cycle[jj][0]);
ll = 0;
do {
ll++;
test = 0;
for (ii = 1; ((ii <= jj) && (!test)); ii++)
for (kaux = 0; ((kaux < size[ii]) && (!test)); kaux++)
if (ll == cycle[ii][kaux])
test = 1;
} while ((test) && (ll < (n - 1)));
if (!(test)) {
jj++;
cycle[jj][0] = ll;
size[jj] = 1;
}
} while (ll < (n - 1));
nocycles = jj;
kaux = 0;
rdncy = 0;
for (ii = 1; ii <= nocycles; ii++) {
min[kaux] = 0;
for (jj = 0; jj < size[ii]; jj++)
for (root = 1; root < d; root++)
if (root == cycle[ii][jj])
min[kaux] = ii;
if (min[kaux]) {
rdncy += size[min[kaux]];
kaux++;
}
}
noterms = kaux;
kaux = 1;
for (ii = 0; ii < noterms; ii++)
for (jj = 0; jj < size[min[ii]]; jj++) {
zeros[kaux] = cycle[min[ii]][jj];
kaux++;
}
printf("This is a (%d, %d, %d) binary BCH code\n", length, k, d);
g[0] = alpha_to[zeros[1]];
g[1] = 1;
for (ii = 2; ii <= rdncy; ii++) {
g[ii] = 1;
for (jj = ii - 1; jj > 0; jj--)
if (g[jj] != 0)
g[jj] = g[jj - 1] ^ alpha_to[(index_of[g[jj]] + zeros[ii]) % n];
else
g[jj] = g[jj - 1];
g[0] = alpha_to[(index_of[g[0]] + zeros[ii]) % n];
}
printf("g(x) = ");
for (ii = 0; ii <= rdncy; ii++) {
printf("%d", g[ii]);
if (ii && ((ii % 70) == 0))
printf("\n");
}
printf("\n");
}
void
encode_bch()
{
register int i, j;
register int feedback;
for (i = 0; i < length - k; i++)
bb[i] = 0;
for (i = k - 1; i >= 0; i--)
{
feedback = data[i] ^ bb[length - k - 1];
if (feedback != 0)
{
for (j = length - k - 1; j > 0; j--)
if (g[j] != 0)
bb[j] = bb[j - 1] ^ feedback;
else
bb[j] = bb[j - 1];
bb[0] = g[0] && feedback;
}
else
{
for (j = length - k - 1; j > 0; j--)
bb[j] = bb[j - 1];
bb[0] = 0;
};
};
};
void
decode_bch()
{
register int i, j, q;
int elp[3], s[5], s3;
int count = 0, syn_error = 0;
int loc[3], reg[3];
int aux;
printf("s[] = (");
for (i = 1; i <= 4; i++) {
s[i] = 0;
for (j = 0; j < length; j++)
if (recd[j] != 0)
s[i] ^= alpha_to[(i * j) % n];
if (s[i] != 0)
syn_error = 1;
s[i] = index_of[s[i]];
printf("%3d ", s[i]);
};
printf(")\n");
if (syn_error) {
if (s[1] != -1) {
s3 = (s[1] * 3) % n;
if ( s[3] == s3 )
{
printf("One error at %d\n", s[1]);
recd[s[1]] ^= 1;
}
else {
if (s[3] != -1)
aux = alpha_to[s3] ^ alpha_to[s[3]];
else
aux = alpha_to[s3];
elp[0] = 0;
elp[1] = (s[2] - index_of[aux] + n) % n;
elp[2] = (s[1] - index_of[aux] + n) % n;
printf("sigma(x) = ");
for (i = 0; i <= 2; i++)
printf("%3d ", elp[i]);
printf("\n");
printf("Roots: ");
for (i = 1; i <= 2; i++)
reg[i] = elp[i];
count = 0;
for (i = 1; i <= n; i++) {
q = 1;
for (j = 1; j <= 2; j++)
if (reg[j] != -1) {
reg[j] = (reg[j] + j) % n;
q ^= alpha_to[reg[j]];
}
if (!q) {
loc[count] = i % n;
count++;
printf("%3d ", (i%n));
}
}
printf("\n");
if (count == 2)
for (i = 0; i < 2; i++)
recd[loc[i]] ^= 1;
else
printf("incomplete decoding\n");
}
}
else if (s[2] != -1)
printf("incomplete decoding\n");
}
}
void main()
{
int i;
read_p();
generate_gf();
gen_poly();
seed = 1;
srand(seed);
data[0]=1;
data[1]=1;
data[2]=1;
data[3]=0;
data[4]=0;
data[5]=1;
data[6]=1;
data[7]=1;
data[8]=1;
data[9]=0;
data[10]=0;
data[11]=0;
data[12]=0;
data[13]=1;
data[14]=1;
data[15]=0;
data[16]=0;
data[17]=1;
data[18]=1;
data[19]=0;
data[20]=1;
encode_bch();
for (i = 0; i < length - k; i++)
recd[i] = bb[i];
for (i = 0; i < k; i++)
recd[i + length - k] = data[i];
printf("c(x) = ");
for (i = 0; i < length; i++) {
printf("%1d", recd[i]);
if (i && ((i % 70) == 0))
printf("\n");
}
printf("\n");
printf("Enter the number of errors and their positions: ");
scanf("%d", &numerr);
for (i = 0; i < numerr; i++)
{
scanf("%d", &errpos[i]);
recd[errpos[i]] ^= 1;
}
printf("r(x) = ");
for (i = 0; i < length; i++)
printf("%1d", recd[i]);
printf("\n");
decode_bch();
printf("Results:\n");
printf("original data = ");
for (i = 0; i < k; i++)
printf("%1d", data[i]);
printf("\nrecovered data = ");
for (i = length - k; i < length; i++)
printf("%1d", recd[i]);
printf("\n");
for (i = length - k; i < length; i++)
if (data[i - length + k] != recd[i])
decerror++;
if (decerror)
printf("%d message decoding errors\n", decerror);
else
printf("Succesful decoding\n");
}
|
|
|
|
|
My Code.
<br />
void CChildView::SortData( LPCTSTR pszData)<br />
<br />
TCHAR buffer[10];<br />
_tcsncpy( buffer, pszData, 10);<br />
<br />
char AsciiStr[10];<br />
WideCharToMultiByte (CP_ACP, 0, buffer, -1, AsciiStr, 10, NULL, NULL);<br />
<br />
ofstream testFile("test.txt", ios::app);<br />
testFile << AsciiStr;<br />
testFile.close();<br />
<br />
Now sometimes it saves the data into test.txt file correctly, but then at other times it just saves little scares and vertical lines. wich I can't find in the ASCII table. It doesn't matter even if I code testFile << "testing"; still shows the unknown scquares and lines, one for each character.
Now I have tried a number of combinations, such as removing big chunks of code and restarting my pc, even chaning ofstream testFile (" test.txt", ios::out);
|
|
|
|
|