win32SDK的hello,world程序
首次用Code::Blocks写Win32GUI程序,关于GDI+的引用摸索了半天。SDK写GUI比较累人,以后还是考虑Qt或者其他方式。
代码:
/**
*code by lichmama from cnblogs.com
*@platform: code::blocks 13.12/windows xp
*/
#if defined(UNICODE) && !defined(_UNICODE)
#define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
#define UNICODE
#endif #include <tchar.h>
#include <windows.h>
#include ".\gdiplus.h" #define BUTTON 101
#define WS_EX_LAYERED 0x80000
#define GWL_EXSTYLE (-20)
#define LWA_ALPHA 2
#define SC_DRAGMOVE 0xF012 /* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
typedef BOOL (WINAPI *PFSLWA) (HWND hWnd, COLORREF cr, BYTE bAlpha, DWORD dwFlags);
PFSLWA SetLayeredWindowAttributes; /* Make the class name into a global variable */
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp"); int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX); /* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = ; /* No extra bytes after the window class */
wincl.cbWndExtra = ; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return ; /* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
, /* Extended possibilites for variation */
szClassName, /* Classname */
NULL, //_T("Code::Blocks Template Windows App"), /* Title Text */
WS_POPUP, //WS_OVERLAPPEDWINDOW, /* default window */
, /* Windows decides the position */
, /* where the window ends up on the screen */
, /* The programs width */
, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
); /* Make the window visible on the screen */ ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusInput;
GdiplusStartup(&gdiplusToken, &gdiplusInput, NULL);
ShowWindow(hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, , ))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
} /* The program return-value is 0 - The value that PostQuitMessage() gave */
Gdiplus::GdiplusShutdown(gdiplusToken);
return messages.wParam;
} /* This function is called by the Windows function DispatchMessage() */ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:
//SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_CAPTION);
//SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME);
SetWindowRgn(hwnd, CreateRoundRectRgn(,,,,,), TRUE);
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE)|WS_EX_LAYERED);
{
HMODULE hmod;
hmod=(HMODULE)LoadLibrary("user32.dll");
SetLayeredWindowAttributes=(PFSLWA)GetProcAddress(hmod, "SetLayeredWindowAttributes");
SetLayeredWindowAttributes(hwnd, , , LWA_ALPHA);
CloseHandle(hmod);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HBITMAP hbmp;
BITMAP bmp;
HDC hmemdc;
HDC hdc;
BeginPaint(hwnd, &ps);
hdc=GetWindowDC(hwnd);
hbmp=(HBITMAP)LoadImage(NULL,
"D:\\12.bmp",
IMAGE_BITMAP,
,
,
LR_DEFAULTSIZE|LR_LOADFROMFILE);
GetObject(hbmp, sizeof(bmp), &bmp);
hmemdc=CreateCompatibleDC(NULL);
SelectObject(hmemdc, hbmp);
BitBlt(hdc, , , bmp.bmWidth, bmp.bmHeight, hmemdc, , , SRCCOPY);
DeleteObject(hbmp);
DeleteDC(hmemdc);
ReleaseDC(hwnd, hdc);
EndPaint(hwnd, &ps);
} {
PAINTSTRUCT ps;
HDC hdc;
UINT width;
UINT height;
WCHAR file[]={L"D:\\3.png"};
BeginPaint(hwnd, &ps);
hdc=GetWindowDC(hwnd);
Gdiplus::GpImage *image;
Gdiplus::GpGraphics *graphics;
Gdiplus::DllExports::GdipLoadImageFromFile(file, &image);
Gdiplus::DllExports::GdipCreateFromHDC(hdc, &graphics);
Gdiplus::DllExports::GdipGetImageWidth(image, &width);
Gdiplus::DllExports::GdipGetImageHeight(image, &height);
Gdiplus::DllExports::GdipDrawImageRect(graphics, image, , , width*0.1, height*0.1);
Gdiplus::DllExports::GdipDisposeImage(image);
Gdiplus::DllExports::GdipDeleteGraphics(graphics);
ReleaseDC(hwnd, hdc);
EndPaint(hwnd, &ps);
}
break;
case WM_LBUTTONDOWN:
{
//(700,10)-(751.61)
UINT cx=LOWORD(lParam);
UINT cy=HIWORD(lParam);
if(cx>= && cx<=){
if(cy>= && cy<=){
if(MessageBox(hwnd, "你希望退出程序么?", "MessageBox", MB_YESNO)==IDYES)DestroyWindow(hwnd);
break;
}
}
}
SendMessage(hwnd,WM_SYSCOMMAND,SC_DRAGMOVE,);
break;
case WM_DESTROY:
PostQuitMessage (); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
} return ;
}
贴张图:

