|
Hi,
Thanks for your reply, your answer satisfies completely my need and sorry for my late reply.
|
|
|
|
|
you're welcome...
i'm here to help the best i can, so i'm happy my answer is exactly what you expected of one of us...
see you on CP...
cheers,
(ps: when an article satisfy you, you can vote for it... )
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
First, I apologize for the remedial question. I am fairly new to Windows Programming (5+ yrs embedded C though).
I have an MFC dialog based ap which has a "RUN" button. The Run button starts a measurement function which interfaces with pieces of test equipment over COM1 and GPIB.
Currently, the measurement function takes ~4 minutes, during which time the dialog is frozen.
I want to make the program multithread so that controls in the dialog, Oven Temperature for example, update during the measurement function.
I am a bit confused how to use a UI thread with my current dialog box.
Can someone offer some tips on how to convert the current dialog based ap to make use a UI thread and several worker threads (I understand the worker thread part).
Thanks a bunch.
|
|
|
|
|
Try here[^].
Software Zen: delete this;
|
|
|
|
|
hi:thx all
please have a look at the following program:
const CStudent& operator =(const CStudent& s)
{...... }
BOOL operator ==(const CStudent& s) const {...... }
what is the diffence putting const between before the definition of function and at the end of definition of function?
|
|
|
|
|
In the first case, the const is used to specify the return type. The return value can't be used as an "l-value" (i.e. on the left hand side of an equals sign) in another expression. So operator = in the case above is returning a const reference to a CStudent object.
In the second case const specifies that the function itself will not modify any of the internal data of the class declaring the operator == method. If the operator == function tried to modify any of the internal CStudent data, you'd get a compiler error.
Hope it helps!!
Bob Ciora
|
|
|
|
|
Hello,
Can anyone tell what is the use for the declaration of global objects in MFC programming?
Hoping for a reply,
Philip
|
|
|
|
|
Which objects are you referring to?
Are you asking how to do it?
Software Zen: delete this;
|
|
|
|
|
Decalaring a global object ensures that your object instance exists before your MFC application runs, and that it will be destructed after your application exits. Your CWinApp -derived main application class in an MFC program is a global object.
Bob Ciora
|
|
|
|
|
Hello,
This question is for an MFC application.
How can I know if the user is pressing on a button for more than 250msec?
As far I know, I get the BN_CLICKED only once, and only when the user releases the button
Any hint?
-- Ricky Marek (AKA: rbid)
-- "Things are only impossible until they are not" --- Jean-Luc Picard
My articles
|
|
|
|
|
Create your own button class CMyButton , which subclasses the existing CButton . Add a handler for the WM_LBUTTONDOWN message to CMyButton . In the handler, post a notification to the parent dialog like this:
WPARAM wParam = MAKEWPARAM(GetDlgCtrlID(),BN_PRESSED);
LPARAM lParam = (LPARAM)m_hWnd;
GetParent()->PostMessage(WM_COMMAND,wParam,lParam);
where BN_PRESSED is a notification code you've defined. In your dialog, add a handler for the BN_PRESSED notification. In the handler, start a timer (try using QueryPerformanceCounter ). In your BN_CLICKED handler, get the value of the timer and compare the difference.
Software Zen: delete this;
|
|
|
|
|
LONG MCIWndSave(
hwnd,
szFile
);
MSDN mention that if the szFile is -1, then it will pop up a sava dialog box to let me choose the location for the wav file that i have recorded. But it never come out even though i have written... How come?
Another question is how can i disable the play button when i use MCIWndCreate? There is no option to let me disable the play button. For menu and record have, but play button don't have. (actually i just need the trackbar)
|
|
|
|
|
|
Hacking is what keeps me up nights - unit tests let me sleep at night. I tests!
Just wanted to share...
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Whatever works for you! But all true hackers drink gallons of coffee and never sleep :p
Bob Ciora
|
|
|
|
|
Doesn't matter. I test and test and test. Then I scream we need a seperate test group. I still wake up in the middle of the night once in a while when I realize I forgot to test some obscure case. Or when a customer discovers one bug and I realize it has a more general case that is likely to hit others.
It helps to have a seperate test group, but even when I was lucky enough to have a good one the above happened.
|
|
|
|
|
Unit tests are not a substitute for system testing! But they help identify bugs a lot sooner by focusing on specific APIs. As a matter of habit, I write unit tests for (virtually all) API calls before implementing the APIs themselves.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
hdc = GetDC (hwnd) ;<br />
hdcMem = CreateCompatibleDC (hdc) ;<br />
hBitmap = CreateCompatibleBitmap (hdc, cxTotal, cyTotal) ;<br />
ReleaseDC (hwnd, hdc) ;<br />
<br />
SelectObject (hdcMem, hBitmap) ;<br />
Rectangle (hdcMem, -1, -1, cxTotal + 1, cyTotal + 1) ;<br />
<br />
hBrush = CreateHatchBrush (HS_DIAGCROSS, 0L) ;<br />
SelectObject (hdcMem, hBrush) ;<br />
SetBkColor (hdcMem, RGB (255, 0, 255)) ;<br />
Ellipse (hdcMem, cxMove, cyMove, cxTotal - cxMove, cyTotal - cyMove) ;
================
The hwnd has a white background color, I wonder how's the preceding codes turn out to be a cyTotal * cxTotal rectangular(white bkground) and within which is a centered circle(pink bkground) painted with hatched brush. How's the code " Rectangle (hdcMem, -1, -1, cxTotal + 1, cyTotal + 1) " play a part? Could anybody give me a explanations in details
The following is the complete source code
#include <windows.h><br />
#define ID_TIMER 1<br />
<br />
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;<br />
<br />
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,<br />
PSTR szCmdLine, int iCmdShow)<br />
{<br />
static TCHAR szAppName[] = TEXT ("Bounce") ;<br />
HWND hwnd ;<br />
MSG msg ;<br />
WNDCLASS wndclass ;<br />
<br />
wndclass.style = CS_HREDRAW | CS_VREDRAW ;<br />
wndclass.lpfnWndProc = WndProc ;<br />
wndclass.cbClsExtra = 0 ;<br />
wndclass.cbWndExtra = 0 ;<br />
wndclass.hInstance = hInstance ;<br />
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;<br />
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;<br />
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;<br />
wndclass.lpszMenuName = NULL ;<br />
wndclass.lpszClassName = szAppName ;<br />
<br />
if (!RegisterClass (&wndclass))<br />
{<br />
MessageBox (NULL, TEXT ("This program requires Windows NT!"),<br />
szAppName, MB_ICONERROR) ;<br />
return 0 ;<br />
}<br />
<br />
hwnd = CreateWindow (szAppName, TEXT ("Bouncing Ball"),<br />
WS_OVERLAPPEDWINDOW,<br />
CW_USEDEFAULT, CW_USEDEFAULT,<br />
CW_USEDEFAULT, CW_USEDEFAULT,<br />
NULL, NULL, hInstance, NULL) ;<br />
<br />
ShowWindow (hwnd, iCmdShow) ;<br />
UpdateWindow (hwnd) ;<br />
<br />
<br />
while (GetMessage (&msg, NULL, 0, 0))<br />
{<br />
TranslateMessage (&msg) ;<br />
DispatchMessage (&msg) ;<br />
}<br />
return msg.wParam ;<br />
}<br />
<br />
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)<br />
{<br />
static HBITMAP hBitmap ;<br />
static int cxClient, cyClient, xCenter, yCenter, cxTotal, cyTotal,<br />
cxRadius, cyRadius, cxMove, cyMove, xPixel, yPixel ;<br />
HBRUSH hBrush ;<br />
HDC hdc, hdcMem ;<br />
int iScale ;<br />
<br />
switch (iMsg)<br />
{<br />
case WM_CREATE:<br />
hdc = GetDC (hwnd) ;<br />
xPixel = 1 ;<br />
yPixel = 1 ;<br />
ReleaseDC (hwnd, hdc) ;<br />
<br />
SetTimer (hwnd, ID_TIMER, 50, NULL) ;<br />
return 0 ;<br />
<br />
case WM_SIZE:<br />
xCenter = (cxClient = LOWORD (lParam)) / 2 ;<br />
yCenter = (cyClient = HIWORD (lParam)) / 2 ;<br />
<br />
iScale = min (cxClient, cyClient) / 16 ;<br />
<br />
cxRadius = iScale;<br />
cyRadius = iScale;<br />
<br />
cxMove = max (1, cxRadius / 2) ;<br />
cyMove = max (1, cyRadius / 2) ;<br />
<br />
cxTotal = 2 * (cxRadius + cxMove) ;<br />
cyTotal = 2 * (cyRadius + cyMove) ;<br />
<br />
if (hBitmap)<br />
DeleteObject (hBitmap) ;<br />
hdc = GetDC (hwnd) ;<br />
hdcMem = CreateCompatibleDC (hdc) ;<br />
hBitmap = CreateCompatibleBitmap (hdc, cxTotal, cyTotal) ;<br />
ReleaseDC (hwnd, hdc) ;<br />
<br />
SelectObject (hdcMem, hBitmap) ;<br />
Rectangle (hdcMem, -1, -1, cxTotal + 1, cyTotal + 1) ;<br />
<br />
hBrush = CreateHatchBrush (HS_DIAGCROSS, 0L) ;<br />
SelectObject (hdcMem, hBrush) ;<br />
SetBkColor (hdcMem, RGB (255, 0, 255)) ;<br />
Ellipse (hdcMem, cxMove, cyMove, cxTotal - cxMove, cyTotal - cyMove) ;<br />
DeleteDC (hdcMem) ;<br />
DeleteObject (hBrush) ;<br />
return 0 ;<br />
<br />
case WM_TIMER:<br />
if (!hBitmap)<br />
break ;<br />
<br />
hdc = GetDC (hwnd) ;<br />
hdcMem = CreateCompatibleDC (hdc) ;<br />
SelectObject (hdcMem, hBitmap) ;<br />
<br />
BitBlt (hdc, xCenter - cxTotal / 2,<br />
yCenter - cyTotal / 2, cxTotal, cyTotal,<br />
hdcMem, 0, 0, SRCCOPY) ;<br />
<br />
ReleaseDC (hwnd, hdc) ;<br />
DeleteDC (hdcMem) ;<br />
<br />
xCenter += cxMove ;<br />
yCenter += cyMove ;<br />
<br />
if ((xCenter + cxRadius >= cxClient) || (xCenter - cxRadius <= 0))<br />
cxMove = -cxMove ;<br />
<br />
if ((yCenter + cyRadius >= cyClient) || (yCenter - cyRadius <= 0))<br />
cyMove = -cyMove ;<br />
<br />
return 0 ;<br />
<br />
case WM_DESTROY:<br />
if (hBitmap)<br />
DeleteObject (hBitmap) ;<br />
<br />
KillTimer (hwnd, ID_TIMER) ;<br />
PostQuitMessage (0) ;<br />
return 0 ;<br />
}<br />
return DefWindowProc (hwnd, iMsg, wParam, lParam) ;<br />
}
|
|
|
|
|
According to Microsoft's documentation for Rectangle, the function draws the outline in the current pen and fills the rectangle with the current brush. Since, at the point Rectangle() is called, neither a Pen nor a Brush has been selected, I'm going to assume that the DC is using PS_NULL as the pen, and a default white brush. This would lead to the result you're describing.
Hope it helps!!
Bob Ciora
|
|
|
|
|
Thanks
But the Rectangle() seems more than just draw a rectangular. When I uncommented that line, the outcome is so different!
|
|
|
|
|
I return to the windows development community in need of some anger and frustration relieving guidance from you guru's. I have the following code :
<br />
#pragma pack(push, 1)<br />
typedef struct<br />
{<br />
u16 _id : 10;<br />
u8 _hflip : 1;<br />
u8 _vflip : 1;<br />
u8 _palettetype : 4;<br />
} MAPDATA;<br />
Correct me if I'm wrong but 10 bits + 1 bit + 1 bit + 4 bits = 16 bits which equates to 2 f**king bytes, yet #pragma pack, push, pop every blinking piece of crap that microsoft has to offer returns 3 bytes when I call sizeof(MAPDATA) ! ! ! If I use #pragma push(2) sizeof then miraculously returns with a 4 byte alignment. This is completely messing up my quantize and save algorithm and I've been up until 2am in the morning trying to figure out why gcc's __attribute__ ((packed)) works like a dream and microsoft's pants #pragma pack counts like an epileptic monkey in a bright multi-coloured jacket.
Thanks all,
and apologies for the frustration.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
1. Why are you using u8 type. If you used u16 again, both compilers might do what you like.
2. I have no idea why you think the pack pragma would do anything here. Everything is being packed byte aligned.
3. The Microsoft and GNU compilers are working as expected. If you would bother to look at the C++ standard, how bitfields are stored is totally implementation defined.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Hey thankyou for the tip off. It came like a dose of paracetemol to me . Here are my answers to some of your questions.
1. Because i didn't see the point in declaring a 16 bit type with a bitfield of less than 8 bits when the 8 bit type is nearer the size i wanted (well that was the thinking).
2. I was assuming the compiler would notice it was trying to pack a 16 bit struct and therefore pack it on a 2 byte boundary as I was requesting.
3. Mmm the weird thing was that I saw that you're supposed to use the 'unsigned' declaration with no size typing so the compilers can make the same choices in their different ways. I think I was just extremely tired, either that or ignorant . I also never bother referencing the c++ standard when using a Microsoft compiler because its tends to break it at will, although the .NET 2003 Visual Studio one is much more compliant (and I'm hoping 2005 will be even better with platform independant project management yay ). I could see that the two compilers had implemented it in their different ways, I just wanted to know what I had to do to get the microsoft implementation to give me the same semantics as gcc.
I was only trying to make a tool for my blinking program, but became frustrated as I wasted the entire evening after coming home from work at 9.30pm (long day) doing something simple like this until 2am (British time). Your response solved it in two seconds. I think it is a lesson learned now though, I shall use the 'unsigned' type declaration instead of a u16 or u8 declaration and leave the packing all up to the compiler.
Thanks again though
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
I take it back, when I make all the struct elements of 'unsigned' type instead of specifying the size (u16), it packs them on a four byte boundary which is just absolutely crap because its soooooooo obvious i want it on a two byte boundary - not only am i specifying the bitfields upto a size of 16bits I'm also TELLING the thing via #pragma pack(2) to shove it on a 2 byte boundary and yet it still cocks it up !
It never ceases to amaze me.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
In my app,I want to use the shared-memory to share the data.But this data is not certain one which can be added or deleted. So, i don't know how to do.
the API-HANDLE CreateFileMapping(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCTSTR lpName
);
DWORD dwMaximumSizeLow:the length of mapping data,but in my app,this length is uncertain.
|
|
|
|
|