|
-
February 28th, 2006, 12:40 AM
#1
Window creation in C++
can we create a window without using-->
Code:
int APIENTRY WinMain(HINSTANCE hinstance,
HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdshow)
right now i m creating a window using CreateWindow(,,,,) but in this we hav to pass a register class which takes the HINSTANSE of the WinMian function.
I want to know if we can create a window without using this as i have to work on C++ not on Win32 ie
Code:
void main (void)
{
//here i want to create a window
}
Virender
-
February 28th, 2006, 03:19 AM
#2
Re: Window creation in C++
Actually, as far I understand there must be a main loop where you will check the messages comming from windows, and those are tracked in WinMain, secondly each window has its own windows procedure which controls messages of specific window individually.
You may create a window in main like this
Code:
#include <windows.h>
HWND myWin;
int main(int argc, char *argv[])
{
myWin = CreateWindow(
WC_DIALOG,"My Window",
WS_OVERLAPPEDWINDOW,
100,100,400,300,
HWND_DESKTOP,
NULL,
NULL,
NULL
);
ShowWindow(myWin, SW_SHOW);
//do whatsoever is nedded
DestroyWindow(myWin);
return 0;
}
But problem is where are you going to track the messages. there are hundreds of messages which are sent/processed by windows.
If any guru gets to this thread please implement something for this fellow by replacing '//do whatsoever is nedded' with some message map.
I am also interested in knowing the implementation of custom message map rather than using the default method.
I hope it was of a little 0.01% help.
regards
-
February 28th, 2006, 07:05 AM
#3
Re: Window creation in C++
 Originally Posted by Ali Imran
If any guru gets to this thread please implement something for this fellow by replacing '//do whatsoever is nedded' with some message map.
Code:
MSG msg = {0};
while ( GetMessage(&msg, myWin, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Last edited by NoHero; February 28th, 2006 at 07:12 AM.
Reason: typo in the code
-
February 28th, 2006, 07:27 AM
#4
Re: Window creation in C++
 Originally Posted by Ali Imran
But problem is where are you going to track the messages. there are hundreds of messages which are sent/processed by windows.
Yes, indeed there are many hundreds of messages, but luckily we have not to process all of them and just send "not interesting" ones to default window procedure (by a call of DefWindowProc).
 Originally Posted by Ali Imran
If any guru gets to this thread please implement something for this fellow by replacing '//do whatsoever is nedded' with some message map.
Not a place for "message map" there. Maybe a call of SetWindowLong to assign a window procedure followed by a message loop.
Code:
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
switch(nMsg)
{
// ...
// ...
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return ::DefWindowProc(hWnd, nMsg, wParam, lParam);
}
return TRUE;
}
int main(int argc, char* argv[])
{
HWND hWnd = CreateWindow(WC_DIALOG,
"My Window",
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
100,100,400,300,
HWND_DESKTOP,
NULL,
NULL,
NULL);
::SetWindowLong(hWnd, GWL_WNDPROC, (LONG)WndProc);
::UpdateWindow(hWnd);
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
However, I cannot guarantee you'll have not headaches developing the code above and I do not recommend it.
Once you suggested a dialog, much more easier and correct is to call DialogBox or CreateDialog for making a modal or modeless dialog, respectively.
 Originally Posted by Ali Imran
I am also interested in knowing the implementation of custom message map rather than using the default method.
PS. Please, explain what do you mean with "custom message map" and "default method".
-
February 28th, 2006, 07:31 AM
#5
Re: Window creation in C++
You can also handle specific messages that you need to handle(sent in the message loop) with a WindowProcedure.
Code:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(msg)
{
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
return(0);
}break;
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
}break;
default:break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
This returns DefWindowProc that handles the rest of the messages with their defaults. LRESULT is a typedef for long and CALLBACK is a typedef for __stdcall.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|