win32SDK的hello,world程序的更多相关文章
- win32SDK的hello,world程序(二)
接上篇,原生的控件都不太好看,所以决定自己画一个,稍微处理下消息就能用了.不过,美化这东西是需要天赋的.即使技术再好,没有对UI布局调整和良好的审美能力,做出来的东西还是很挫. 主要把消息逻辑和画的过 ...
- 《白手起家Win32SDK应用程序》(完整版+目录)
<白手起家Win32SDK应用程序> 目 录 <白手起家Win32SDK应用程序> 第一篇.预备知识 第二篇.创建Win32工程和主函数 第三篇.增加一个回调函数 第四篇.注册 ...
- Win32SDK应用程序
转自:https://blog.csdn.net/jxf_ioriyagami/article/details/1486626 1 说在前面 由于VC6及MFC的特点,我们许多人从标准C++学习 ...
- windows下VC界面 DIY系列1----写给想要写界面的C++程序猿的话
非常早就想写关于C++ UI开发的一系列博文,博客专栏刚审核通过,就立即開始刷博文,不能辜负自己的一番热血,我并非写界面的高手,仅仅想通过写博文提高我自己的技术积累,也顺便帮助大家解决界面开发的瓶颈. ...
- JavaScript之父Brendan Eich,Clojure 创建者Rich Hickey,Python创建者Van Rossum等编程大牛对程序员的职业建议
软件开发是现时很火的职业.据美国劳动局发布的一项统计数据显示,从2014年至2024年,美国就业市场对开发人员的需求量将增长17%,而这个增长率比起所有职业的平均需求量高出了7%.很多人年轻人会选择编 ...
- 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用
有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...
- 微信小程序开发心得
微信小程序也已出来有一段时间了,最近写了几款微信小程序项目,今天来说说感受. 首先开发一款微信小程序,最主要的就是针对于公司来运营的,因为,在申请appid(微信小程序ID号)时候,需要填写相关的公司 ...
- node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理
一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...
- 微信应用号(小程序)开发IDE配置(第一篇)
2016年9月22日凌晨,微信宣布“小程序”问世,当然只是开始内测了,微信公众平台对200个服务号发送了小程序内测邀请.那么什么是“小程序”呢,来看微信之父怎么说 看完之后,相信大家大概都有些明白了吧 ...
随机推荐
- JDBC进阶
PreparedStatement的使用: conn = DriverManager.getConnection("jdbc:mysql://localhost/mydata?" ...
- 关于JS的return false
之前真的不知道JS里的return false 还能跳出事件. 今天在修改BUG的时候,用到了这个,就去查了一下,为了加深记忆在此处做个总结. retrun true: 返回正确的处理结果. retu ...
- 005---query接口初步
Query session.createQuery(String hql)方法; * hibernate的session.createQuery()方法是使用HQL(hibernate的查询语句)语句 ...
- "php-cgi.exe - FastCGI 进程意外退出" 解决办法
问题描述: win7下iis中php-cgi.exe - FastCGI 进程意外退出 错误提示: HTTP 错误 500.0 - Internal Server Error D:\phpStudy\ ...
- 纯css实现select下拉框并排显示
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- java中static关键字的作用
java中static关键字主要有两种作用: 第一:为某特定数据类型或对象分配单一的存储空间,而与创建对象的个数无关. 第二,实现某个方法或属性与类而不是对象关联在一起 简单来说,在Java语言中,s ...
- 在chrome下鼠标拖动层变文本形状的问题
学JQ也有一段时间了,想自己写个鼠标拖动层移动的效果(很简单,只是为了练习而已)于是就写下了下面的代码 <!DOCTYPE html> <html> <head> ...
- windows embedded compact 2013 正版免费下载
不知道wince2013是不是真的免费了,不过可以试一下! 下载地址:http://www.microsoft.com/en-us/download/details.aspx?id=39268 你仍然 ...
- 提高java编程质量 - (三)三目运算符的两个操作数类型尽量一致
先看一个例子: package com.test; public class TernaryOperator { public static void main(String[] args) { in ...
- java书系列之——前言
第1章Java的起源 对于计算机语言的发展史,业界一般认为:B语言导致了C语言的诞生,C语言演变出了C++语言,而C++语言将让位于Java语言.要想更好地了解Java语言,就必须了解它产生的原因.推 ...