|
-
February 22nd, 2008, 07:00 PM
#4
Re: Events on WinApi C++
I don't much care for the tutorial you were looking at. If you are serious about learning windows, a good place to start is with Charles Petzold's Programming Windows 5th Edition.
In the meantime, I banged out a sample that works based on your code. It is compiled for UNICODE so you will have to set that in your project options.
Code:
#include <windows.h>
const WCHAR* App_Title = L"Skoumas and the brains at the kangela";
const UINT idButton = 101;
LRESULT WINAPI MyDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CLOSE:
{
int apantisi;
apantisi = MessageBox(NULL, L"Are you Sure?",App_Title,1);
if (apantisi==1)
{
PostQuitMessage(0);
}
}
break;
case WM_COMMAND:
if (LOWORD(wParam) == idButton && HIWORD(wParam) == BN_CLICKED)
{
int apantisi;
apantisi = MessageBox(NULL, L"Are you Sure?",App_Title,1);
if (apantisi==1)
{
PostQuitMessage(0);
}
}
break;
default:
break;
}
return 0;
}
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
HWND hDlg = CreateWindowEx(0, WC_DIALOG, App_Title, WS_OVERLAPPEDWINDOW | WS_VISIBLE,
600, 100, 400, 200, NULL, NULL, NULL, NULL);
if (hDlg)
{
SetWindowLong(hDlg, DWL_DLGPROC, (long) MyDlgProc);
HWND hwndBtn = CreateWindowEx(0, L"BUTTON", L"My Button", BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD,
50, 50, 100, 25, hDlg, (HMENU)idButton, NULL, NULL);
if (hwndBtn)
{
ShowWindow(hDlg, SW_SHOWNORMAL);
UpdateWindow(hDlg);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return 0;
}
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
|