| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2383 人关注过本帖
标题:[分享]情人节写了个情书给女友
取消只看楼主 加入收藏
aiyuheng
Rank: 1
等 级:新手上路
威 望:1
帖 子:656
专家分:0
注 册:2006-1-12
收藏
 问题点数:0 回复次数:4 
[分享]情人节写了个情书给女友

刚接触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) ;

}

搜索更多相关主题的帖子: 情人节 情书 女友 分享 
2006-02-14 00:12
aiyuheng
Rank: 1
等 级:新手上路
威 望:1
帖 子:656
专家分:0
注 册:2006-1-12
收藏
得分:0 

//.H
#define LOVELETTER 100


#define MENU_FILE_ID_OPEN 1000
#define MENU_FILE_ID_CLOSE 1001
//.RC
#include "MENU.h"


LOVELETTER MENU DISCARDABLE
BEGIN
POPUP "&LOVE"
BEGIN
MENUITEM "&LOVE", MENU_FILE_ID_OPEN
MENUITEM "&Close", MENU_FILE_ID_CLOSE
END
END


when i want to ask anyone,i will ask myself first.
2006-02-14 00:12
aiyuheng
Rank: 1
等 级:新手上路
威 望:1
帖 子:656
专家分:0
注 册:2006-1-12
收藏
得分:0 
本来还想写个图标和鼠标来着,可是实在困了 ,就没写

when i want to ask anyone,i will ask myself first.
2006-02-14 00:15
aiyuheng
Rank: 1
等 级:新手上路
威 望:1
帖 子:656
专家分:0
注 册:2006-1-12
收藏
得分:0 

WINDOWS仍将是家庭,办公等的主要操作系统.
在这方面应该还有广阔的天地.有兴趣的朋友可以一起学习并进步!


when i want to ask anyone,i will ask myself first.
2006-02-14 20:40
aiyuheng
Rank: 1
等 级:新手上路
威 望:1
帖 子:656
专家分:0
注 册:2006-1-12
收藏
得分:0 
VC 建工程为WIN32 Application

when i want to ask anyone,i will ask myself first.
2006-02-15 22:16
快速回复:[分享]情人节写了个情书给女友
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023223 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved