@SpaceWorm: He doesn't mean to draw an image over a window, but he means this:
http://www.resedit.net/
You can compose your window with this and pack it in a "Resource file" as a Dialog.
@IWishIKnew: When you create a window, Windows sends you lots of informations about what is the user doing, like, moving the mouse, clicking around, pressing keys, moving the window, etc...
But, where does it sends you these informations?
To your WndProc/DlgProc.
Your DlgProc is a function, and it will look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
INT_PTR CALLBACK YourWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg) // Msg will contain the current event that's happening.
{
case WM_INITDIALOG:
// Dialog is being created here.
return 1;
case WM_QUIT:
// Dialog is being destroyed here.
return 1;
case WM_CLOSE:
// User is asking you to close your program here.
if(AllowUserToCloseProgram) // If you want user to be able to close the program,
{
EndDialog(hWnd,0); // Close it.
}
return 1;
case WM_TIMER: // Will be used if you want to use timers.
// Right now, it's useless tho.
return 1;
case WM_COMMAND: // A button is pressed!
switch(LOWORD(wParam)) // This contains the ID of the pushed button/item.
// Basically, if you made an item with id IDC_BUTTON1,
// then LOWORD(wParam) will be IDC_BUTTON1 once pushed.
{
case IDC_BUTTON1:
// First button pushed
return 1;
}
return 0;
}
return 0;
}
|
For other Window items, like static text and such, you have functions like SetWindowText and GetWindowText, or SetDlgItemText or GetDlgItemText for your uses:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645521(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms645489(v=vs.85).aspx
For other infos, just search on the MSDN.
MSDN has informations for all Window items and Messages.
http://msdn.microsoft.com/en-us/library/ms644927%28v=VS.85%29.aspx
Another information:
You will not need a message loop for dialogs.
You just need to write
DialogBox((HINSTANCE)GetModuleHandle(0),MAKEINTRESOURCE( IDD_DIALOG1 ),0, YourWindowProc);
where you want your Dialog to be created at.
Working example (IDD_DIALOG1 and IDC_BUTTON1 required, so, a dialog with a push button):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
INT_PTR CALLBACK YourWindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_BUTTON1:
MessageBoxA(hWnd,"Button Clicked!","Info",MB_ICONASTERISK);
return 1;
}
return 0;
}
case WM_INITDIALOG:
MessageBoxA(hWnd,"Dialog Created!","Info",MB_ICONASTERISK);
return 1;
case WM_CLOSE:
if(MessageBoxA(hWnd,"Destroy Dialog?","Question",MB_ICONQUESTION|MB_YESNO) == IDOK)
{
EndDialog(hWnd,0);
}
return 1;
case WM_QUIT:
MessageBoxA(hWnd,"Dialog being closed","Info",MB_ICONASTERISK);
return 1;
}
return 0;
}
int main(int argc, char** argv)
{
DialogBox((HINSTANCE)GetModuleHandle(0),MAKEINTRESOURCE( IDD_DIALOG1 ),0, YourWindowProc);
return 0;
}
|
Other infos:
HWND is a
Wi
ndow
Handle.
WPARAM and LPARAM are the same type now, 32-bit, where long ago one was 16-bit and the other 32-bit.
HINSTANCE is a
Handle to a Program
Instance. This was also used long ago, and it's still being used for few things.
MessageBoxA shows the default
MessageBox "Alert" window, for the
Ascii text mode.
For the unicode, you can use MessageBoxW (
Wide).
For both, use MessageBox and
TCHAR's.
This is the very bare bones GUI program, using Dialogs.