惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 热门话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Project Zero
Project Zero
V
Vulnerabilities – Threatpost
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
C
Cisco Blogs
A
Arctic Wolf
月光博客
月光博客
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
量子位
小众软件
小众软件
Latest news
Latest news
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
Security Latest
Security Latest
N
Netflix TechBlog - Medium
K
Kaspersky official blog
人人都是产品经理
人人都是产品经理
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
Y
Y Combinator Blog
P
Proofpoint News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
S
Schneier on Security
D
Docker
Scott Helme
Scott Helme
MyScale Blog
MyScale Blog
Spread Privacy
Spread Privacy
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
GbyAI
GbyAI
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
H
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
J
Java Code Geeks
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tenable Blog
B
Blog
Know Your Adversary
Know Your Adversary
IT之家
IT之家

博客园 - 克仔

克仔嘅第一次。。。“浮潜” Exact ADC之Paintball大戦 - 克仔 - 博客园 .NET Compact Framework里的DateTimePicker Control显示錯误的month selection list .NET CF v1的Form.ShowDialog(Me)里的Me在不能用了! .NET CF里的toolbar image在Windows Mobile 2003 SE消失了。 先嚟為《達文西的密碼》電影熱熱身。 汽油起價 - 加油站車龍。 我嘅第一部O2 Xda ll mini 《達文西的密碼》登上大银幕 丹•布朗 《數字城堡》 全新ARM base PocketPC 2003 Emulator Beta 已登場。 向左走,向右走? 全新旅途。。。 如何在ASP.NET里用HtmlInputFile控件来上载文件。 達文西的密碼 - 後記。 達文西的密碼。 如何用ASP.NET里的State Management Database来储存Session Variable。 如何用DataSet.GetChanges来提升数据库资料更新效率。 如何用SqlConnection类的InfoMessage事件来显示Stored Procedure的PRINT讯息。 Deamon Tool
Single Instance Appplication in .NET CF
克仔 · 2005-06-15 · via 博客园 - 克仔

(華)PockePC里的(X)在很多情况下都会给用户一个错觉,那就是以为按此键就会推出程序。但是此(X)跟一般WinForm程序有点不同,不同的就是此(X)是Minimize而不是Close。。。如果所写的程序里没有注意这一点,那就大有可能会导致出现两个同样的程序在同一时间操作。。。而以下就是怎样去防止此情况的一点点心得跟大家分享。

在此就需要用到P/Invoke来access三个API:
  - FindWindowW
  - ShowWindow
  - SetForegroundWindow

Imports System.Runtime.InteropServices

Module Win32Api

#Region " WIN32API CONSTANT PROTOTYPE"
    
Public Const SW_RESTORE = 9
#End Region


#Region " WIN32API FUNCTION DECLARATION PROTOTYPE "
    
<DllImport("coredll.dll")> _
    
Public Function FindWindowW(ByVal lpClassName As StringByVal lpWindowName As StringAs IntPtr
    
End Function


    
<DllImport("coredll.dll")> _
    
Public Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As IntegerAs Integer
    
End Function


    
<DllImport("coredll.dll")> _
    
Public Function SetForegroundWindow(ByVal hwnd As IntPtr) As Integer
    
End Function

#End Region


End Module


然后再多写一个main ()就完成了,

Module AppGlobal

    
Public Sub main()

        
Dim hWnd As IntPtr

        hWnd 
= FindWindowW(vbNullString, "Form1")

        
If hWnd.ToInt64 = 0 Then
            
Dim frmMainObj As Form1
            frmMainObj 
= New Form1
            Application.Run(frmMainObj)
        
Else
            SetForegroundWindow(hWnd)
            ShowWindow(hWnd, SW_RESTORE)
            Application.
Exit()
        
End If

    
End Sub


End Module


如果有更好的方法,例如不用Win32Api;那不妨提供上来跟大家分享。

posted on 2005-06-15 09:13  克仔  阅读(985)  评论(3)    收藏  举报