|
this is my test code, it runs good on my computer, but on other computer , can not see the progress dialog,why ?:
(Are there any other methods to show a progress dialog to a no window procedure except multithread?)
////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <process.h>
#include <commctrl.h>
#include "resource.h"
/*-------------------------------------------------------------------------*/
#define WM_PROGRESS WM_USER+1
typedef struct
{
HWND hDlg;
HWND hProgress;
HINSTANCE hInst;
}MyParams, *ptMyParams;
/*-----------------------------------------------------------------------*/
BOOL CALLBACK MyDlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
void Thread1(PVOID pvoid);
/*------------------------------------------------------------------------*/
void Thread1(PVOID pvoid)
{
ptMyParams pt=(ptMyParams)pvoid;
DialogBoxParam(pt->hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, MyDlgProc, (LPARAM)pt);
_endthread();
}
/*------------------------------------------------------------------------*/
BOOL CALLBACK MyDlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
ptMyParams pt;
switch(Message)
{
case WM_INITDIALOG:
pt = (ptMyParams)lParam;
pt->hDlg = hWnd;
pt->hProgress = GetDlgItem(hWnd, IDC_PROGRESS1);
return TRUE;
}
return FALSE;
}
/*------------------------------------------------------------------------*/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdshow)
{
static MyParams myParam;
int i;
myParam.hInst=hInstance;
_beginthread(Thread1, 0, &myParam);
Sleep(1000);
SendMessage(myParam.hProgress, PBM_SETRANGE, 0, MAKELPARAM(0, 30));
for(i=0;i<30;i++)
{
SendMessage(myParam.hProgress, PBM_SETPOS, i, 0);
Sleep(20);
}
Sleep(1000);
EndDialog(myParam.hDlg, 0);
return 0;
}
////////////////////////////////////////////////////////////////////////////
-- modified at 1:17 Tuesday 15th May, 2007
|
|
|
|
|
Do you get any error on another computers when run your program?
|
|
|
|
|
NO, when i click the exe, i can not see any thing, but the process table shows the procedure until end.
you can run on you computer , the resource just only a dialog with a progress bar.
help, Please!!!
|
|
|
|
|
You said it works on your computer perfect,but when you run it on another computer it doesnt show progress bar,did you try to run exe file or compile source code on another computer?
|
|
|
|
|
|
no , i compile the project on other computer , and run the exe, it is same, i can not see anything.
so, i try to use signal , it is same.
|
|
|
|
|
Besides the problems of using Sleep() for synchronization and improper use of EndDialog(), you
loop for less than a second. Is the dialog gone before it has a chance to paint itself?
Does the loop complete before the dialog is even finished being created?
Using Sleep() for thread synchronization will be problematic at best.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
if i use signal , the condition is same.
|
|
|
|
|
i change the Sleep(20) to Sleep(2000); result is same,
and i debug the project, i received the WM_INITDIALOG msg , so this means the dialog is created, just i can`t see it!!!
what happen in your computer to run this precedure?
i have try 3 machines, just the one which build the project can see the dialog!!!
|
|
|
|
|
I compile your code but I think it doesnt receive WM_INITDIALOG and it seems that hProgress=0x00
|
|
|
|
|
zhongwenjia wrote: what happen in your computer to run this precedure?
It worked fine (XP Pro, SP2).
I did have to add
INITCOMMONCONTROLSEX initcontrols;
initcontrols.dwSize = sizeof(INITCOMMONCONTROLSEX);
initcontrols.dwICC = ICC_PROGRESS_CLASS;
::InitCommonControlsEx(&initcontrols);
to get my dialog to create.
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Here's your code, modified to use a thread synchronization object...
#define WM_DLGCREATED WM_USER+1
#define WM_PROGRESS WM_USER+2
typedef struct
{
HWND hDlg;
HANDLE hDlgCreatedEvent;
HWND hProgress;
HINSTANCE hInst;
}MyParams, *ptMyParams;
/*-----------------------------------------------------------------------*/
BOOL CALLBACK MyDlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
void Thread1(PVOID pvoid);
/*------------------------------------------------------------------------*/
void Thread1(PVOID pvoid)
{
ptMyParams pt=(ptMyParams)pvoid;
DialogBoxParam(pt->hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, MyDlgProc, (LPARAM)pt);
_endthread();
}
/*------------------------------------------------------------------------*/
BOOL CALLBACK MyDlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
ptMyParams pt;
switch(Message)
{
case WM_INITDIALOG:
pt = (ptMyParams)lParam;
pt->hDlg = hWnd;
pt->hProgress = GetDlgItem(hWnd, IDC_PROGRESS1);
::PostMessage(hWnd, WM_DLGCREATED, 0, lParam);
return TRUE;
case WM_DLGCREATED:
pt = (ptMyParams)lParam;
::SetEvent(pt->hDlgCreatedEvent);
return TRUE;
}
return FALSE;
}
/*------------------------------------------------------------------------*/
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
INITCOMMONCONTROLSEX initcontrols;
initcontrols.dwSize = sizeof(INITCOMMONCONTROLSEX);
initcontrols.dwICC = ICC_PROGRESS_CLASS;
::InitCommonControlsEx(&initcontrols);
static MyParams myParam;
int i;
myParam.hInst=hInstance;
myParam.hDlgCreatedEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
_beginthread(Thread1, 0, &myParam);
::WaitForSingleObject(myParam.hDlgCreatedEvent, INFINITE);
::CloseHandle(myParam.hDlgCreatedEvent);
myParam.hDlgCreatedEvent = 0;
SendMessage(myParam.hProgress, PBM_SETRANGE, 0, MAKELPARAM(0, 30));
for(i=0;i<30;i++)
{
SendMessage(myParam.hProgress, PBM_SETPOS, i, 0);
Sleep(100);
}
Sleep(1000);
EndDialog(myParam.hDlg, 0);
return 0;
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
hi.
I have this error that pointed to this code:
// Get a pointer to the current document
CVector3DDoc * pDoc = GetDocument();
m_pLead.m_aValue = pDoc->m_aLead; // error occur here in view class
Can I do this? m_aLead is a variable in Doc class while m_pLead is a variable in view class. both m_aLead and m_pLead.m_aValue is an array. I am trying to get the data in the Doc class to view class..Thanks.
|
|
|
|
|
What you need to do to copy those depends on what kind of arrays you have. If they are of type CArray or similar, there is a member function CArray::Copy to achieve this. Others require you go through and copy each element in the array to a corresponding index on the destination array.
However, if it's an array of pointers, you want to think this through carefully and understand who points to what an who is reponsible for resource cleanup so you don't dangle pointers later on.
In a nutshell, the assignment operator = is usually not used to copy arrays.
|
|
|
|
|
In a nutshell, the assignment operator = is usually not used to copy arrays.
Why do you think so? operator = is usual and natural for a concrete entity as far as the term 'assignment' itself is natural. An array may be assigned to another one which I think is natural [I'm not speaking about the correct ways of doing that]. For instance, std::vector has the = operator overloaded which, I'm pretty sure, is used extensivelly.
--
=====
Arman
|
|
|
|
|
Good point. I don't use STL so I wasn't aware of that.
Would it be safe to say the assignment operator is not usually used to copy arrays unless your using STL and a vector?
|
|
|
|
|
If it is a normal language array such as char lead[10] , then the compiler does not generate the code to copy for you. If you where expecting dynamic copy and or creation, then you need to use a container class like vector for that.
char a1[10] = {};
char a2[10];
memcpy(a2,a1,10);
Or with vector
std::vector<char> b1;
std::vector<char> b2;
b2 = b1;
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
I have created a IP address control dynamically.
How to add a event handler for those controls.
How to use event handlers with dynamically created control.
|
|
|
|
|
Generally, three things to be done;
*) decide which exact command to handle
*) prepare the handler function [whose prtototype is influenced by the cammand to be handled]
*) map the command to the handler
As for ip control, I guess you are trying to handle the IPN_FIELDCHANGED notifycation. So you would have a handler like this;
void CMyDialog::OnFieldChangedIpAddress(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMIPADDRESS pIPAddr = reinterpret_cast<LPNMIPADDRESS>(pNMHDR);
*pResult = 0;
}
And map it to the notifycation inside BEGIN_MESSAGE_MAP/END_MESSAGE_MAP pair like so;
ON_NOTIFY(IPN_FIELDCHANGED, IDC_MYIPADDRESS, OnFieldChangedIpAddress)
--
=====
Arman
|
|
|
|
|
ON_NOTIFY(IPN_FIELDCHANGED, IDC_MYIPADDRESS, OnFieldChangedIpAddress)
I cant use the control id directly because i created control dynamically.
How to add On_notify for dynamically created one
|
|
|
|
|
You can and hou have to. The last parameter of CIPAddressCtrl::Create takes the id of the newly creating control. So define an id inside resource.h file and pass it to the Create method.
PS. To define an id, go to menu option Edit\Resource Synbols... and then choose New... .
--
=====
Arman
|
|
|
|
|
how to use this id to call notify event
|
|
|
|
|
You should not bother about calling notify events. This is done by the system. So your job is to handle the notifyfication only. See my first post; it describes what you need to do.
--
=====
Arman
|
|
|
|
|
prathuraj wrote: I cant use the control id
How do you make IP address control ? CIPAddressCtrl::Create(....,UINT nID); or CIPAddressCtrl::CreateEx(...,UINT nID);
|
|
|
|
|
CIPAddressCtrl* pIPAdd = new CIPAddressCtrl;
pIPAdd->Create(WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_BORDER|ES_AUTOHSCROLL,
CRect(x,y,x+sz.cx,y+sz.cy),this,nID);
|
|
|
|
|