刚接触WINAPI 两天,照着葫芦话了个瓢,
在情人节的时候给女朋友写了个情书.
#include <windows.h>
#include "MENU.h"
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("LOVELETTER") ;
HWND hwnd ;
MSG msg ;
WNDCLASSEX wndclass ;
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = (LPCSTR)LOVELETTER;
wndclass.lpszClassName = szAppName ;
wndclass.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
if (!RegisterClassEx (&wndclass))
{
MessageBox ( NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
if (!(hwnd = CreateWindowEx( WS_EX_TOPMOST,szAppName, // window class name
TEXT ("i love you!"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL)))
return 0;// creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int i,j;
int wmId;
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
static HMENU hMenu;
static char *string[11]={" // what you want to say to your lover}; //我的我女朋友说的11行,这里就11了.
switch (message)
{
case WM_CREATE:
return 0;
case WM_COMMAND:
hMenu= GetMenu(hwnd);
wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case MENU_FILE_ID_OPEN:
MessageBox(hwnd,"I love you forever!!!","I love you!",MB_OKCANCEL|MB_ICONWARNING);
return 0;
case MENU_FILE_ID_CLOSE:
DestroyWindow(hwnd);
break;
}
break;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
for (i=0,j=0;i<11&&j<400;i++)
{
TextOut (hdc, 1,j,string[i],strlen(string[i]));
j+=30;
}
TextOut (hdc,400,400,"左上角有我最想对你说的话!!",strlen("左上角有我最想对你说的话!!"));
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}