24,854
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
char class_name[]="my_class";
char window_title[]="GDI_based_application";
//windows procedure
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
static PAINTSTRUCT ps;
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CREATE:
PlaySound("file.wav",NULL,SND_FILENAME|SND_ASYNC);
break;
case WM_PAINT:
BeginPaint(hwnd,&ps);
//draw here
EndPaint(hwnd,&ps);
break;
default:
return DefWindowProc(hwnd,msg,wParam,lParam);
}
return 0;
}
//Program Entry Point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prev,LPSTR lpCmdLine,int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wc={
sizeof(WNDCLASSEX),
0,
WndProc,
0,
0,
hInstance,
LoadIcon(NULL,IDI_APPLICATION),
LoadCursor(NULL,IDC_ARROW),
(HBRUSH)(COLOR_WINDOW+1),
NULL,
class_name,
LoadIcon(NULL,IDI_APPLICATION)
};
RegisterClassEx(&wc);
hwnd= CreateWindowEx(
WS_EX_CLIENTEDGE,
class_name,
window_title,
WS_OVERLAPPED|WS_VISIBLE|WS_CAPTION|WS_SYSMENU,
CW_USEDEFAULT,CW_USEDEFAULT,640,480,
NULL,NULL,hInstance,NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
#ifdef _UNICODE
typedef wchar_t TCHAR;
#define __T(x) L##x
#define _T(x) __T(x)
#else
#define __T(x) x
typedef char TCHAR;
#endif
宏 未定义_UNICODE(ANSI字符) 定义了_UNICODE(Unicode字符)
_tcschr strchr wcschr
_tcscmp strcmp wcscmp
_tcslen strlen wcslen
#include <windows.h>
int main()
{
MessageBox(0, "test", "title", 0);
return 0;
}
WINUSERAPI
int
WINAPI
MessageBoxA(
__in_opt HWND hWnd,
__in_opt LPCSTR lpText,
__in_opt LPCSTR lpCaption,
__in UINT uType);
WINUSERAPI
int
WINAPI
MessageBoxW(
__in_opt HWND hWnd,
__in_opt LPCWSTR lpText,
__in_opt LPCWSTR lpCaption,
__in UINT uType);
#ifdef UNICODE
#define MessageBox MessageBoxW
#else
#define MessageBox MessageBoxA
#endif // !UNICODE