|
You just pass Hwnd = NULL as parameter.
The return value will be your dialog handel.
try it will work for sure.
|
|
|
|
|
I just tried this and I get NULL pointer on return. I also checked MSDN and it doesn't say anything about first parameter being NULL. In fact it specifically says:
"If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control."
I take that as input dialog boc handle must be valid. Can you share you source of information?
-Saurabh
Edit1:
I checked GetLastError after calling GetDlgItem(NULL, IDD_MYDIALOG) and it says Invalid Window Handle.
Edit2:
Okay just saw that you modified your original post to include MSDN documentation.
|
|
|
|
|
an important concept to know in MFC is that window creation and destruction
are TWO STEP PROCESSES....
1) the C++ object - a CWnd or derived object
2) the operating system object - an HWND
You have only created item 1
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Q)the question is my program run without error but it does not display the output
i need to change the setting options in project can any one tell where to change it
my program is a simple win 32 pgm
#include<windows.h>
#include"resource.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASS wc;
MSG msg;
HWND hMainWnd;
if(hPrevInstance!=0)
{
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.hCursor=LoadCursor(hInstance,MAKEINTRESOURCE(IDC_MYCURSOR));
wc.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_MYICON));
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszClassName="WindowClass";
wc.lpszMenuName=NULL;
}
RegisterClass(&wc);
hMainWnd=CreateWindow("WindowClass","MyfirstWindowsPgm",0,0,0,300,300,NULL,NULL,hInstance,0);
ShowWindow(hMainWnd,nShowCmd);
UpdateWindow(hMainWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hMainWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{ case WM_CREATE: MessageBox(hMainWnd,"Window created","WM_CREATED",MB_OK);
break;
case WM_DESTROY:
MessageBox(hMainWnd,"Window Destroyed","WM_DESTROYED",MB_OKCANCEL);
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
MessageBox(hMainWnd,"left mouse button clicked","WM_LBUTTONDOWN",MB_OK);
break;
default:
return(DefWindowProc(hMainWnd,message,wParam,lParam));
}
return 0;
}
Thanks and Regrads
From Srikanth.Y
|
|
|
|
|
srikanthyenuganti wrote: if(hPrevInstance!=0)
Why are you doing this? Remove this check and application will work fine.
-Saurabh
|
|
|
|
|
thank u
Thanks and Regrads
From Srikanth.Y
|
|
|
|
|
You are welcome.
-Saurabh
|
|
|
|
|
hPrevInstance parameter is kept just for compatibility with Win16 (16 bit) programs.
It will always be NULL for win32 applications.
Regards,
Sandip.
|
|
|
|
|
Q)the question is my program run without error but it does not display the output
i need to change the setting options in project can any one tell where to change it
my program is a simple win 32 pgm
#include<windows.h>
#include"resource.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASS wc;
MSG msg;
HWND hMainWnd;
if(hPrevInstance!=0)
{
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.hCursor=LoadCursor(hInstance,MAKEINTRESOURCE(IDC_MYCURSOR));
wc.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_MYICON));
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszClassName="WindowClass";
wc.lpszMenuName=NULL;
}
RegisterClass(&wc);
hMainWnd=CreateWindow("WindowClass","MyfirstWindowsPgm",0,0,0,300,300,NULL,NULL,hInstance,0);
ShowWindow(hMainWnd,nShowCmd);
UpdateWindow(hMainWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hMainWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{ case WM_CREATE: MessageBox(hMainWnd,"Window created","WM_CREATED",MB_OK);
break;
case WM_DESTROY:
MessageBox(hMainWnd,"Window Destroyed","WM_DESTROYED",MB_OKCANCEL);
PostQuitMessage(0);
break;
case WM_LBUTTONDOWN:
MessageBox(hMainWnd,"left mouse button clicked","WM_LBUTTONDOWN",MB_OK);
break;
default:
return(DefWindowProc(hMainWnd,message,wParam,lParam));
}
return 0;
}
Thanks and Regrads
From Srikanth.Y
|
|
|
|
|
Instead of RegisterClass use RegisterClassEx API. Also intialize
wcex.cbSize = sizeof(WNDCLASSEX);
There is no need to change any settings if you are using the wizard.
|
|
|
|
|
the code runned well when i removed if(!PrevInstance)
Thanks and Regrads
From Srikanth.Y
|
|
|
|
|
How can I send messages from one thread to another?
I want to avoid busy/wait loops.
Thank you.
modified 7-Mar-17 16:41pm.
|
|
|
|
|
If a thread has a message queue (for instance GUI threads have it) then you know how to do it.
As for worker threads this page [^] may help.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
wow 2 votes of 1 .... i guess i fail any reason why this isn't a good messaging scheme?
|
|
|
|
|
I've only just seen your post, so I'm not one of the 2 1's, but pipes are a heavy duty solution that's too cumbersome most of the time.
I've used them myself between processes - the idea was that one of my processes might not even be on the same PC, so they give good flexibility.
But between two threads in the same the same process, I think they're over the top. Especially for worker->ui thread communications. PostMessage works a treat, and fits nicely into the MFC message loop handling. For pipes, you'd need to alter the message pump to wait for events (you have overlapped I/O I hope!) and messages.
For ui->worker thread communications, pipes are more appropriate - especially if it's opened in message mode.
Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
|
|
|
|
|
Hmm u raise a good point, PostMessage() or PostThreadMessage() probably more applicable in this case.
thinking back to when i have used pipes i have been shooting off messages then a chunk of data.
i will admit i like pulling out the nail gun even if i only have to put in one nail
|
|
|
|
|
As a remark, it's also usefull to know that you can access the variables directly (providing you have a way to access them) from within the different threads.
|
|
|
|
|
Hello everyone,
I have correctly set the source path in Windbg. After setting a breakpoint, how to display the related source files so that I can use them as the similar approach in Visual Studio 2008, e.g. using F10 to step next, using F11 to step in something like this.
I have tried ls command in WinDbg, but failed, error message is "No current source file".
thanks in advance,
George
|
|
|
|
|
Has the program you're debugging has symbol files (.PDB files)?
Steve
|
|
|
|
|
Sure, Stephen! I have setup the symbol path. My purpose is to find some "cool and lazy" way which could type a command in command window, and related source file is displayed, currently I have to use File --> Open Source File to open the related source file.
I set the source path by File --> Source Code Path, then input the path of the directory which contains the source codes. Is this correct way to setup source path? Do I need to do anything else in order to setup source path, e.g. reload something?
regards,
George
|
|
|
|
|
Hi,
My application writes into a particular location in Registry
Eg. RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
0, KEY_ALL_ACCESS, &h_Key); //Open a particular registry key
//Write to that registry key.
I need to restrict this activity to only Administrator..
Can I have a code snippet which allows this only for Administrator.
Thanks.
Venkat
|
|
|
|
|
|
Thanks.. But I am getting a compilation error even after including "shlobj.h"
|
|
|
|
|
venkat.kupunaram wrote: I am getting a compilation error
My telescope is missing. Can you tell me what exactly the error is?
|
|
|
|
|