基于wnidowAPI的对话框应用程序框架

#include "resource.h"


LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// 创建主对话框,用CreateDialog创建的是非模态对话框,而DialogBox则是模态对话框,自己参考MSDN
HWND hMain = NULL;

hMain = CreateDialog( hInstance, (LPCTSTR)( IDD_ABOUTBOX ), NULL, (DLGPROC)About );

::SetWindowPos( hMain, HWND_TOP, 250,200, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
// ShowWindow( hMain, SW_SHOW) // 有了上边一句,这个就不用啦
::UpdateWindow( hMain );

if( NULL == hMain )
{
::MessageBox( NULL, "CreateWindow error ", "error ", MB_OK );
return -1;
}
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if( !::IsDialogMessage( hMain, &msg ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return msg.wParam;
}






// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));//只用这个的话,只会关闭对话框,但是没有关闭应用程序
PostQuitMessage( 0 );
return TRUE;
}
break;
}
return FALSE;
}


实在不怎么喜欢MFC。。API顺眼多了

posted @ 2011-11-07 20:23  ☆A希亿  阅读(306)  评论(0编辑  收藏  举报