首次用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程序的更多相关文章

  1. win32SDK的hello,world程序(二)

    接上篇,原生的控件都不太好看,所以决定自己画一个,稍微处理下消息就能用了.不过,美化这东西是需要天赋的.即使技术再好,没有对UI布局调整和良好的审美能力,做出来的东西还是很挫. 主要把消息逻辑和画的过 ...

  2. 《白手起家Win32SDK应用程序》(完整版+目录)

    <白手起家Win32SDK应用程序> 目 录 <白手起家Win32SDK应用程序> 第一篇.预备知识 第二篇.创建Win32工程和主函数 第三篇.增加一个回调函数 第四篇.注册 ...

  3. Win32SDK应用程序

    转自:https://blog.csdn.net/jxf_ioriyagami/article/details/1486626 1 说在前面    由于VC6及MFC的特点,我们许多人从标准C++学习 ...

  4. windows下VC界面 DIY系列1----写给想要写界面的C++程序猿的话

    非常早就想写关于C++ UI开发的一系列博文,博客专栏刚审核通过,就立即開始刷博文,不能辜负自己的一番热血,我并非写界面的高手,仅仅想通过写博文提高我自己的技术积累,也顺便帮助大家解决界面开发的瓶颈. ...

  5. JavaScript之父Brendan Eich,Clojure 创建者Rich Hickey,Python创建者Van Rossum等编程大牛对程序员的职业建议

    软件开发是现时很火的职业.据美国劳动局发布的一项统计数据显示,从2014年至2024年,美国就业市场对开发人员的需求量将增长17%,而这个增长率比起所有职业的平均需求量高出了7%.很多人年轻人会选择编 ...

  6. 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用

    有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...

  7. 微信小程序开发心得

    微信小程序也已出来有一段时间了,最近写了几款微信小程序项目,今天来说说感受. 首先开发一款微信小程序,最主要的就是针对于公司来运营的,因为,在申请appid(微信小程序ID号)时候,需要填写相关的公司 ...

  8. node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理

    一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...

  9. 微信应用号(小程序)开发IDE配置(第一篇)

    2016年9月22日凌晨,微信宣布“小程序”问世,当然只是开始内测了,微信公众平台对200个服务号发送了小程序内测邀请.那么什么是“小程序”呢,来看微信之父怎么说 看完之后,相信大家大概都有些明白了吧 ...

随机推荐

  1. 2-LPC1778之GPIO

    其实这篇文章主要是介绍自己为其写的GPIO库,自己借鉴了原子写的STM32,野火写的K60,还有LPC官方库,然后按照自己平时用的,然后写了一个..其实写库的主要目的是为了方便(主要是方便操作)以后自 ...

  2. 《安卓网络编程》之第四篇 处理URL地址

    在Android手机系统中,可以通过URL地址获取网络资源.在URL类的众多方法中,可以使用openStream()方法来读取该URL资源的输入流InputStream.在此方法的基础上可以引申出很多 ...

  3. iOS crash日志分析

    iOS crash日志分析 一. 寻找crash文件:手机崩溃后的ips或者crash文件(ips文件可以直接修改成crash文件,直接改后缀名就可以了),这里说下如何拿到crash文件 1. 把运行 ...

  4. 使用公共 Registry - 每天5分钟玩转 Docker 容器技术(19)

    保存和分发镜像的最直接方法就是使用 Docker Hub. Docker Hub 是 Docker 公司维护的公共 Registry.用户可以将自己的镜像保存到 Docker Hub 免费的 repo ...

  5. 6. Java 加解密技术系列之 3DES

    Java 加解密技术系列之 3DES 序 背景 概念 原理 代码实现 结束语 序 上一篇文章讲的是对称加密算法 — — DES,这篇文章打算在 DES 的基础上,继续多讲一点,也就是 3 重 DES ...

  6. Spark学习资料共享

    链接相关 课件代码:http://pan.baidu.com/s/1nvbkRSt 教学视频:http://pan.baidu.com/s/1c12XsIG 这是最近买的付费教程,对资料感兴趣的可以在 ...

  7. DDD理论学习系列(4)-- 领域模型

    DDD理论学习系列目录 1.引言 我们还是先来拆词理解,领域模型可以拆为"领域"和"模型"二词. 领域:按照我们之前的文章的理解,DDD中的领域是指软件系统要解 ...

  8. C#解析json的两种方式

    C#中Json转换主要使用的几种方法! 这篇主要介绍2.4.第三种方法使用的比较局限,所以我没有深入学习. 第二种方法 我使用比较多的方式,这个方法是.NET内置的,使用起来比较方便 A.利用seri ...

  9. 浅析DES与AES、RSA三种典型加密算法的比较

    DES与AES的比较 自DES 算法公诸于世以来,学术界围绕它的安全性等方面进行了研究并展开了激烈的争论.在技术上,对DES的批评主要集中在以下几个方面: 1.作为分组密码,DES 的加密单位仅有64 ...

  10. orcle :Could not initialize "D:\app\Administrator\product\11.2.0\dbhome_1\bin\oci.dll" Make sure you have the 32 bits Oracle Client installed.

    服务器重启后,数据库登录信息为空 错误信息: ---------------------------(Not logged on) - PL/SQL Developer---------------- ...